I'm trying to start plotting maps in python with matplotlib's basemap, but every shapefile I've tried to far seems to have coordinates in metres instead of lat/lon, so I get the following error from readshapefile
:
ValueError: shapefile must have lat/lon vertices - it looks like this one has vertices in map projection coordinates.
Here's output from fiona
about the shapefile I'm using:
shape = fiona.open('./data/ESRI/London_Ward.shp')
bounds = shape.bounds
print(shape.crs)
: {'proj': 'tmerc', 'lat_0': 49, 'lon_0': -2, 'k': 0.999601272, 'x_0': 400000, 'y_0': -100000, 'datum': 'OSGB36', 'units': 'm', 'no_defs': True}
print(bounds)
: (503568.2, 155850.8, 561957.5, 200933.9)
ogr2ogr
is the only conversion tool I've managed to install so far, is it possible to use it to make the necessary conversion?
Best Answer
Yes, it is. Use it like this from the command line (might be necessary to
cd
into the folder where ogr2ogr has been installed to):If you want to run it from Python, you can use subprocess to set up the command and run it from the script, e.g. like this:
Alternatively, pass all parts of the command as a list like this:
In case you really want to stay within Python and don't use the command line, use the accepted answer from Python - OGR: Transform coordinates from meter to decimal degrees
Also have a look at the Documentation
EDIT: After working a bit more with
subprocess
, I would like to update the call to the following:subprocess
seems to like lists better than pure string commands.