Change spatial reference of JSON input coords

2544
2
Jump to solution
01-06-2016 07:13 AM
JamesCrandall
MVP Frequent Contributor

I'm trying to figure out how to project individual polygon features that I'm constructing from a JSON input that gets parsed from coordinates.  The input looks like this:

feature_info = """[{"rings":[[[-9050993.00, 3222038.00],[-9049770.00, 3220509.00],[-9047629.00, 3213783.00],[-9054356.00, 3215923.00],[-9050993.00, 3222038.00]]]}]"""

I do not have problems creating the polygon, however I need to project the feature (see the inSr and outSr variables for their WKID's).  Again, no problems with the projection to that desired system!  But the units are in US Foot and I need it to be in Meters.

Apparently, this property is read only and does not change it:

inSr = arcpy.SpatialReference(3857)
outSr = arcpy.SpatialReference(26758)
outSr.linearUnitName = 'Meter' #this does nothing

Then I see that some have successfully just altered the desired output SpatialReference by manipulating the string value of the projection like this, but again, it still doesn't change the unit to meters for me.  Maybe you can spot the issue?

outSr.loadFromString(re.sub('PARAMETER\[\'Unit\', Foot_US]', 'PARAMETER\[\'Unit\', Meter]', outSr.exportToString())) 
print arcpy.SpatialReference.exportToString(outSr)
0 Kudos
1 Solution

Accepted Solutions
JamesCrandall
MVP Frequent Contributor

Even better solution is to just set proper parameters on the .getArea() method:

prjpolygon = polygon.projectAs(outSr)
sqmeters = prjpolygon.getArea('PLANAR','Meters')

View solution in original post

2 Replies
JamesCrandall
MVP Frequent Contributor

I think I can just apply some simple math to arrive at a solution but feel free to shoot it down and suggest a better way!

prjpolygon = polygon.projectAs(outSr)
parea = prjpolygon.getArea()
sqmeters = parea * 0.09290304
0 Kudos
JamesCrandall
MVP Frequent Contributor

Even better solution is to just set proper parameters on the .getArea() method:

prjpolygon = polygon.projectAs(outSr)
sqmeters = prjpolygon.getArea('PLANAR','Meters')