Converting geometry to WKT using ArcPy?

A da.searchcursor should work for you.

for row in arcpy.da.SearchCursor("path2data", ["SHAPE@WKT"]):
  print row[0]

POINT Z (-119.53753379999995 49.854383300000052 303.14500000000407)

doc here: http://resources.arcgis.com/en/help/main/10.1/index.html#//002z0000001t000000

Note: SHAPE@JSON, SHAPE@WKB, and SHAPE@WKT tokens were made available at ArcGIS 10.1 Service Pack 1.

Or, if you're after the samples toolbox like you mentioned - its there, just deprecated. You can call into it with scripts still. If you need the actual toolbox you can use, its here on the old Model and Script Gallery

EDIT (extra example)...Because you asked so nicely: :)

for row in arcpy.da.SearchCursor("GPX_Layer", ["SHAPE@WKT"],where_clause="TYPE = 'a'"):
    print row[0]

It's just the same as a "select by attributes" type of query/expression. I have a field called "TYPE" and and a value 'a'.


I'm not equipped to confirm this, but this page documenting SearchCursor (arcpy.da), discussing the field_names parameter, notes the following:

FROM ArcGIS Help 10.1 - SearchCursor (arcpy.da)

Additional information can be accessed using tokens (such as OID@) in place of field names:

SHAPE@WKT —The well-known text (WKT) representation for OGC geometry. It provides a portable representation of a geometry value as a text string

Note: SHAPE@JSON, SHAPE@WKB, and SHAPE@WKT tokens were made available at ArcGIS 10.1 Service Pack 1.

What do you think?


Just adding this in case it's useful for someone...

# Convert to WKT by field name (Shape)
file_path = 'C:\shapefile.shp'
query= arcpy.SearchCursor(file_path)
for row in query:
  the_geom=row.getValue('Shape') # Get Geometry field
  wkt = the_geom.WKT # Convert to WKT, can also use WKB, JSON etc