As part of a larger script I am extracting postgis geometries from WKT(got that part down) then I am trying to create an in_memory polygon geometry to be used in arcpy tools.
so far:
postgis_layer="select ST_Astext(st_force2d(shape)) from {}".format(fc2)
print postgis_layer
cur.execute(postgis_layer)
#good until here!
in_mry=arcpy.Polygon(arcpy.FromWKT((x for x in cur)))
print in_mry
#arcpy.Union_analysis(fc1,in_mry,output)
how do I go from arcpy.FromWKT to the arcpy.Polygon? then can I use that in the union tool? I do not want to save the geometries from postgis as feature classes
postgis_layer="select ST_Astext(st_force2d(shape)) from {}".format(fc2)
print postgis_layer
cur.execute(postgis_layer)
geoms=arcpy.Array()
for geom in cur:
print geom[0]
geoms.add(arcpy.FromWKT(geom[0]))
in_mry=arcpy.Polygon(geoms)
print in_mry
#arcpy.Union_analysis(fc1,in_mry,output)
select ST_Astext(st_force2d(shape)) from rmp_indicators.total_forest
POLYGON((535836.248384263 740131.124948196,535934.437164262 740343.250836283,535909.998236761 740114.438629866,535836.248384263 740131.124948196))
Traceback (most recent call last):
File "R:\Data\LUCZ_2017\Python_Scripts\Unclassified_Areas.py", line 53, in <module>
p.union_fcs('blah','rmp_indicators.total_forest','b')
File "R:\Data\LUCZ_2017\Python_Scripts\Unclassified_Areas.py", line 43, in union_fcs
geoms.add(arcpy.FromWKT(geom[0]))
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\arcobjects\arcobjects.py", line 48, in add
return convertArcObjectToPythonObject(self._arc_object.Add(*gp_fixargs(args)))
ValueError: Array: Add input not point nor array object
so I got until here:
polys=[arcpy.FromWKT(geom[0]) for geom in cur]
for x in polys:
print x
poly=arcpy.Polygon(polys)
polys works, but I do not know how to pass polys into the arcpy.Polygon
x prints out
<geoprocessing describe geometry object object at 0x24FAC2E0>
<geoprocessing describe geometry object object at 0x24FAC320>
<geoprocessing describe geometry object object at 0x24FAC360>
<geoprocessing describe geometry object object at 0x24FAC3A0>
<geoprocessing describe geometry object object at 0x24FAC3E0>
<geoprocessing describe geometry object object at 0x24FAC420>
<geoprocessing describe geometry object object at 0x24FAC460>
<geoprocessing describe geometry object object at 0x24FAC4A0>
<geoprocessing describe geometry object object at 0x24FAC4E0>
<geoprocessing describe geometry object object at 0x24FAC520>
so clearly the geometries are there, I just do not know how to pass them into the Polygon geometry. I am going to just try and use polys as the input to the union tool, maybe the arcpy.FromWKT automatically turns it into a functioning Polygon because it is one