Spatial Projections

Spatial Projections

(This is based entirely on the GDAL/OSR Tutorial and Python GDAL/OGR Cookbook.)

The ArchGDAL.SpatialRef, and ArchGDAL.CoordTransform types are lightweight wrappers around GDAL objects that represent coordinate systems (projections and datums) and provide services to transform between them. These services are loosely modeled on the OpenGIS Coordinate Transformations specification, and use the same Well Known Text format for describing coordinate systems.

Coordinate Systems

There are two primary kinds of coordinate systems. The first is geographic (positions are measured in long/lat) and the second is projected (such as UTM - positions are measured in meters or feet).

Creating Spatial References

import ArchGDAL; const AG = ArchGDAL

projstring2927 = AG.importEPSG(2927) do spref
    AG.toPROJ4(spref)
end
"+proj=lcc +lat_1=47.33333333333334 +lat_2=45.83333333333334 +lat_0=45.33333333333334 +lon_0=-120.5 +x_0=500000.0001016001 +y_0=0 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=us-ft +no_defs "

The details of how to interpret the results can be found in http://proj4.org/usage/projections.html.

In the above example, we constructed a SpatialRef object from the EPSG Code 2927. There are a variety of other formats from which SpatialRefs can be constructed, such as

We currently support a few export formats too:

Reprojecting a Geometry

AG.importEPSG(2927) do source
    AG.importEPSG(4326) do target
        AG.createcoordtrans(source, target) do transform
            AG.fromWKT("POINT (1120351.57 741921.42)") do point
                println("Before: $(AG.toWKT(point))")
                AG.transform!(point, transform)
                println("After: $(AG.toWKT(point))")
end end end end
Before: POINT (1120351.57 741921.42)
After: POINT (-122.598135130878 47.3488013802885)

References

Some background on OpenGIS coordinate systems and services can be found in the Simple Features for COM, and Spatial Reference Systems Abstract Model documents available from the Open Geospatial Consortium. The GeoTIFF Projections Transform List may also be of assistance in understanding formulations of projections in WKT. The EPSG Geodesy web page is also a useful resource. You may also consult the OGC WKT Coordinate System Issues page.