PostGIS - Tipps und Tricks
Zur Navigation springen
Zur Suche springen
Siehe auch
SRID
Der SRID (projection identifier) wird an drei Orten verwaltet:
- In der geometry column: select SRID(the_geom) from mytable limit 5;
- As a constraint on the table for the geometry column: \d mytable
- In the geometry_columns system table: select * from geometry_columns;
Mit der Methode UpdateGeometrySRID([<schema_name>], <table_name>, <column_name>, <srid>) kann man die Kolonne aktualisieren.
Tipp: http://www.spatialreference.org/
shp2pgsql
Man beachte beim Import von Shapefiles das .prj File. Ohne weitere Angaben wird der SRID auf -1 gesetzt. Siehe SRID (Quelle).
Shapfeil Geodaten in Datenbank geo1 laden:
% shp2pgsql -s 21781 -I -W ISO-8859-1 gemeinden public.gemeinden > gemeinden.sql % psql -d geo1 -U geo1 -f gemeinden.sql
Eine Alternative zu shp2pgsql ist ogr2ogr von OGR.
PostGIS über http-Tool mit Google Earth verknüpfen
- mit Java, GML und Google Maps - Rendering roads on Google Maps using Java and PostGIS.
- thetimoneygroup.net - On-the-Fly Spatial Analysis With PostGIS and Google Earth.
- (mit Oracle XML-DB).
Von PostGIS direkt nach Google Earth
Man starte psql (Beispiel mit Box um Victoria, BC, Kanada):
-- Set output to unaligned
\a
-- Show only tuples
\t
-- Dump query to a file
\o my_kml_file.kml
-- Run your query
SELECT askml('my_line', 'description', 'SRID=3005;LINESTRING( 1190000
390000, 1200000 390000, 1200000 380000, 1190000 380000, 1190000 390000
)'::geometry);
-- Flush output your file and close the output stream
\o
Dann Doppelklick auf die KML-Datei und Google Earth startet!
Beispiel für einen Ausschnitt der Schweiz:
SELECT askml('the_geom', 'SRID=21781;LINESTRING(
480000 300000, 835000 300000, 835000 70000, 480000 70000, 480000 300000
)'::geometry);