Reprojection
While reprojection is less common these days, because of more advanced methods of data distribution, sometimes you need to reproject a shapefile. The pure Python utm
module works for reference system conversion, but for a full reprojection we need some help from the OGR Python API.
As an example we'll use a point
shapefile containing museum and gallery locations in the Lambert conformal projection. We'll reproject it to WGS84 geographic (or unproject it rather). You can download this zipped shapefile at:
https://geospatialpython.googlecode.com/files/NYC_MUSEUMS_LAMBERT.zip
The following minimalist script reprojects the shapefile. The geometry is transformed and then written to the new file, but the dbf
file is simply copied to the new name as we aren't changing it. The standard Python shutil
module, short for shell utilities, is used to copy dbf
. The source and target shapefile names are variables at the beginning of the script. The target projection is also near the top which...