grass-pg.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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>Geometry import from PostgreSQL table</h2>
  49. <em>v.in.db</em> creates a new vector (points) map from a database table
  50. containing coordinates. See <a href="v.in.db.html">here</a> for examples.
  51. <h2>PostGIS: PostgreSQL with vector geometry</h2>
  52. <a href=http://postgis.refractions.net/>PostGIS</a>:
  53. adds geographic object support to PostgreSQL.
  54. <h3>Example: Import from PostGIS</h3>
  55. In an existing PostGIS database, create the following table:
  56. <div class="code"><pre>
  57. CREATE TABLE test
  58. (
  59. id serial NOT NULL,
  60. mytime timestamp DEFAULT now(),
  61. text varchar,
  62. wkb_geometry geometry,
  63. CONSTRAINT test_pkey PRIMARY KEY (id)
  64. ) WITHOUT OIDS;
  65. # insert value
  66. INSERT INTO test (text, wkb_geometry)
  67. VALUES ('Name',geometryFromText('POLYGON((600000 200000,650000
  68. 200000,650000 250000,600000 250000,600000 200000))',-1));
  69. # register geometry column
  70. select AddGeometryColumn ('postgis', 'test', 'geometry', -1, 'GEOMETRY', 2);
  71. </pre></div>
  72. GRASS can import this PostGIS polygon map as follows:
  73. <div class="code"><pre>
  74. v.in.ogr dsn="PG:host=localhost dbname=postgis user=neteler" layer=test \
  75. output=test type=boundary,centroid
  76. v.db.select test
  77. v.info -t test
  78. </pre></div>
  79. <h4>Geometry Converters</h4>
  80. <ul>
  81. <li><a href=http://postgis.refractions.net/download/>PostGIS with shp2pgsql</a>:<br>
  82. <tt>shp2pgsql -D lakespy2 lakespy2 test > lakespy2.sql</tt>
  83. <BR><BR>
  84. <li><a href=http://e00pg.sourceforge.net/>e00pg</a>: E00 to PostGIS filter,
  85. see also <em><a href="v.in.e00.html">v.in.e00</a></em>.
  86. <BR><BR>
  87. <li>GDAL/OGR <a href=http://www.gdal.org/ogr/>ogrinfo and ogr2ogr</a>:
  88. GIS vector format converter and library, e.g. ArcInfo or SHAPE to PostGIS.<br>
  89. <tt>ogr2ogr -f "PostgreSQL" shapefile ??</tt>
  90. <BR><BR>
  91. </ul>
  92. <H2>SEE ALSO</H2>
  93. <em>
  94. <a HREF="db.connect.html">db.connect</a>,
  95. <a HREF="db.execute.html">db.execute</a>,<BR>
  96. <a HREF="databaseintro.html">Database management in GRASS GIS</a>,<BR>
  97. <a HREF="database.html">Help pages for database modules</a>,<BR>
  98. <a HREF="sql.html">SQL support in GRASS GIS</a>
  99. </em>
  100. <BR><BR>
  101. <em>
  102. <a href="http://www.PostgreSQL.org">PostgreSQL web site</a>,<BR>
  103. <a href="http://www.pgadmin.org/">pgAdmin graphical user interface</a>
  104. <p>
  105. Book: <a href="http://www.postgresql.org/docs/books/awbook.html">PostgreSQL:
  106. Introduction and Concepts</a> by Bruce Momjian<BR>
  107. <a href="http://www.postgresql.org/docs/">PostgreSQL Documentation</a><BR>
  108. <a href="http://techdocs.postgresql.org/">PostgreSQL Technical Documentation</a><BR>
  109. <a href="http://www.gdal.org/ogr/drv_pg.html">GDAL/OGR PostgreSQL driver documentation</a><BR>
  110. <a href="http://mapserver.gis.umn.edu/cgi-bin/wiki.pl?MapServerWiki">MapServer Wiki</a>
  111. </em>
  112. <p><i>Last changed: $Date$</i></p>
  113. <HR>
  114. <BR><a href=index.html>Help Index</a>
  115. </body>
  116. </html>