It is very difficult to just "scratch the surface" of GIS. You don't have to dig very deep into this field before you uncover some of the eccentricities of geographic data. Map projections are one such feature that is easy to understand at a basic level but has huge implications for geospatial programmers.
Map projections are conceptually straight-forward and intuitive. If you try to take any three-dimensional object and flatten it onto a plane, such as your screen or a sheet of paper, the object is distorted. (Remember the orange peel experiment from 7th grade geography?) You can manipulate this distortion to preserve common properties such as area, scale, bearing, distance, shape, etc.
I won't go into the details of map projections as there are thousands of web pages and online videos devoted to the subject. But there are some things you need to know for dealing with them programmatically. First of all, most geospatial data formats don't even contain any information about map projections. This lack of metadata is really mostly just geospatial cultural history with some technical reasons. And furthermore, while the concept of map projections is easy to grasp, the math to transform a coordinate from one projection to another is quite complex. The end result is most data libraries don't deal with projections in any way.
But now, thanks to modern software and the Internet making data exchange easier and more common, nearly every data format, both images and vector, have tacked on a metadata format that defines the projection. For shapefiles this is the .prj projection file which follows the naming convention
If you do need to deal with projections programmatically you basically have one choice: the PROJ4 library. It is one of the few free libraries, if not the only library period, that comprehensively deals with re-projecting goespatial data. Fortunately it has bindings for just about every language out there and is incorporated into many libraries including OGR. There is a Python project called pyproj which provides python bindings.
So be aware that projections are not trivial and can often add a lot of complexity to what would otherwise be a simple programming project. And also know that pyshp does nothing to work with map projections. I did an earlier post on how to create a .prj file for a shapefile and why I chose not to include this functionality in the library itself.
Here are some other resources related to map projections.
SpatialReference.org - a clearning house for projection definitions
PROJ4 - the #1 map projection library
OGR2OSM - Python script to convert OGR vector formats to the Open Street Map format with projection support
PyProj - Python bindings for Proj4 library
GDAL - Python bindings to GDAL which contains OGR and PROJ4 allowing you to reporject raster and vector data
No comments:
Post a Comment