Archive for February, 2007

rotation in postgis 0

It appears the rotate function in PostGIS only rotates the geometry about the center of the co-ordinate systems. There was a neat little trick that was mentioned on the postgis-list by Bruce Rindhal to rotate a polygon about its center:

CREATE TABLE shapes (gid serial PRIMARY KEY,  name varchar);
SELECT AddGeometryColumn('', 'shapes', 'the_geom', -1, 'POLYGON', 2);
INSERT INTO "shapes" ("the_geom", "name") VALUES (
       'POLYGON((2 2, 2 7, 12 7, 12 2, 2 2))', 'laying down');

Next we are going to translate the polygon’s centroid to (0,0). Rotate it by 45 degrees and then move it back to the original centroid.

SELECT
translate(
  rotate(
    translate( the_geom, -x(centroid(the_geom)), -y(centroid(the_geom)) ), 
    radians(45)
  ), 
  x(centroid(the_geom)), y(centroid(the_geom)) 
)
FROM shapes WHERE name = 'laying down';

postgis rotation
Without the translate on line 4 and line 2 and 7 it would look like this:
postgis rotation without translate

Ruby/GDAL How to open a dataset (1) 0

I’ll try to post some code snippets on the use of GDAL Ruby bindings. In case you don’t already know there is a bleeding edge gentoo overlay maintained by Kashif at gentoo geo-overlay
I am working on a howto for using that as well to build a gentoo box with some of the latest Open Source Geo-tools.

require 'gdal/gdal'
require 'gdal/gdalconst'
include Gdal
 
file = "./rasterdata.tif"
 
begin
  @dataset = Gdal::Gdal.open(file, Gdalconst::GA_READONLY)
    rescue RuntimeError
      $stderr.print "Gdal failed to open #{file}.\n"
    exit
end