grass-pg.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>GRASS-PostgreSQL driver</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. <link rel="stylesheet" href="grassdocs.css" type="text/css">
  7. </head>
  8. <body bgcolor="white">
  9. <img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade>
  10. <h1>PostgreSQL driver in GRASS</h1>
  11. The driver name is 'pg'.
  12. <H2>Creating a PostgreSQL database</H2>
  13. A new database is created with 'createdb', see the PostgreSQL manual
  14. for details.
  15. <H2>Connecting GRASS to PostgreSQL</H2>
  16. <div class="code"><pre>
  17. # example for connecting to a PostgreSQL server:
  18. db.connect driver=pg database="host=myserver.osgeo.org,dbname=mydb"
  19. # password is asked interactively if not specified:
  20. db.login user=myname [pass=secret]
  21. db.connect -p
  22. db.tables -p
  23. </pre></div>
  24. <H2>Supported SQL commands</H2>
  25. All SQL commands supported by PostgreSQL.
  26. <H2>Operators available in conditions</H2>
  27. All SQL operators supported by PostgreSQL.
  28. <H2>Adding an unique ID column</H2>
  29. Import vector module require an unique ID column which can
  30. be generated as follows in a PostgreSQL table:
  31. <div class="code"><pre>
  32. echo "
  33. ALTER TABLE mytable ADD ID integer;
  34. CREATE SEQUENCE mytable_seq;
  35. UPDATE mytabe SET ID = nextval('mytable_seq');
  36. DROP SEQUENCE mytable_seq;
  37. " | db.execute
  38. </pre></div>
  39. <h2>Attribute Converters</h2>
  40. CSV import into PostgreSQL:
  41. <div class="code"><pre>
  42. \h copy
  43. COPY t1 FROM 'filename' USING DELIMITERS ',';
  44. </pre></div>
  45. <a href=http://www.klaban.torun.pl/prog/pg2xbase/>pg2xbase</a>:
  46. DBF to PostgreSQL converter.
  47. <BR>
  48. <h2>PostGIS: PostgreSQL with vector geometry</h2>
  49. <a href=http://postgis.refractions.net/>PostGIS</a>:
  50. adds geographic object support to PostgreSQL.
  51. <h3>Example: Import from PostGIS</h3>
  52. In an existing PostGIS database, create the following table:
  53. <div class="code"><pre>
  54. CREATE TABLE test
  55. (
  56. id serial NOT NULL,
  57. mytime timestamp DEFAULT now(),
  58. text varchar,
  59. wkb_geometry geometry,
  60. CONSTRAINT test_pkey PRIMARY KEY (id)
  61. ) WITHOUT OIDS;
  62. # insert value
  63. INSERT INTO test (text, wkb_geometry)
  64. VALUES ('Name',geometryFromText('POLYGON((600000 200000,650000
  65. 200000,650000 250000,600000 250000,600000 200000))',-1));
  66. # register geometry column
  67. select AddGeometryColumn ('postgis', 'test', 'geometry', -1, 'GEOMETRY', 2);
  68. </pre></div>
  69. GRASS can import this PostGIS polygon map as follows:
  70. <div class="code"><pre>
  71. v.in.ogr dsn="PG:host=localhost dbname=postgis user=neteler" layer=test \
  72. output=test type=boundary,centroid
  73. v.db.select test
  74. v.info -t test
  75. </pre></div>
  76. <h4>Geometry Converters</h4>
  77. <ul>
  78. <li><a href=http://postgis.refractions.net/download/>PostGIS with shp2pgsql</a>:<br>
  79. <tt>shp2pgsql -D lakespy2 lakespy2 test > lakespy2.sql</tt>
  80. <BR><BR>
  81. <li><a href=http://e00pg.sourceforge.net/>e00pg</a>: E00 to PostGIS filter,
  82. see also <em><a href="v.in.e00.html">v.in.e00</a></em>.
  83. <BR><BR>
  84. <li>GDAL/OGR <a href=http://www.gdal.org/ogr/>ogrinfo and ogr2ogr</a>:
  85. GIS vector format converter and library, e.g. ArcInfo or SHAPE to PostGIS.<br>
  86. <tt>ogr2ogr -f "PostgreSQL" shapefile ??</tt>
  87. <BR><BR>
  88. </ul>
  89. <H2>SEE ALSO</H2>
  90. <em>
  91. <a HREF="db.connect.html">db.connect</a>,
  92. <a HREF="db.execute.html">db.execute</a>,<BR>
  93. <a HREF="databaseintro.html">Database management in GRASS GIS</a>,<BR>
  94. <a HREF="database.html">Help pages for database modules</a>,<BR>
  95. <a HREF="sql.html">SQL support in GRASS GIS</a>
  96. </em>
  97. <BR><BR>
  98. <em>
  99. <a href="http://www.PostgreSQL.org">PostgreSQL web site</a>,<BR>
  100. <a href="http://www.pgadmin.org/">pgAdmin graphical user interface</a>
  101. <p>
  102. Book: <a href="http://www.postgresql.org/docs/books/awbook.html">PostgreSQL:
  103. Introduction and Concepts</a> by Bruce Momjian<BR>
  104. <a href="http://www.postgresql.org/docs/">PostgreSQL Documentation</a><BR>
  105. <a href="http://techdocs.postgresql.org/">PostgreSQL Technical Documentation</a><BR>
  106. <a href="http://www.gdal.org/ogr/drv_pg.html">GDAL/OGR PostgreSQL driver documentation</a><BR>
  107. <a href="http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?MapServerWiki">MapServer Wiki</a>
  108. </em>
  109. <p><i>Last changed: $Date$</i></p>
  110. <HR>
  111. <BR><a href=index.html>Help Index</a>
  112. </body>
  113. </html>