2

I have a shapefile of San Francisco that I successfully loaded but I need to convert the coordinates to longitude/latitude form. The variables I have are as follows:

w1 = x coordinates w2 = y coordinates

Currently the coordinates look like this:

print(w1[0], w2[0])
6017864.66784 2104744.54451

I've tried to convert the points like such:

from pyproj import Proj, transform
inProj = Proj(init='epsg2227')
outProj = Proj(init='epsg4326')
x1, y1 = w1[0], w2[0]
x2, y2 = transform(inProj, outProj, x1, y1)
print(x2, y2)
-70.44154167927961 41.036642156063856

San Francisco's coordinates are approximately -122 degrees west and 37.7 degrees north. I believe my problem is that my inProj and outProj commands have the wrong epsg but I can't figure out what I should be. Any help would be greatly appreciated.

DDoubleU
  • 51
  • 3

1 Answers1

0

I just learned more about pyproj than I had originally intended:

All you need to do is add preserve_units = True to your Projection aliases:

w1=[1]
w2=[1]
w1[0]=6010936.158609
w2[0]=2090667.302531
from pyproj import Proj, transform
inProj = Proj(init='epsg:2227', preserve_units=True)
outProj = Proj(init='epsg:4326', preserve_units=True)
x1, y1 = w1[0], w2[0]
x2, y2 = transform(inProj, outProj, x1, y1)
print(x2, y2)

[out]: -122.4, 37.8

Basically all preserve_units does will use local units instead of standard meters.

here's the git page

Here is the transform page

Basically 2227 is in US survey foot units and 4326 is in degrees and it was treating both as meters

EoinS
  • 5,405
  • 1
  • 19
  • 32