GRASS logo

NAME

v.in.postgis - Create a grass layer from any sql query in postgis

KEYWORDS

postgis, db, sql

SYNOPSIS

v.in.postgis
v.in.postgis help
v.in.postgis [-dzrg] sqlquery=string geometryfield=string [output=string]

Flags:

-d
import result in grass dbf format (no new table in postgis). If not set, the grass layer will be directly connected to the postgis new table
-z
use -z for v.in.ogr (create 3D output)
-r
use -o for v.in.ogr (override dataset projection)
-g
add a gist index to the imported table in postgis (useless with the d flag)

Parameters:

query=name
Any sql query returning a recordset with geometry for each row
geometryfield=name
Name of the source geometry field. Usually defaults to the_geom but needed if a geometry function was used (for example, centroid), or if the table has many geometry columns
output=name
Name of the geographic postgis table where to place the query results. Will be the name of the imported grass layer. If -d flag is set, this table is deleted and replaced by a dbf attribute table. Use a different name than the original. Do not use capital letters

DESCRIPTION

v.in.postgis is a shell script to import as a grass layer the result of any sql query returning geometry. There are two main modes : i)grass native format import with attributes in a dbf file. No tables are added in PostGIS ; ii)Grass layer import with attributes directly connected to a temporary table in PostGIS containing the query results. Before using the script, db.connect (and eventually db.login) commands must have been called. The script has been tested with Linux and WinGrass. However, for winGrass, you should modify the home directory setting at the beginning of the script. Logfile is written in the directory specified by the LOGFILE environment variable (default : home directory).

EXAMPLES

  • PostGIS sql query to grass map (dbf attributes table, no new table in postgis)
    v.in.postgis -d query="SELECT * FROM zones, data WHERE zones.zone_id=data.zone_id AND value > 100" output=zones
    
  • work in Grass directly on a PostGIS table (a new table is added in postgis, create a gist index)
    v.in.postgis -r -g query="SELECT value, centroid(geocolumn) AS locations FROM zones, data WHERE zones.zone_id=data.zone_id 
    GROUP BY name" geometryfield=locations output=locations
    

    SEE ALSO

    db.connect, db.login, v.in.ogr,

    AUTHOR

    Mathieu Grelier, greliermathieu@gmail.com

    Last changed : 2009/07/02


    Main index - vector index - Full index