123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
- <title>GRASS GIS manual: GRASS-PostgreSQL DB driver</title>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <link rel="stylesheet" href="grassdocs.css" type="text/css">
- </head>
- <body bgcolor="white">
- <img src="grass_logo.png" alt="GRASS logo">
- <hr class="header">
- <!-- meta page description: PostgreSQL driver -->
- <h1>PostgreSQL DB driver in GRASS</h1>
- <h2>KEYWORDS</h2>
- database, attribute table, driver
- <h2>DESCRIPTION</h2>
- The DB (database) driver name in GRASS is <b>pg</b>.
- <h2>Creating a PostgreSQL database</h2>
- A new database is created with <tt>createdb</tt>, see
- the <a href="http://www.postgresql.org/docs/manuals/">PostgreSQL
- manual</a> for details.
- <h2>Connecting GRASS to PostgreSQL</h2>
- <div class="code"><pre>
- # example for connecting to a PostgreSQL server:
- db.connect driver=pg database="host=myserver.osgeo.org,dbname=mydb"
- # password is asked interactively if not specified:
- db.login user=myname [pass=secret]
- db.connect -p
- db.tables -p
- </pre></div>
- <h2>Supported SQL commands</h2>
- All SQL commands supported by PostgreSQL.
- It's not possible to use C-like escapes (with backslash like \n etc)
- within the SQL syntax.
- <h2>Operators available in conditions</h2>
- All SQL operators supported by PostgreSQL.
- <h2>Adding an unique ID column</h2>
- Import vector module require an unique ID column which can
- be generated as follows in a PostgreSQL table:
- <div class="code"><pre>
- db.execute sql="ALTER TABLE mytable ADD ID integer"
- db.execute sql="CREATE SEQUENCE mytable_seq"
- db.execute sql="UPDATE mytable SET ID = nextval('mytable_seq')"
- db.execute sql="DROP SEQUENCE mytable_seq"
- </pre></div>
- <h2>Attribute import into PostgreSQL</h2>
- CSV import into PostgreSQL:
- <div class="code"><pre>
- \h copy
- COPY t1 FROM 'filename' USING DELIMITERS ',';
- </pre></div>
- <h2>Geometry import from PostgreSQL table into GRASS</h2>
- <em><a href="v.in.db.html">v.in.db</a></em> creates a new vector
- (points) map from a database table containing
- coordinates. See <a href="v.in.db.html">here</a> for examples.
- <h2>PostGIS: PostgreSQL with vector geometry</h2>
- <a href="http://postgis.refractions.net/">PostGIS</a>:
- adds geographic object support to PostgreSQL.
- <h3>Example: Import from PostGIS</h3>
- In an existing PostGIS database, create the following table:
- <div class="code"><pre>
- CREATE TABLE test
- (
- id serial NOT NULL,
- mytime timestamp DEFAULT now(),
- text varchar,
- wkb_geometry geometry,
- CONSTRAINT test_pkey PRIMARY KEY (id)
- ) WITHOUT OIDS;
- # insert value
- INSERT INTO test (text, wkb_geometry)
- VALUES ('Name',geometryFromText('POLYGON((600000 200000,650000
- 200000,650000 250000,600000 250000,600000 200000))',-1));
- # register geometry column
- select AddGeometryColumn ('postgis', 'test', 'geometry', -1, 'GEOMETRY', 2);
- </pre></div>
- GRASS can import this PostGIS polygon map as follows:
- <div class="code"><pre>
- v.in.ogr dsn="PG:host=localhost dbname=postgis user=neteler" layer=test \
- output=test type=boundary,centroid
- v.db.select test
- v.info -t test
- </pre></div>
- <h4>Geometry Converters</h4>
- <ul>
- <li><a href="http://postgis.refractions.net/download/">PostGIS with shp2pgsql</a>:<br>
- <tt>shp2pgsql -D lakespy2 lakespy2 test > lakespy2.sql</tt>
- </li>
- <li><a href="http://e00pg.sourceforge.net/">e00pg</a>: E00 to PostGIS filter,
- see also <em><a href="v.in.e00.html">v.in.e00</a></em>.
- </li>
- <li>GDAL/OGR <a href="http://www.gdal.org/ogr/">ogrinfo and ogr2ogr</a>:
- GIS vector format converter and library, e.g. ArcInfo or SHAPE to PostGIS.<br>
- <tt>ogr2ogr -f "PostgreSQL" shapefile ??</tt>
- </li>
- </ul>
- <h2>SEE ALSO</h2>
- <em>
- <a href="db.connect.html">db.connect</a>,
- <a href="db.execute.html">db.execute</a>
- </em>
- <p>
- <a href="databaseintro.html">Database management in GRASS GIS</a><br>
- <a href="database.html">Help pages for database modules</a><br>
- <a href="sql.html">SQL support in GRASS GIS</a><br>
- <h2>REFERENCES</h2>
- <ul>
- <li><a href="http://www.postgresql.org/">PostgreSQL web site</a></li>
- <li><a href="http://www.pgadmin.org/">pgAdmin graphical user interface</a></li>
- <li><a href="http://www.gdal.org/ogr/drv_pg.html">GDAL/OGR PostgreSQL
- driver documentation</a></li>
- </ul>
- <p>
- <i>Last changed: $Date$</i>
- <hr class="header">
- <p><a href="index.html">Main index</a> - <a href="database.html">Database index</a> - <a href="topics.html">Topics index</a> - <a href="keywords.html">Keywords Index</a> - <a href="full_index.html">Full index</a></p>
- <p>© 2003-2013 <a href="http://grass.osgeo.org">GRASS Development Team</a>, GRASS GIS 7.0.svn Reference Manual</p>
- </body>
- </html>
|