September 11, 2009

Gdal tools

Saving a portion of a map with gdal_translate

gdal_translate -of JPEG world.topo.bathy.200407.3x21600x21600.A1.png world.topo.bathy.200407.3x21600x21600.A1.jpg -srcwin 0 0 1000 1000 -co "WORLDFILE=YES"

Tiling with gdal for geoserver pyramid serving
gdal_retile -of JPEG -pyramidOnly -ps 256 256 -levels 5 -targetDir piramid world.topo.bathy.200407.3x21600x21600.A1.png

or for Geotiffs;

gdal_retile -levels 5 -pyramidOnly -targetDir pyramid bathymetry.tif

or
gdal_retile.py -v -r bilinear -levels 4 -ps 2048 2048 -co "TILED=YES"
-co "COMPRESS=JPEG" -targetDir bmpyramid bmreduced.tiff



With geoserver 2.0.2 it is a piece of cake to load this pyramid into geoserver...


Indexing with gdaltindex
geotiffPyramid\pyramid>gdaltindex -tileindex location test 1\*.tif

Creating a 3D image file from elevation data
gdaldem hillshade elevationGeotif.tif elevation.png

Adding overlay
gdaladdo -r average bath.tif 2 4 8 16 32 64 128

Merging geotiffs
gdal_merge -o c:\merged.tif *.tif

Translating a png image to geotiff
You should have a world file for the png file .If you know the bounds of the image and the resolution, you can produce this info from here http://egb13.net/2009/03/worldfile-calculator/.
You can download the image files from here :
http://visibleearth.nasa.gov/view_detail.php?id=7105

and the image bounds are (get more details from readme.pdf) :
[X].3x21600x21600.A1.[Y] 90N 180W 0N 90W 240
[X].3x21600x21600.B1.[Y] 90N 90W 0N 0W 240
[X].3x21600x21600.C1.[Y] 90N 0W 0N 90E 240
[X].3x21600x21600.D1.[Y] 90N 90E 0N 180E 240
[X].3x21600x21600.A2.[Y] 0N 180W 90S 90W 240
[X].3x21600x21600.B2.[Y] 0N 90W 90S 0W 240
[X].3x21600x21600.C2.[Y] 0N 0W 90S 90E 240
[X].3x21600x21600.D2.[Y] 0N 90E 90S 180E 240
An example world file:

0.004166666666666667
0.00000
0.00000
-0.004166666666666667
-180
90
and the tranlation command:
gdal_translate -a_srs wktGeoreferenceFile -of Gtiff input.png output.tif

Example wkt file content(wgs 84) :

GEOGCS["WGS 84",
DATUM["World Geodetic System 1984",
SPHEROID["WGS 84", 6378137.0, 298.257223563, AUTHORITY["EPSG","7030"]],
AUTHORITY["EPSG","6326"]],
PRIMEM["Greenwich", 0.0, AUTHORITY["EPSG","8901"]],
UNIT["degree", 0.017453292519943295],
AXIS["Geodetic longitude", EAST],
AXIS["Geodetic latitude", NORTH],
AUTHORITY["EPSG","4326"]]
Tiling a geotiff to smaller pieces
gdal_retile -targetDir targetdir -ps 2400 2400 a1.tif


Adding overviews to tiffs in a directory using sfk tool
sfk run -yes "gdaladdo -r average $file 2 4 8 16 32" .

Changing data type format of a Geotiff format (eg int16->Float32)
gdal_translate -ot Float32 input.tiff output.tiff


Scaling data in a Geotiff File(eg from meters to centimetes vice versa)
gdal_translate -scale 12615 12731 1.1 2.1  input.tif  WroclawDEM_output_scaled.tif




August 19, 2009

Howto convert geotiff elevation data to esri bil file format?

Use gdal tools, namely gdal_translate[1]. If your geotiff file has spatial specs encoded in it is really easy.

eg;
gdal_translate -of EHdr e020n40.Bathmetry.tif e020n40.bil

The gdal_translate command also creates the necessary bil header files.

[1] http://gdal.org/formats_list.html

Try to view the output with OpenEV.

August 05, 2009

Link Shell Extension

Hardlinks provide the ability to keep a single copy of a file yet have it appear in multiple folders (directories).

Now for NTFS it is possible to define new hard links, junctions etc. It is very useful if you use DropBox and sync different folders.

It is freeware, you can get it from the link below;

http://schinagl.priv.at/nt/hardlinkshellext/hardlinkshellext.html

July 29, 2009

Installing PostgreSQL and PostGIS - Part 3

Storing some geospatial data.
Following the steps documented in Postgis documentation here.
I have used pgadmin for accessing postgresql but psql will suffice too. I recommend pgadmin as it lets you see the spatial structures much more easily.


Step 1 - Create some normal table

CREATE TABLE roads (
road_id INTEGER,
road_name VARCHAR
);

Step 2 - Add a special column for spatial data

SELECT AddGeometryColumn( 'roads', 'roads_geom', -1, 'GEOMETRY',
 2 );

The 2 at the end of the sql command indicates the dimension of the geometry.

Step 3 - Add some data

BEGIN;
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (1,ST_GeomFromText('LINESTRING(191232 243118,191108 243242)',-1),'Jeff Rd');
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (2,ST_GeomFromText('LINESTRING(189141 244158,189265 244817)',-1),'Geordie Rd');
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (3,ST_GeomFromText('LINESTRING(192783 228138,192612 229814)',-1),'Paul St');
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (4,ST_GeomFromText('LINESTRING(189412 252431,189631 259122)',-1),'Graeme Ave');
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (5,ST_GeomFromText('LINESTRING(190131 224148,190871 228134)',-1),'Phil Tce');
INSERT INTO roads (road_id, roads_geom, road_name)
VALUES (6,ST_GeomFromText('LINESTRING(198231 263418,198213 268322)',-1),'Dave Cres');
COMMIT;

You can view the data from some postgis enabled application like uDIG or JGrass.

Related posts:
[1]Installing PostgreSQL and PostGIS - Part 1
[2]Installing PostgreSQL and PostGIS - Part 2

Installing PostgreSQL and PostGIS - Part 2

The previous step was [1].

Now installing postgis 1.4. Actually this consists of copying some dlls and running some scripts for creating spatial datatypes and functions.
My database name is deneme.

Installing

Step 1
Downloaded postgis and unzipped it, copied everything to the postgresql installation directory.
Step 2
Ran some sql scripts using psql. Followed the steps in postgis documentation here...

That was all...

Part 3 is for loading some data...

[1] Installing PostgreSQL and PostGIS - Part 1