2

I am trying to reproject a shapefile from EPSG:2229 (NAD83 / California zone 5 (ftUS)) to EPSG:2163 (US National Atlas Equal Area (meters)).

Below is the code that does this transformation for a point in the shapefile:

import fiona
from fiona.crs import from_epsg
from pyproj import Proj, transform


# Open the shapefile we want to reproject and initiate original projection
shape = fiona.open(inputfile)
oriproj = Proj(shape.crs)

# Initiate output projection
outcrs = fiona.crs.from_epsg(2163)
outproj = Proj(outcrs)

# Create a new file where the transformed point shapefile will be written
with fiona.open(outputfile,'w',shape.driver,shape.schema.copy(),crs=outcrs) as output:
    for feat in shape:
        point = feat['geometry']['coordinates']
        x,y = point
        new_x,new_y = transform(oriproj,outproj,x,y)
        feat['geometry']['coordinates'] = (new_x,new_y)
        output.write(feat)

This process works well with lat/long to meter transformations and transformations that involve meters to meters (EPSG:2163 to EPSG:32620) but for some reason it is breaking when trying to transform from feet to meters.

After this transformation, the points maintain their original distribution, but are located off of the coast of Delaware (when they should be in Los Angeles County). I have a feeling this might be an origin issue but I'm not sure.

Has anyone had this issue before? And if so, how did you fix it?

  • You might see if it will unproject to 4269 (NAD83 lat/lon) to see whether the issue is in the original projCRS or the target projCRS. – mkennedy Mar 31 '16 at 0:49
  • @mkennedy Are you saying transform the shapefile to 4269 and see if that works? I also want to note that when I used ogr2ogr, it worked. I just want to find a solution that utilizes tools within python. – DavBar Mar 31 '16 at 14:43
  • Oh, I see, sorry about the suggestion. It might confirm that Fiona's doing something strange when units are feet, I just tried unprojecting two points in 2229, but using 26945 (CA 5 meters) and the lat/lon values were very far off (one in the middle of the country, the other in the Atlantic. PROJ4 wants false easting/northing in meters so Fiona's conversion may not be taking that into account when units are feet. – mkennedy Mar 31 '16 at 16:27
  • I tried the transformation from 2229 to 2230 (feet to feet) and I got really strange results again. When I used ogr2ogr to transform the original file to WGS84 and then pyproj/fiona to 2163, it worked perfectly. I'm surprised pyproj can't handle feet as a unit measurement. – DavBar Mar 31 '16 at 19:07
  • @mkennedy I fixed the issue. Pyproj was automatically converting the feet to meters when establishing a Proj object. The issue was resolved when I added: oriproj = Proj(shape.crs, preserve_units=True) – DavBar Mar 31 '16 at 19:34
3

Pyproj was automatically converting the feet to meters when establishing a Proj object. The issue was resolved when I added:

oriproj = Proj(shape.crs, preserve_units=True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.