Thursday, November 17, 2005

Polygon 2 XY Table 2 Polygon

Some folks here need to create a automated task that can easily convert polygon vertices to a table containing XY coords. They would like to be able to edit this table using their homemade algorithms and then recreate the polygon based on the moved XY coords.

I was concerned that the capabilities of the ESRI geoprocessing objects that I have been infatuated with over the past year or so might have reached their limit and that I would have to undust my crusty old ArcObject tombs. However, ESRI did not let me down. Right there on pages 66-70 of Writing Geoprocessing Scripts (PDF book bundled with the ArcGIS package) and also in the ArcGIS Desktop Help, it describes the geometry object which can be accessed with the SearchCursor, InsertCursor, and the UpdateCursor. There is even an example of reading coords from a text file and creating a polyline. Wonderful!

Well, I am using the IGPDispatch to create the COM connection using .NET, and everything is going smoothly so far given this great documentation provided in the Writing Geoprocessing Scripts e-book. I will post the file here as soon as I have finished it.

3 comments:

dylan said...

Seems like re-inventing the wheel to me. Here is a quick one-liner that will work in any UNIX, with the open source GDAL tools installed:

ogrinfo -al line_shapefile.shp | grep LINESTRING | tr -d "LINESTRING()" | awk '{RS=","; FS=" "; print $1, $2}'

returns x,y list for each line element in the shape file:
668684.125 4038113.25
668692.0625 4038125.25
668704.625 4038146.5
668713.3125 4038153.5
668717.75 4038166.25

pipe the out put to a file, and there is your list of x,y pair. Easily modified to work with point or polygon data as well.

mapz said...

Hey, thanks a lot for sharing this with me. I do have access to a Linux computer over here and just downloaded the tar files for the installation.

Tell me, is it just as easy (short) to reverse your command? Can I read a list of x,y from a text file and create line/polygon parts?

Dylan said...

Glad that you found it helpful.

As for reversing the result, I would recommend using GDAL's VRT (virtual dataset) construct for transforming a CSV file into a corrosponding vector data format. I normally do the conversion in GRASS, so I am not familliar with the exact syntax. The GDAL mailing list would be a good start.

Cheers!