Tuesday, November 20, 2012

New Geometry Tags for Cursors

At 10.1 SP1, there are 3 new tags that can be used to represent geometry objects.  Those tags are:
  • SHAPE@WKB
  • SHAPE@WKT 
  • SHAPE@JSON
The well-known binary (WKB) representation for OGC geometry. It provides a portable representation of a geometry value as a contiguous stream of bytes.  The well-known text (WKT) representation for OGC geometry. It provides a portable representation of a geometry value as a text string.  The esri JSON string representing the geometry.

Here is a simple usage example from the python window:

from arcpy import da
with da.SearchCursor("Counties", ["SHAPE@JSON", "SHAPE@WKT", "SHAPE@WKB"]) as rows:
     for r in rows:
         print r[0]
         print r[1]
         print r[2]
         break
You'll see all three types print out.  The print out doesn't really mean anything except to show the various string formats that a coder can now export the geometry object into. It will also make exporting geometries to something like a TAB or Excel table a bit more practical.  I would stay away from csv, since many of these formats use the ',' (comma) to separate the points.

Enjoy