PostGIS: Difference between revisions

From GRASS-Wiki
Jump to navigation Jump to search
Line 68: Line 68:


The direct read access avoids need of creating a link via {{cmd|v.external|version=70}} and accessing PostGIS data directly without creating any data elements in the current mapset. The main drawback of direct read access is that the pseudo-topology is built each time when accessing the data.
The direct read access avoids need of creating a link via {{cmd|v.external|version=70}} and accessing PostGIS data directly without creating any data elements in the current mapset. The main drawback of direct read access is that the pseudo-topology is built each time when accessing the data.
=== Direct write access ===


== See also ==
== See also ==

Revision as of 10:56, 29 October 2011

See also working with external data in GRASS 7.

Help pages

Link to external dataset

Import into GRASS

  1. v.in.ogr (import only geometry column from postgresql/postgis)
  2. v.clean

There is a fundamental difference between the PostGIS format which is non-topological (OGC simple feature-based) and the internal GRASS format which is topological and which, thus, does not really allow for overlapping polygons. You can digitize them, but they are not really useful...

Link to GRASS

You can register a PostGIS layer into GRASS using v.external, eg. PostGIS layer 'lakes' from database 'pgis_nc'

v.external dsn=PG:dbname=pgis_nc layer=lakes

It will create in the current mapset new vector map 'lakes', the module also builds pseudo-topology for this map,

Important note: In GRASS 6 this link is read-only, in GRASS 7 it's possible to modify linked layers directly via OGR library, see working with external data in GRASS 7.

You can also link a GRASS layer to a PostgreSQL attribute table, though v.db.connect.

Export to PostGIS

To export GRASS vector map layer to PostGIS layer use v.out.ogr, eg.

v.out.ogr in=lakes@PERMANENT dsn=PG:dbname=pgis_nc format=PostgreSQL type=area

Note that exporting data can be quite time-consuming task, especially when input vector map attributes are stored in DBF format. It's recommended to store attribute data in SQLite format rather then in old-fashioned DBF format. For example when exporting vector map 'lakes' from North Carolina sample dataset.

  • Attributes in DBF format
real    1m15.072s
user    1m6.160s
sys     0m3.824s
  • Attributes in SQLite format
real    0m11.796s
user    0m5.564s
sys     0m4.148s

Direct access to PostGIS data

Important note: Direct read/write access is implemented only in GRASS 7.

Direct read access

GRASS 7 enables the users to access PostGIS layers directly via virtual mapset 'OGR' and modules parameters map=OGR_datasource@OGR and layer=OGR_layer, eg. to access PostGIS layer 'lakes' from database 'pgis_nc'

v.info map=PG:dbname=pgis_nc@OGR layer=lakes

The direct read access avoids need of creating a link via v.external and accessing PostGIS data directly without creating any data elements in the current mapset. The main drawback of direct read access is that the pseudo-topology is built each time when accessing the data.

Direct write access

See also