I am attempting to convert a shapefile to WKT using ArcGIS 10.4. I have seen the question/answer posted here, Converting geometry to WKT using ArcPy?, which is helpful. However, when I follow the code and write it to the text file I create, the spatial reference is incorrect. The geometric shape is identical to the original shapefile, but the WKT maps to a different continent. I don't have experience writing to WKT, so I could be making an amateurish mistake that is causing my spatial reference to be off.
import arcpy
# Create new empty text file
outFile = open(r"my_path.txt", "w")
# My shapefile
fc = r"my_path.shp"
# Convert to WKT and write to file
cursor = arcpy.da.SearchCursor(fc, ["SHAPEFILE@WKT"])
for row in cursor:
print(row[0])
outFile.write((row[0]) + "\n")
del row
del cursor
outFile.close()
The projection that I want my WKT to be in is NAD_1983_UTM_Zone_13N.
Best Answer
Firstly,
"SHAPEFILE@WKT"
should be"SHAPE@WKT"
.Secondly, your WKT will be in exactly the same coordinate system as your shapefile. If you're getting strange results, your data is probably not in NAD 1983 UTM Zone 13N, but some other spatial reference and is being projected on the fly when you view it in ArcGIS.
To specify the output spatial reference for your search cursor, pass in a SpatialReference object.
For example:
Output: