I would like to be able to convert a single feature (or potentially many features) in an ArcGIS layer into Well Known Text (WKT) format during a geoprocessing operation using Python and ArcPy (no non-ArcPy modules). The purpose is to then pass the WKT on to SQL Server Spatial and do additional processing outside of the ArcGIS GP toolset. Is there a method for converting a ArcGIS geometry features to WKT via ArcPy?
I have already read the following, without finding what I am after:
- Shapefiles to Text (references a tool in the deprecated "Samples" toolbox)
- Convert between ESRI Geometry and WKT (uses ArcObjects or non-ArcPy modules)
- How to convert a shapefile to WKT? (Uses QGIS and OGR)
There apparently used to be a tool called "Write Features To Text File" (which appears to be a Python script) that was in the Samples toolbox, but that toolbox was deprecated at version 10 and I cannot find a copy of the Samples Toolbox (I have v10.0) on my machine. If there are no current solutions, if someone could just point me to a copy of the sample, I would be totally fine with using that tool, too.
Best Answer
A da.searchcursor should work for you.
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: :)
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'.