Thursday, 4 February 2016

arcgis 10.0 - Create Polylines from arrays of points


Let me describe the data setup. A line has been provided as an array of coordinate pairs, one for each vertex. This array is variable in size, anywhere from 2 to 200 coordinate pairs per line. What I am trying to wrap my mind around is the best way to create these lines. Arcpy and ArcObjects are both viable options, but ArcObjects is preferred due to its speed (generally).


I have brainstormed a few methods, but they fall short for some reason or another:


1) I could use the Polyline class with arcpy to create polylines and then Copy Features, but the resulting geometry would not have any of the attribution necessary to identify said points.



2) I could use XY To Line, but this only works with one pair of point, and I require something much more robust.


The long and short is that I require a method that can create a polyline from arrays and maintain a schema for data that I have created in a table. One idea I have is to create said table and schema, and then somehow create the polyline and copy its shape property to the output table, porting over the ID and whatever other attribution is needed. How can I go about creating the polyline's shape property without resorting to an intermediate shapefile? Or, if there is a better method that comes to mind, please share it with me.


Update This code seems to work!


IFeatureClass fClass = gpUtil.OpenFeatureClassFromString(path);
IFeatureCursor cursor = fClass.Insert(true);
IFeatureBuffer buffer = fClass.CreateFeatureBuffer();



string[] nodearray = a.Split(';');

foreach (string i in nodearray)
{
query.WhereClause = "\"PNT_ID\" = '" + i+"'";
Console.WriteLine(query.WhereClause.ToString());
ICursor search = table.Search(query, false);
IRow row = search.NextRow();
float x = float.Parse(row.get_Value(2).ToString());
float y = float.Parse(row.get_Value(3).ToString());
int id = int.Parse(row.get_Value(1).ToString());
point.X = x;

point.Y = y;
point.ID = id;
point.SpatialReference = sRef;
pCollection.AddPoint(point, ref Missing, ref Missing);

}
IGeometry5 polygeo = (IGeometry5)pCollection;
buffer.set_Value(1, polygeo);
buffer.set_Value(2, wayid);
cursor.InsertFeature(buffer);


Answer



It looks like I've got it. I created an IPoint class and used it to fill an IPointCollection instantiated as a PolylineClass. Then I cast the collection to IGeometry5 and used that as the shape field for the row in my output feature class, copying over the ID with a buffer.


I got my head twisted in a few circles working with two inputs, but it seems to work all right.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...