Transforming Coordinates
PCL 0.9.1, or revision 109 of the trunk, provides a new module for transforming coordinates between spatial reference systems. It's easier to use than the transforms of OGR/OSR, and more complete than PyProjection?. It can also be installed and used independently of the rest of PCL, depending only on the PROJ.4? library. See HowToInstallReferencing?.
For the Impatient
>>> from cartography.referencing.srs import SpatialReference >>> from cartography.referencing.transform.proj4 import ProjTransform >>> utm13 = SpatialReference(epsg=26913) >>> wgs84 = SpatialReference(epsg=4326) >>> t = ProjTransform(utm13, wgs84) >>> transformed_coords = t.transform([(-105, 39), (-106, 40)]) [(499999.99999999889, 4316776.5830979366), (414639.53815663763, 4428236.0645195534)]
Details
As shown above the proj4 module has a ProjTransform? class, initialized from two instances of SpatialReference?. One is the source SRS, the other is the destination SRS.
t = ProjTransform(destination_srs, source_srs)
This class has a transform() method which takes a list of X,Y coordinate tuples (see above) and returns another such list
transformed_coords = t.transform(source_coords)
The order of the parameters goes a bit against the grain if you're accustomed to mapscript, but I think it makes more sense. Chain it all out like
transformed_coords = ProjTransform(destination_srs, source_srs).transform(source_coords)
and you see that on the right we have all the sources, and on the left all the outputs. I see it as a built-in hint.
Spatial Reference Systems
PCL's spatial reference systems are based on the PROJ.4 definitions. They can be constructed from either a list of proj parameters
srs = SpatialReference(["proj=utm", "zone=13", "ellips=GRS80", "datum=NAD83", "units=m", "no_defs"])
or with an integer EPSG code keyword argument
srs = SpatialReference(epsg=26913)
