C#中已知点的坐标,如何通过编程向一个指定的SHP图层上批量添加这些点啊?ArcEngine/C#
答案:1 悬赏:0 手机版
解决时间 2021-01-25 17:21
- 提问者网友:送舟行
- 2021-01-25 13:09
C#中已知点的坐标,如何通过编程向一个指定的SHP图层上批量添加这些点啊?ArcEngine/C#
最佳答案
- 五星知识达人网友:煞尾
- 2021-01-25 13:50
下面是批量加点的代码,如有疑问请与我持联系。希望对你有帮助!
///
/// 点坐标 结构体
///
public struct PointXY
{
public double dX;
public double dY;
}
///
/// 建立 ESRI中的 点类型 并 将其转化为基类接口 IGeometry
///
/// 点坐标 结构体
///
public IGeometry BuildPoint(PointXY point)
{
IPoint pPoint = new PointClass();
pPoint.X = point.dX;
pPoint.Y = point.dY;
IGeometry pGeometry = pPoint as IGeometry;
return pGeometry;
}
///
/// 批量加入 点坐标 结构体
///
/// 点图层
/// 泛型集合【点坐标 结构体】
///
public bool AddPointsToLayer(ILayer pLayer, List 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;
}
///
/// 点坐标 结构体
///
public struct PointXY
{
public double dX;
public double dY;
}
///
/// 建立 ESRI中的 点类型 并 将其转化为基类接口 IGeometry
///
/// 点坐标 结构体
///
public IGeometry BuildPoint(PointXY point)
{
IPoint pPoint = new PointClass();
pPoint.X = point.dX;
pPoint.Y = point.dY;
IGeometry pGeometry = pPoint as IGeometry;
return pGeometry;
}
///
/// 批量加入 点坐标 结构体
///
/// 点图层
/// 泛型集合【点坐标 结构体】
///
public bool AddPointsToLayer(ILayer pLayer, List
{
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;
}
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯