Script: Ex- und Import von Shapes nach PostGIS

Dieses Script stellt ein HTML-Formular für den Export und Import von shapes direkt in und aus einer PostGIS-Datenbank bereit.

Zum Import packt man die drei Files, die zu einem shape gehören, in ein Zip-Paket und lädt diese hoch, das Script importiert dann die shapes in die PostGIS-Datenbank als Tabellen.

Zum Export gibt man Datenbank und Tabelle an und erhält ein Zip-Paket mit den drei Files, die zu einem Shape gehören, zum Download. Auspacken und weiterverarbeiten.

Das Script ist auf das SRS epsg:25833 fest angepasst - bei Durchsicht und entsprechender Anpassung des Scripts sollte man aber auch andere SRS verwenden können.

Voraussetzungen

  • eine PostgreSQL-Datenbank mit PostGIS-Aufsatz
  • einen Webserver mit PHP auf derselben Maschine wie die Datenbank
  • installiert: shp2pgsql und pgsql2shp (s. unten)
  • zip und unzip (von der Kommandozeile)

Das Script wurde unter ubuntu 8.04 entwickelt und wird dort eingesetzt. Mit ein paar Anpassungen sollte man es aber auch unter Windws zum Laufen bringen.

ACHTUNG* Es handelt sich um Workware, das bedeutet, es sind keine Sicherheits-Abfragen eingebaut. Bei der Anwendung sollte der Administrator wissen, was er tut. Vielleicht findet sich noch jemand, der diese Script noch verfeinert und vielleicht sogar ins phppgadmin einbaut? ;-)

Eigentlich unnötig zu erwähnen:

DIE BENUTZUNG ERFOLGT AUF EIGENE GEFAHR. 
ES WIRD KEINERLEI GARANTIE ÜBERNOMMEN.

oder?

Download

Installation

  • Download
  • Auspacken und in ein Verzeichnis hinter den Webserver legen
  • Script öffnen, ReadMe lesen und entsprechende Angaben einbauen
  • Im Browser aufrufen - sollte laufen :-)

Debugging

Tipps wenns nicht gleich läuft:

  • PHP.ini: Hochladen von Files: alles so eingerichtet, wie es sein sollte?
  • Ausführen der einzelnen Befehle „zu Fuß“ auf der Kommandozeile - meist sieht man dann, wo es hakt.

Besten Dank an einen Kollegen.

Viel Spaß

Rückmeldungen sehr erwünscht!

Shape nach PostGIS und PostGIS nach shape

shp-pg Tools

Version Postgis 1.3.3 (November 2008)

Installation:

  1. Zip-Paket in ein Verzeichnis (z.B. C:\Programme\shp-pg-Tools\) entpacken.
  2. Installationsort der Umgebungsvariable PATH hinzufügen

Verwendung:

Kommandozeile:

SQL-File zu shape umwandeln:

C:\>pgsql2shp
RCSID: $Id: pgsql2shp.c,v 1.74.2.6 2005/10/24 16:12:41 strk Exp $
USAGE: pgsql2shp [<options>] <database> [<schema>.]<table>
       pgsql2shp [<options>] <database> <query>

OPTIONS:
  -f <filename>  Use this option to specify the name of the file
     to create.
  -h <host>  Allows you to specify connection to a database on a
     machine other than the default.
  -p <port>  Allows you to specify a database port other than the default.
  -P <password>  Connect to the database with the specified password.
  -u <user>  Connect to the database as the specified user.
  -g <geometry_column> Specify the geometry column to be exported.
  -b Use a binary cursor.
  -r Raw mode. Do not assume table has been created by
     the loader. This would not unescape attribute names
     and will not skip the 'gid' attribute.
  -k Keep postgresql identifiers case.

shape zu SQL-File umwandeln

  
C:\>shp2pgsql
RCSID: $Id: shp2pgsql.c 2764 2008-04-12 16:44:55Z pramsey $ RELEASE: 1.3.3
USAGE: shp2pgsql [<options>] <shapefile> [<schema>.]<table>
OPTIONS:
  -s <srid>  Set the SRID field. If not specified it defaults to -1.
  (-d|a|c|p) These are mutually exclusive options:
      -d  Drops the table, then recreates it and populates
          it with current shape file data.
      -a  Appends shape file into current table, must be
          exactly the same table schema.
      -c  Creates a new table and populates it, this is the
          default if you do not specify any options.
      -p  Prepare mode, only creates the table.
  -g <geometry_column> Specify the name of the geometry column
     (mostly useful in append mode).
  -D  Use postgresql dump format (defaults to sql insert statments.
  -k  Keep postgresql identifiers case.
  -i  Use int4 type for all integer dbf fields.
  -I  Create a GiST index on the geometry column.
  -S  Generate simple geometries instead of MULTI geometries.
  -w  Use wkt format (for postgis-0.x support - drops M - drifts coordinates).
  -W <encoding> Specify the character encoding of Shape's
     attribute column. (default : "ASCII")
  -N <policy> Specify NULL geometries handling policy (insert,skip,abort)
  -n  Only import DBF file.
  -? Display this help screen
shape_postgis_tools.txt · Zuletzt geändert: 2009/07/07 23:32 von kbl