How to Create shapefile using Geometry field

المشرف العام

Administrator
طاقم الإدارة
I am working on ArcObjects. I want to create shapefile. I am very close to it but need some better alternative as I feel my solution may fall short in time when there are thousand of records.

I have a geometry field in a database. From that I get the string which is Linstring, Multilinestring or Point

Eg.

"LINESTRING (-98.71702604799998 37.746413141000062, -98.717210399999942 37.738209632000064, -98.717347586999949 37.732091870000033)"

From this I manually extract the coordinates like

string d = st.Substring(12); // to get rid of LINESTRING labeld = d.Substring(0, d.Length - 1); // to get points as x1 y1,x2 y2,x3 y3arr = d.Split(','); // now to get array [x1 y1, x2 y2, x3 y3]Here is my code:

private IPolyline CreatePolyline(DataSet ds){ ESRI.ArcGIS.Geometry.IPolyline pSegPoly1 = new ESRI.ArcGIS.Geometry.PolylineClass(); pSegPoly1.SpatialReference = createSpatialReference(); ESRI.ArcGIS.Geometry.IGeometryCollection pGeoColl12 = pSegPoly1 as ESRI.ArcGIS.Geometry.IGeometryCollection; foreach (DataRow row in ds.Tables[0].Rows) { string st = row["ShapeGeoWKT"].ToString(); string[] arr = null; if (st.StartsWith("MULTI")) { string d = st.Substring(18); d = d.Substring(0, d.Length - 2); arr = d.Split(','); } else if (st.StartsWith("LINE")) { string d = st.Substring(12); d = d.Substring(0, d.Length - 1); arr = d.Split(','); } ESRI.ArcGIS.Geometry.IPoint[] pntArrayTemp = new ESRI.ArcGIS.Geometry.IPoint[arr.Length]; int k = 0; ESRI.ArcGIS.Geometry.ILine[] linearray = new ESRI.ArcGIS.Geometry.LineClass[pntArrayTemp.Length]; ESRI.ArcGIS.Geometry.ISegmentCollection[] paths = new ESRI.ArcGIS.Geometry.PathClass[pntArrayTemp.Length]; foreach (string st1 in arr) { linearray[k] = new ESRI.ArcGIS.Geometry.LineClass(); paths[k] = new ESRI.ArcGIS.Geometry.PathClass(); pntArrayTemp[k] = new ESRI.ArcGIS.Geometry.PointClass(); string[] temp1 = st1.Trim().Split(' '); pntArrayTemp[k].X = Convert.ToDouble(temp1[0].Replace(")", "").Replace("(", "").Trim()); pntArrayTemp[k].Y = Convert.ToDouble(temp1[1].Replace(")", "").Replace("(", "").Trim()); object obj1 = Type.Missing; paths[k].AddSegment((ISegment)linearray[k], ref obj1, ref obj1); k++; } for (int j = 0; j < paths.Length - 1; j++) { object obj12 = Type.Missing; pGeoColl12.AddGeometry((ESRI.ArcGIS.Geometry.IGeometry)paths[j], ref obj12, ref obj12); linearray[j].PutCoords(pntArrayTemp[j], pntArrayTemp[j + 1]); } } pGeoColl12.GeometriesChanged(); return pGeoColl12 as IPolyline;}From this I get an array of the co-ordinates which I use to create shape for line. It is a very tedious procedure for many records (100k or more).

Is their any simple easy method in ArcObjects that I can use to get the coordinates from LINESTRING on the fly or I can use the LINESTRING to draw lines?



أكثر...
 
أعلى