C#中已知点的坐标,如何通过编程向一个指定的SHP图层上批量添加这些点啊?ArcEngine/C#
已知点的坐标,如何通过编程向一个指定的SHP图层上批量添加这些点并给点赋予相应的属性啊?跪求高手指导--ArcEngine/C#...
已知点的坐标,如何通过编程向一个指定的SHP图层上批量添加这些点并给点赋予相应的属性啊?跪求高手指导- -ArcEngine/C#
展开
1个回答
展开全部
下面是批量加点的代码,如有疑问请与我持联系。希望对你有帮助!
/// <summary>
/// 点坐标 结构体
/// </summary>
public struct PointXY
{
public double dX;
public double dY;
}
/// <summary>
/// 建立 ESRI中的 点类型 并 将其转化为基类接口 IGeometry
/// </summary>
/// <param name="point">点坐标 结构体</param>
/// <returns></returns>
public IGeometry BuildPoint(PointXY point)
{
IPoint pPoint = new PointClass();
pPoint.X = point.dX;
pPoint.Y = point.dY;
IGeometry pGeometry = pPoint as IGeometry;
return pGeometry;
}
/// <summary>
/// 批量加入 点坐标 结构体
/// </summary>
/// <param name="pLayer">点图层</param>
/// <param name="pointCol">泛型集合【点坐标 结构体】</param>
/// <returns></returns>
public bool AddPointsToLayer(ILayer pLayer, List<PointXY> pointCol)
{
IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
if (pFeatureLayer == null)
{
System.Windows.Forms.MessageBox.Show(pLayer.Name + "不是矢量图层!"); return false;
}
//
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
if (pFeatureClass.ShapeType != esriGeometryType.esriGeometryPoint)
{
System.Windows.Forms.MessageBox.Show(pLayer.Name + "不是点图层!"); return false;
}
//
IFeatureCursor pFeatureCursor = pFeatureClass.Insert(true);
IFeatureBuffer pFeatureBuffer = null;
foreach(PointXY one in pointCol)
{
pFeatureBuffer = pFeatureClass.CreateFeatureBuffer();
IFeature pNewFeature = pFeatureBuffer as IFeature;
pNewFeature.Shape = BuildPoint(one);
//
pFeatureCursor.InsertFeature(pFeatureBuffer);
}
pFeatureCursor.Flush();
return true;
}
/// <summary>
/// 点坐标 结构体
/// </summary>
public struct PointXY
{
public double dX;
public double dY;
}
/// <summary>
/// 建立 ESRI中的 点类型 并 将其转化为基类接口 IGeometry
/// </summary>
/// <param name="point">点坐标 结构体</param>
/// <returns></returns>
public IGeometry BuildPoint(PointXY point)
{
IPoint pPoint = new PointClass();
pPoint.X = point.dX;
pPoint.Y = point.dY;
IGeometry pGeometry = pPoint as IGeometry;
return pGeometry;
}
/// <summary>
/// 批量加入 点坐标 结构体
/// </summary>
/// <param name="pLayer">点图层</param>
/// <param name="pointCol">泛型集合【点坐标 结构体】</param>
/// <returns></returns>
public bool AddPointsToLayer(ILayer pLayer, List<PointXY> pointCol)
{
IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer;
if (pFeatureLayer == null)
{
System.Windows.Forms.MessageBox.Show(pLayer.Name + "不是矢量图层!"); return false;
}
//
IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;
if (pFeatureClass.ShapeType != esriGeometryType.esriGeometryPoint)
{
System.Windows.Forms.MessageBox.Show(pLayer.Name + "不是点图层!"); return false;
}
//
IFeatureCursor pFeatureCursor = pFeatureClass.Insert(true);
IFeatureBuffer pFeatureBuffer = null;
foreach(PointXY one in pointCol)
{
pFeatureBuffer = pFeatureClass.CreateFeatureBuffer();
IFeature pNewFeature = pFeatureBuffer as IFeature;
pNewFeature.Shape = BuildPoint(one);
//
pFeatureCursor.InsertFeature(pFeatureBuffer);
}
pFeatureCursor.Flush();
return true;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询