Wednesday, 6 September 2017

python - Converting EPSG:2284 to EPSG:4326 with pyproj


I have some points in EPSG:2284 and I'm trying to convert them to EPSG:4326 using pyproj, however I get weird results. When I go to the spatial reference website I see that there is an endpoint that does the conversion. When I use that instead I get the correct result.


Here is some code illustrating the different results:



from pyproj import Proj, transform
import requests

if __name__ == '__main__':

# points I want to convert from EPSG:2284 -> EPSG:4326
targets = [
(3669486.63386,11293013.10592,709.08004),
(3669559.13811,11292972.72831,711.60055),
(3669639.51308,11292851.48264,712.22258),

(3669800.62304,11292949.38118,714.75766),
]

for northing, easting, up in targets:
print "Converting", easting, northing

# Transform using pyproj (gives wrong answer)
WGS84 = Proj(init='EPSG:4326')
inp = Proj(init='EPSG:2284')
x, y = transform(inp, WGS84, easting, northing)

print x, y, "(with proj4)"

# Transform using spatialreference.org URL (gives correct answer)
url = "http://spatialreference.org/projection/?json=%7B%22type%22%3A%22Feature%22%2C%20%22geometry%22%3A%7B%22type%22%3A%22Point%22%2C%20%22coordinates%22%3A%5B{lon}%2C%20{lat}%5D%7D%2C%22properties%22%3A%7B%7D%7D&inref=EPSG:{inp}&outref=epsg:{outp}"
url = url.format(lon=easting, lat=northing, inp='2284', outp='4326')
x, y = requests.get(url).json()['coordinates']
print x, y, '(using spatialreference.org URL)'

Does anyone know why they are giving different result and what is wrong with the Pyproj code?




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...