Tag: Please help Jason Scheirer
After running down the path of geoJSON, I've finally encountered some difficulty in setting the spatial reference on a polygon feature. In the code below, I thought I could get away with somehow setting the spatial ref on arcpy.AsShape() method but now I'm stuck on what to do!
The problem seems to be that my polygon.projectAs(outSr) is not working, I presume because the input polygon feature does not have the inSr set?
polygon = arcpy.AsShape(v) # <-- does not have a spatial ref at this point prjpolygon = polygon.projectAs(outSr)
Input JSON coordinates are web Mercator (Auxiliary Sphere).
Hopefully I'm just missing the obvious.
data = {}
feature_info = """[{"rings":[[[-9020934.359395614,3186437.9104202176],[-9020934.359395612,3186323.2548777903],[-9021029.90568097,3185711.7586515094],[-9021794.27596382,3185941.0697363648],[-9020934.359395614,3186437.9104202176]]]}]"""
def geo_convert(ring_string):
from json import loads, dumps
rings = loads(ring_string)
feat_coll = {'type': 'FeatureCollection',
'features':[]}
for ring in rings:
feat_coll['features'].append(
{'type': 'Feature',
'geometry': {
'type': 'Polygon',
'coordinates': [ring['rings'][0]]
}})
return dumps(feat_coll)
tmpArr = []
jsonFrmt = geo_convert(feature_info)
jsonData = json.loads(jsonFrmt)
inSr = arcpy.SpatialReference(3857)
outSr = arcpy.SpatialReference(26758)
for key,value in jsonData.iteritems():
if value == 'FeatureCollection':
pass
else:
for i in value:
try:
for k,v in i.iteritems():
if k == 'geometry':
polygon = arcpy.AsShape(v) #cannot set a sr
#project to output sr
prjpolygon = polygon.projectAs(outSr) #does not project
else:
pass
except:
pass
Solved! Go to Solution.