以配电网gis为例,将采集好的电网数据gps数据导入到sde数据库, 以杆塔线路为例,杆塔数据绘制好之后自动联线,同时保持网络关系。
/// <summary>
/// 获取文件所有要添加的杆塔的所有的线路名称
/// /// </summary>
///
public void Getlinenames()
{
//gpsEdit.CurrentLayer=
IFeatureWorkspace pFeatWS;
IWorkspaceFactory pWorkspaceFactory;
pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
if (Fileworkspacestring == null) return;
pFeatWS = pWorkspaceFactory.OpenFromFile(Fileworkspacestring, 0) as IFeatureWorkspace;
foreach (String file in listnames)
{
// Create a PictureBox.
if (file == "Export_Output.shp")
{
try
{
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.SubFields = "xlmc,zlmc";
IFeatureClass pFeatureClass = pFeatWS.OpenFeatureClass(file);
ISelectionSet selectionSet = pFeatureClass.Select(null, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal, null);
IEnumIDs enumIDs = selectionSet.IDs;
int fieldIndex = pFeatureClass.FindField("xlmc");
int fieldIndex1 = pFeatureClass.FindField("zlmc");
IFeature feature;
int iD = enumIDs.Next();
xlname xl = new xlname();
int isfirst = 0;
while (iD != -1) //-1 is reutned after the last valid ID has been reached
{
if (isfirst == 0)
{
feature = pFeatureClass.GetFeature(iD);
xl.xlmc = feature.get_Value(fieldIndex).ToString();
xl.zlmc = feature.get_Value(fieldIndex1).ToString();
xlnames.Add(xl);
isfirst = 1;
}
else
{
feature = pFeatureClass.GetFeature(iD);
xl.xlmc = feature.get_Value(fieldIndex).ToString();
xl.zlmc = feature.get_Value(fieldIndex1).ToString();
bool iscz = true;
foreach (xlname xlmc in xlnames)
{
if ((xlmc.xlmc == xl.xlmc) && (xlmc.zlmc == xl.zlmc))
{
iscz = false;//是否存在
}
}
if (iscz == true) //不存在就添加
{
xlnames.Add(xl);
}
}
iD = enumIDs.Next();
}
int dd = xlnames.Count;
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
}
}
}
/// <summary>
/// 绘制点状设备
/// </summary>
/// <param name="iflayer"></param>
/// <param name="pPoint"></param>
private void Drawpoint(ILayer iflayer,IPoint pPoint)
{
try
{
if (iflayer == null) return;
if (!(iflayer is IGeoFeatureLayer)) return;
IFeatureLayer pFeatureLayer = (IFeatureLayer)iflayer;
IFeatureClass mfeatureClass = pFeatureLayer.FeatureClass;
IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass;
if (pDataset == null) return;
// 开始编辑,并设置Undo/Redo 为可用
IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace;
if (!pWorkspaceEdit.IsBeingEdited())
{
pWorkspaceEdit.StartEditing(true);
pWorkspaceEdit.EnableUndoRedo();
IFeature myfeature;
IFeatureClassWrite fr = mfeatureClass as IFeatureClassWrite;//绘制杆塔
pWorkspaceEdit.StartEditOperation();
myfeature = mfeatureClass.CreateFeature();
myfeature.Shape = pPoint;
myfeature.Store();
fr.WriteFeature(myfeature);
pWorkspaceEdit.StopEditOperation();
pWorkspaceEdit.StopEditing (true );
m_pMap.ClearSelection();
IActiveView pActiveView = (IActiveView)m_pMap;
pActiveView.Refresh();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
}
/// <summary>
/// 画线路
/// </summary>
public void Drawline(ILayer iflayer, IPointCollection pointCollection)
{
try
{
if (iflayer == null) return;
if (!(iflayer is IGeoFeatureLayer)) return;
IFeatureLayer pFeatureLayer = (IFeatureLayer)iflayer;
IFeatureClass mfeatureClass = pFeatureLayer.FeatureClass;
IDataset pDataset = (IDataset)pFeatureLayer.FeatureClass;
if (pDataset == null) return;
// 开始编辑,并设置Undo/Redo 为可用
IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pDataset.Workspace;
if (!pWorkspaceEdit.IsBeingEdited())
{
pWorkspaceEdit.StartEditing(true);
pWorkspaceEdit.EnableUndoRedo();
IFeature myfeature;
IFeatureClassWrite fr = mfeatureClass as IFeatureClassWrite;//绘制杆塔
pWorkspaceEdit.StartEditOperation();
myfeature = mfeatureClass.CreateFeature();
pWorkspaceEdit.StartEditOperation();
myfeature = mfeatureClass.CreateFeature();
//IGeometry gGeometry = (IGeometry)pointCollection ;
IPolyline pPolyline = pointCollection as IPolyline;
myfeature.Shape = pPolyline;
myfeature.Store();
fr.WriteFeature(myfeature);
IComplexEdgeFeature Ccomplexedte = myfeature as IComplexEdgeFeature;//建立连通性
Ccomplexedte.ConnectAtIntermediateVertices();
pWorkspaceEdit.StopEditOperation();
pWorkspaceEdit.StopEditing(true);
m_pMap.ClearSelection();
IActiveView pActiveView = (IActiveView)m_pMap;
pActiveView.Refresh();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message.ToString());
}
}
/// <summary>
/// 绘制gps数据,杆塔,线路
/// </summary>
public void Draw()
{
IFeatureWorkspace pFeatWS; IWorkspaceFactory pWorkspaceFactory; pWorkspaceFactory = new ShapefileWorkspaceFactoryClass(); if (Fileworkspacestring == null) return; pFeatWS = pWorkspaceFactory.OpenFromFile(Fileworkspacestring, 0) as IFeatureWorkspace; foreach (String file in listnames) { if (file == "Export_Output.shp")//布绘杆塔 { foreach (xlname xlmc in xlnames) { IFeature featurepoint; int idline = GetLayerid(m_pMap, "GIS.lines");//获取线图层 ILayer ilayerline = m_pMap.get_Layer(idline); int idpoint = GetLayerid(m_pMap, "gt");//获取点图层 ILayer iflayer = m_pMap.get_Layer(idpoint); IPolyline mypolylin = new PolylineClass(); IPointCollection pointCollection = mypolylin as IPointCollection; object missingVal = System.Reflection.Missing.Value; IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = "xlmc='"+xlmc .xlmc+"'"+" and zlmc='" + xlmc.zlmc+"'"; IFeatureClass pFeatureClass = pFeatWS.OpenFeatureClass(file); //IQueryFilterDefinition queryFilterDefinition = (IQueryFilterDefinition)queryFilter; //queryFilterDefinition.PostfixClause = "ORDER BY gh"; IFields fField = pFeatureClass.Fields; for (int fieldindex = 0; fieldindex < fField.FieldCount;fieldindex++ ) { string dd = fField.get_Field(fieldindex).Name; string ddd = pFeatureClass.ShapeFieldName; } ISelectionSet selectionSet = pFeatureClass.Select(queryFilter, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal,
null); int fieldIndexgh = pFeatureClass.FindField("gh"); int fieldIndexzjgh = pFeatureClass.FindField("zjgh"); int fieldindexxlmc = pFeatureClass.FindField("xlmc"); int fieldindexzlmc = pFeatureClass.FindField("zlmc"); int fieldindextjxl = pFeatureClass.FindField("tjxl"); int fieldindextjgh = pFeatureClass.FindField("tjgh"); IEnumIDs enumIDs = selectionSet.IDs; for (int j = 1; j <= selectionSet.Count;j++ ) { bool istjgh = false; enumIDs.Reset(); int iD = enumIDs.Next(); while (iD != -1) //-1 is reutned after the last valid ID has been reached { featurepoint = pFeatureClass.GetFeature(iD); IGeometry geometrygt = featurepoint.Shape;//获取shp文件中的对象 IPoint pointgt = geometrygt as IPoint; gtzb gtxx = new gtzb(); gtxx.gh = featurepoint.get_Value(fieldIndexgh).ToString(); gtxx.xlmc = featurepoint.get_Value(fieldindexxlmc).ToString(); gtxx.zlmc = featurepoint.get_Value(fieldindexzlmc).ToString(); gtxx.zjgh = featurepoint.get_Value(fieldIndexzjgh).ToString(); if (gtxx.gh == j.ToString() && gtxx.zjgh.ToString().Trim() =="") { Drawpoint(iflayer, pointgt); //将shp文件中的对象绘制到数据库 pointCollection.AddPoint(pointgt, ref missingVal, ref missingVal); } else if (gtxx.gh == j.ToString() && gtxx.zjgh.ToString().Trim() != "") { istjgh = true; } iD = enumIDs.Next(); } if (istjgh) { IQueryFilter queryFiltersub = new QueryFilterClass(); queryFiltersub.WhereClause = "xlmc='" + xlmc.xlmc + "'" + " and zlmc='" + xlmc.zlmc + "'and zjgh='" + j + "'"; ISelectionSet selectionSetsub = pFeatureClass.Select(queryFiltersub, esriSelectionType.esriSelectionTypeIDSet, esriSelectionOption.esriSelectionOptionNormal,
null); for (int subj = 1; subj <= selectionSetsub.Count; subj++) { IEnumIDs enumsubIDs = selectionSetsub.IDs; enumsubIDs.Reset(); int iDsub = enumsubIDs.Next(); while (iDsub != -1) //-1 is reutned after the last valid ID has been reached { featurepoint = pFeatureClass.GetFeature(iDsub); IGeometry geometrygt = featurepoint.Shape; IPoint pointgt = geometrygt as IPoint; gtzb gtxx = new gtzb(); gtxx.longitude = pointgt.X; gtxx.latitude = pointgt.Y; gtxx.elevation = pointgt.Z; gtxx.gh = featurepoint.get_Value(fieldIndexgh).ToString(); gtxx.zjgh = featurepoint.get_Value(fieldIndexzjgh).ToString(); gtxx.xlmc = featurepoint.get_Value(fieldindexxlmc).ToString(); gtxx.zlmc = featurepoint.get_Value(fieldindexzlmc).ToString(); if (gtxx.zjgh == subj.ToString()) { Drawpoint(iflayer, pointgt); pointCollection.AddPoint(pointgt, ref missingVal, ref missingVal); } iDsub = enumsubIDs.Next(); } } } } //绘制线路 Drawline(ilayerline, pointCollection); }
}
}
分享到:
相关推荐
SDE(Spatial Database Engine,空间数据库引擎)是ArcGIS中的一个核心组件,用于管理、存储和分发地理空间数据。本手册将详述如何在ArcGIS 10.3中创建SDE数据库、导入与导出数据,以及发布地图的步骤。 一、创建...
总结来说,这个基于ArcGIS Engine 10.1的项目旨在模拟并扩展ArcCatalog的部分功能,提供了SDE数据库的连接管理、要素数据集和要素类的创建,以及SHP文件的上传。这样的工具对于GIS专业人员来说,能够提高数据管理和...
3. **数据导入**:在AE中,我们可以使用“数据管理”工具箱中的“导入/导出”工具来将.shp文件转换并加载到SDE中。这通常涉及到数据的预处理,如检查坐标系一致性,以及设置合适的存储模式(如文件GDB或企业级GDB)...
在GIS(地理信息系统)领域,将SHP(Shapefile)数据导入到SDE(Spatial Database Engine)数据库是一项常见的任务。SHP是一种常见的矢量地理数据格式,由Esri公司开发,用于存储地理空间特征,如点、线和多边形。而...
在GIS(地理信息系统)领域,"SHP上传sde.zip"这一标题暗示了我们需要将Shapefile(SHP)格式的数据导入到ArcGIS的SDE(Spatial Database Engine)环境中。SDE是Esri公司开发的一种用于存储和管理地理空间数据的高...
使用`ESRI.ArcGIS.Geometry.Envelope`类创建一个边界框,然后通过`ESRI.ArcGIS.esriSystem.IName`接口的`Open`方法打开SHP文件,并将其添加到地图的图层集合中。要移除图层,只需从`IMap.Layers`集合中删除相应的`...
- 选择需要导出的数据源文件,例如.shp文件或其他支持的格式。 - 将文件拖拽到ArcMap界面中,即可将其加载为新图层。 ##### 2. 设置导出环境 接下来,需要设置适当的导出环境,以便ArcMap能够正确地处理和导出数据...
### ArcGIS Engine中的数据访问详解 #### 一、概述 ArcGIS Engine是Esri公司推出的一款功能强大的地理信息系统开发工具,允许开发者通过编程的方式构建定制化的GIS应用。ArcGIS Engine支持多种数据格式,并且提供...
SDE是ArcGIS软件中用于访问和管理大型数据库中的空间数据的一种技术。SDE允许直接在关系型数据库中存储和管理空间数据,例如Oracle、SQL Server等。在ArcEngine中,开发者可以通过数据库连接,如ODBC或OLE DB等,...
工作空间是 ArcEngine 中用于管理数据的一种方式,主要包括文件地理数据库 (FileGeoDatabase)、形状文件 (SHP) 和空间数据库 (SDE) 的操作。 - **文件地理数据库 (FileGeoDatabase)**:通过 `...
- 为了自由存取GPS点或shp文件属性,需要理解ArcGIS的数据结构和API,以实现读写操作。 12. **计算点到直线的最短距离**: - 这是空间分析的基础,通过GIS库(如ESRI.ArcGIS.Geometry)实现,通常使用缓冲区和...
1. **导出**:可以使用 ARC/INFO、PCARC/INFO、Spatial Database Engine (SDE)、ArcView GIS 或 BusinessMAP 软件将现有数据源导出为 Shapefile 格式。 2. **数字化**:利用 ArcView GIS 中的要素创建工具直接进行...
"shp2sde"是一个命令行工具,用于将Shapefile格式的空间数据导入到ArcSDE管理的数据库中。Shapefile是Esri广泛使用的矢量数据格式,而shp2sde则提供了将这种数据格式转换为数据库存储空间数据的便捷方式。使用该工具...
6. **2004年**:为了进一步扩展GIS的应用范围,ESRI推出了ArcGIS Engine和ArcGIS Server,并引入了geodatabase作为新一代的数据格式。 #### 二、Coverage 数据格式详解 Coverage是ARC/INFO工作站的原生数据格式。...
- 在SDE(Spatial Database Engine)数据库中使用`dataset`来存放多个道路图层。创建网络数据集时可以选择这些图层中的多个。 - 如果使用的是.shp文件,则通常只能使用单个图层来创建网络数据集。 - 在Catalog...