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.3k10 gold badges27 silver badges48 bronze badges
asked Jun 23, 2014 at 12:13
6
  • 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? Commented Jun 23, 2014 at 12:23
  • No I cannot change db and you are correct I need to get rid of the tedious calculation to get coordinates. Commented Jun 23, 2014 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 Commented Jun 23, 2014 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 and here which might help. Commented Jun 24, 2014 at 1: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. Commented Jul 2, 2014 at 13:08

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.