Geography Reference
In-Depth Information
A Better Way to Transform?
You may be wondering if there is a better way to transform
coordinates. In fact, there are a bunch of ways to do it. For sim-
ple command-line transformations, you can use the cs2cs utility
that is part of the PROJ4 Cartographic Projections Library. This
library is used by virtually all OSGIS projects for doing transfor-
mations or “projecting on the fly.”
You can also transform entire datasets using ogr2ogr . Many of
the OSGIS applications provide a means to transform a dataset
to new coordinate system.
So, why use Ruby and PostGIS to do it? The point was to gen-
tly introduce you to the possibilities of scripting using both Post-
greSQL and the GeoRuby classes. Let's hope we succeeded in
whetting your appetite for further scripting endeavors.
We just need to know the proper EPSG code to specify in the query, in
this case 26906. If we run the program now, we get different-looking
coordinates—let's hope ones that make sense for a point in UTM Zone
6, NAD83:
$ ruby code/transform_point.rb -151 61
Input NAD27 point : -151, 61
Output UTM Zone 6 NAD83 point: 283625.288353973, 6769338.97358209
One other point before we leave this topic: note how we created a point
from the results of a query. We used the from_hex_ewkb(WKB) method
when creating the new point. This is the format that is returned when
we query a geometry column in a PostGIS layer. This handy method
makes it easy to create objects from the results of a query.
The GeoRuby classes can also be used with Ruby on Rails, opening up a
world of possibilities for integrating PostGIS and your web applications.
Finally, if you are thinking this example was a bit contrived, you are
right. However, there is a practical application. For example, suppose
you are writing an application (either web or desktop) that accepts user
input in one coordinate system but must store it in PostGIS in another.
The simple solution presented here is one way to do it. Of course, the
possibilities are endless. . . .
 
 
Search WWH ::




Custom Search