GeometryFromText

From MapbenderWiki

Jump to: navigation, search

Contents

English

Connect to PostgreSQL

Connect to the database with your favorite programming interface.

Create PosgreSQL Table

Create a standard table with all the fields except the geometry (which would cause this to be a "feature" table)

CREATE TABLE the_table (gid int4, more_data varchar);

Add Geometry Column

Add a geometry column. This transforms the table into a "Feature Table" and allows using geographic operations defined by PostGIS.

SELECT AddGeometryColumn('the_database','the_table','the_geom','4326','POLYGON',2);

Add Geographic Feature to the Table using SQL

The following SQL-clause adds a geographic feature to the new table (a small traingle).

INSERT INTO the_table VALUES ('1','Some Text',GeometryFromText('POLYGON((7.1 50.1,7.1 50.2,7.2 50.1,7.1 50.1))', 4326));

Thats it.


Deutsch

Datenbankverbindung mit PostgreSQL

Stellen Sie eine Verbindung zur Datenbank mit der Entwicklungsumgebung Ihrer Wahl her.

PostgreSQL Tabelle erzeugen

Die folgende Syntax erstellt eine Standard-Tabelle in PostgreSQL (noch ohne Geometriefeld).

CREATE TABLE the_table (gid int4, more_data varchar);

Geometriespalte hinzufügen

Um Geometrien speichern und darauf geographische Operationen durchführen zu können muss die Tabelle in eine sogenannte "Feature Table" transformiert werden. Das erfolgt über die PostGIS-Funktion AddGeometryColumn.

SELECT AddGeometryColumn('the_database','the_table','the_geom','4326','POLYGON',2);

Geographisches Objekt über SQL hinzufügen

Der folgende SQL-Befehl fügt ein Dreieck als Geometrie in die Datenbank ein.

INSERT INTO the_table VALUES ('1','Some Text',GeometryFromText('POLYGON((7.1 50.1,7.1 50.2,7.2 50.1,7.1 50.1))', 4326));

Das wars schon.


Personal tools