2

I am working on ArcObject. I want to create shape file using arcObject. I am very close to it. but need some better alternative as I feel my solution may fall short in time when there are hundreds of thousands of records

I have Geometry field in sql 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 
 label d = d.Substring(0, d.Length - 1); // to get points as x1 y1,x2 y2,x3 y3 
 arr = d.Split(','); // now to get array [x1 y1, x2 y2, x3 y3] 

here is how my code goes

  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 obj1 = Type.Missing;
                pGeoColl12.AddGeometry((ESRI.ArcGIS.Geometry.IGeometry)paths[j], ref obj1, ref obj1);
                linearray[j].PutCoords(pntArrayTemp[j], pntArrayTemp[j + 1]);
            }

        }
        pGeoColl12.GeometriesChanged();
        return pGeoColl12 as IPolyline;

from this I get array of the co-ordinates which I use to create shape for line. It is very tedious procedure for many record[100k or more]. Is there any simple easy method in arcObject that I can get the coordinates from LINESTRING on fly or I can use the LINESTRING to draw lines ?

James Z
  • 12,209
  • 10
  • 24
  • 44
Harsh Desai
  • 31
  • 1
  • 4
  • Hi, is db not changeable? I mean it is not best way to hold coordinates, doesn't it? And can you little bit rephrase your question, do you want to get rid of parsing string part(for example create object from string) or what? – Valentyn Vynogradskiy Jun 23 '14 at 12:23
  • No I cannot change db and you are correct I need to get rid of the tedious calculation to get coordinates. – Harsh Desai Jun 23 '14 at 12:34
  • Okay, I remember that I have a lot of headache with ArcGIS, but I can't find anything exclude you did, only I can suggest is to ask this question here [link](http://gis.stackexchange.com/questions/tagged/arcgis) – Valentyn Vynogradskiy Jun 23 '14 at 12:49
  • Google tells me ESRI doesn't like the WKT (WellKnownText - which is what your `LINESTRING(...)` is) geometry representations very much, but there's a couple of interesting threads [here](http://gis.stackexchange.com/questions/4600/convert-between-esri-geometry-and-wkt) and [here](http://forums.esri.com/thread.asp?c=159&f=1707&t=236848) which might help. – Juffy Jun 24 '14 at 01:39
  • Can I make a suggestion? If you `Import ESRI.ArcGIS.Geometry` then you can cut out all references to it in your code. Much easier to read. – pvdev Jul 02 '14 at 13:08
  • I'm voting to close this question as off-topic because it obviously belongs to gis.stackexchange. The exact same question is posted and answered here: http://gis.stackexchange.com/questions/102877/how-to-create-shapefile-using-geometry-field – MakePeaceGreatAgain Nov 20 '15 at 11:05

0 Answers0