向oracle数据库新增点图形数据:
1 1 public static int CreatePoint(string featureClassName, SCoordinates sCoord, string[] sde=null) 2 2 { 3 3 4 4 if (pFeatureWorkspace == null) 5 5 ConnectSDE(sde); 6 6 OpenFeatureSet(sde); 7 7 IFeatureClass pFeatureClass; 8 8 IFeature pFeature = null; 9 9 IGeometry pGeo = null; 10 10 IPoint pPoint = null; 11 11 int fidIndex; 12 12 int objectID = -1; 13 13 featureClassName = "PMGIS" + "." + featureClassName; 14 14 try 15 15 { 16 16 if (pFeatureClassdic.Keys.Contains(featureClassName)) 17 17 { 18 18 pFeatureClass = pFeatureClassdic[featureClassName]; 19 19 m_WorkspaceEdit.StartEditing(false); 20 20 m_WorkspaceEdit.StartEditOperation(); 21 21 pFeature = pFeatureClass.CreateFeature(); 22 22 //一般Shape图形表都会有2个图形字段 OBJECTID和Shape 23 23 fidIndex = pFeature.Fields.FindField("OBJECTID"); 24 24 objectID = (int)pFeature.get_Value(fidIndex); 25 25 pPoint = new Point(); 26 26 pPoint.X = sCoord.X; 27 27 pPoint.Y = sCoord.Y; 28 28 pPoint.Z = sCoord.Z; 29 29 //pPoint = GetProject(sCoord.X, sCoord.Y); 30 30 pGeo = pPoint as IGeometry; 31 31 IZAware pZAware = (IZAware)pGeo;//创建要素类时,必须选择“Coordinates include z values” 32 32 pZAware.ZAware = true; 33 33 pFeature.Shape = pGeo;//,否则,则会出错 34 34 pFeature.Store(); //保存 35 35 m_WorkspaceEdit.StopEditOperation(); //停止编辑操作 36 36 m_WorkspaceEdit.StopEditing(true); //停止编辑 顺序不能颠倒 37 37 } 38 38 } 39 39 catch (Exception ex) 40 40 { 41 41 42 42 } 43 43 return objectID; 44 44 }
向oracle数据库新增线图形数据:
1 public static int CreateLine(string featureClassName, ListsCoordLst, string[] sde = null) 2 { 3 4 int objectID = -1; 5 if (sCoordLst.Count == 0) 6 return objectID; 7 8 if (pWorkspaceFactory == null || pFeatureWorkspace == null) 9 ConnectSDE(sde); 10 OpenFeatureSet(); 11 IFeatureClass pFeatureClass; 12 IFeature pFeature = null; 13 IPoint pPoint = null; 14 int fidIndex; 15 featureClassName = "PMGIS" + "." + featureClassName; 16 try 17 { 18 if (pFeatureClassdic.Keys.Contains(featureClassName)) 19 { 20 pFeatureClass = pFeatureClassdic[featureClassName]; 21 m_WorkspaceEdit.StartEditing(false); 22 m_WorkspaceEdit.StartEditOperation(); 23 pFeature = pFeatureClass.CreateFeature(); 24 ESRI.ArcGIS.Geometry.Polyline pPolyline = new ESRI.ArcGIS.Geometry.Polyline(); 25 ((IZAware)(pPolyline as IGeometry)).ZAware = true; 26 for (int i = 0; i < sCoordLst.Count; i++) 27 { 28 pPoint = new Point() { X = sCoordLst[i].X, Y = sCoordLst[i].Y, Z = sCoordLst[i].Z }; 29 pPolyline.AddPoint(pPoint); 30 } 31 fidIndex = pFeature.Fields.FindField("OBJECTID"); 32 objectID = (int)pFeature.get_Value(fidIndex); 33 pFeature.Shape = pPolyline as IGeometry; 34 35 pFeature.Store(); 36 m_WorkspaceEdit.StopEditOperation(); 37 m_WorkspaceEdit.StopEditing(true); 38 } 39 } 40 catch (Exception ex) 41 { 42 43 } 44 return objectID; 45 }