arcgis創建點圖形和線圖形


向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, List<SCoordinates> sCoordLst, 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 }




注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2020 ITdaan.com