How can I export WKB (geometry) to text file using arcpy (ArcGIS)?
When I use the examples that I found on the Internet, it doesn't work. Below it's the code I'd wrote:
## Import arcpy module
import sys
import string
import os
import arcpy
## Global variables:
mxd = arcpy.mapping.MapDocument("current")
IN_FC = arcpy.GetParameterAsText(0)
OUT_Addre = arcpy.GetParameterAsText(1)
OUT_Name = arcpy.GetParameterAsText(2)
## Set progressor
lines = arcpy.GetCount_management(IN_FC)
number = int(fc.getOutput(0))
arcpy.SetProgressor("default","Exporting WKB geometry",0,number,1)
## for row in input
with arcpy.da.SearchCursor(IN_FC, ["OID@", "SHAPE@WKB"]) as cursor:
for row in cursor:
## First feature
elem = IN_FC.getFeatures().next()
geom = elem.geometry()
## Export into wkb format
wkb = geom.asWkb()
## Import to ogr geometry
from osgeo import ogr
geom_ogr = ogr.CreateGeometryFromWkb(wkb)
## Import to Shapely geometry
from shapely.wkb import loads
line = loads(wkb)
ls = wkb.encode('hex')
## output
output_file = open(OUT_Addre & OUT_Name & ".txt", 'w')
output_file.write('\n' & ls.encode('utf-8'))
output_file.close()
Some errors message:
import ogr or wkb = geom.asWkb() "doesn't exist"