Friday, April 10, 2009

Subquery of subquery PostGIS SQL

Had to create some polygons that represented the dissolved and buffered outlines of a region, that were then clipped to an artificial extent. Came up with the following SQL, which still makes me scratch my head when I look at it.

SELECT ST_Intersection(c1.diss_buff_geom, m.the_geom) AS intersection_geom, 
        c1.name AS name
    FROM (SELECT geomunion(the_geom) AS diss_buff_geom, name
        FROM (SELECT name, ST_Buffer((ST_Dump(the_geom)).geom, .12) AS the_geom 
            FROM coastlines) c
        WHERE c.name LIKE 'India' GROUP BY c.name) c1, 
            global_land_mask_v5 m
        WHERE ST_Intersects(c1.diss_buff_geom, m.the_geom) 
            AND c1.name = 'India';

Honestly... still hurts to look at this now.

Monday, April 6, 2009

Working with GDAL in C

Baby steps. Find the "ogr_capi_test.c" test program and compile it. Comes with GDAL library and is found in $GDAL_ROOT/ogr.

Compile with these flags: "gcc -g ogr_capi_test.c `gdal-config --libs` `gdal-config --cflags` -o ogr_capi_test"