source_srs = get_srs(shp_abs_path)
source_epsg = source_srs.GetAttrValue("PROJCS|GEOGCS|AUTHORITY", 1)
print source_epsg #prints 4269
target_epsg = 3857 # because these are headed to leafletjs
target_srs = osr.SpatialReference()
target_srs.ImportFromEPSG(target_epsg)
osr_transform = osr.CoordinateTransformation(source_srs, target_srs)
then as I enumerate through the shapefile I transform the bboxes on the fly
sf = shapefile.Reader(base_path)
shapeRecords = sf.shapeRecords() #will store the geometry separately
self.shapefile_records[fn] = shapeRecords
for i, shape in enumerate(sf.shapes()):
bbox = shape.bbox
## OGR/SRS TRANSFORMATION
point = ogr.Geometry(ogr.wkbPoint)
point.AddPoint(bbox[0],bbox[1])
point.Transform(osr_transform)
print point.GetX(), point.GetY()
point.AddPoint(bbox[2],bbox[3])
point.Transform(osr_transform)
print point.GetX(), point.GetY()
which prints coordinates like this…
-13613708.5846 4623834.1438
-13613668.296 4623869.60132
these put me out in the ocean I think, but they’re supposed to be in Napa county. Any suggestions are warmly welcomed. I can use almost any python lib.
NEW
I’ve identified an issue and I’m not sure if it’s with osgeo or the 4269 to 4326 transformation I’ve defined. Have a look at this output:
>>> from osgeo import ogr, osr
>>> source_srs = osr.SpatialReference()
>>> source_srs.ImportFromEPSG(4269)
0
>>> target_srs = osr.SpatialReference()
>>> target_srs.ImportFromEPSG(4326)
0
>>> osr_transformation = osr.CoordinateTransformation(source_srs, target_srs)
>>> point = ogr.Geometry(ogr.wkbPoint)
>>> point.AddPoint(6449750.845, 2001628.41312)
>>> point.Transform(osr_transformation)
0
>>> print point.Transform(osr_transformation)
0
>>> point.GetX(), point.GetY()
(6449750.845, 2001628.4131199997)
Nothing is modified. I’ve triple confirmed the data is in EPSG:4269 and included a shortened bitly link to it below in the comments.