I want to save some geometry to a shapefile with the python27 module fiona
and manually specify the coordinate reference system (CRS).
Here's what I tried:
import fiona
import fiona.crs
outpath = "shape.shp"
schema = {'geometry': 'Point', 'properties': {'place': 'str'}}
point = {u"type": u"Point", u"coordinates": [0.0, 51.4769]}
properties = {'place': 'Greenwich'}
wgs84 = fiona.crs.from_epsg(4326)
with fiona.open(outpath, 'w', crs=wgs84, driver='ESRI Shapefile',
schema=schema) as layer:
layer.write({'geometry': point, 'properties': properties})
Unfortunately the shape.prj
file that's produced is empty, hence the CRS is not specified in the output file.
A little diagnostics: After running the script, the layer has the CRS specified:
In [10]: layer.crs
Out[10]: {'init': 'epsg:4326', 'no_defs': True}
Any idea what's going wrong there?
I can work around this issue by downloading the .PRJ file from spatialreference.org, placing it in the same folder and renaming it shape.prj
. I guess I'll figure out how to do that programmatically if there's no direct solution (should be easy).
from fiona.crs import from_espg
and change line 9 towgs84 = from_epsg(4326)
.import fiona.crs
, thecrs
submodule and hencefrom_epsg
shouldn't be available. I tried the changes suggested by @smiller and they give exactly the same result. Shouldn'tfrom_epsg
do the same thing no matter how you import it?conda uninstall fiona
andconda install fiona
)