[GRASSLIST:8058] GRASS - PGSQL - PostGIS

Hello,

since a few days I am back on the GRASS-Postgresql issue, this time using
GRASS 6, Postgis, Postgresql 7.4 (deb repository), however I am stumbling
over a few problems:

so far I did:

install GRASS
install Postgresql 7.4.7

createuser
createdb grass_pg

install PostGIS (deb unstable)

createlang plpgsql grass_pg

inside GRASS

db.login driver=pg database=grass_pg
db.connect driver=pg database=grass_pg
v.db.connect map=soils driver=pg database=grass_pg table=test_tb key=cat

layer=1 -o

GRASS_INFO_WARNING(6534,1): Table <test_tb> does not exist in database

<grass_pg>

GRASS_INFO_WARNING(6534,2): The table <test_tb> is now part of vector map

<soils2> and may be deleted or overwritten by GRASS modules.

v.to.db map=soils2 type=point,line,boundary,centroid layer=1 qlayer=1

option=cat units=meters
DBMI-Postgres driver error:
Cannot select:
SELECT cat FROM test_tb
ERROR: relation "test_tb" does not exist
Updating database ... Segmentation fault

which point did I miss?

However I would love to have a tutorial how to use GRASS in conjunction with
Postgresql which tells me which software I do need and how I initialise this
cross-package functionality. I haven't found a link to a tutorial, in case I
missed it, I would be glad if you can send a link.

regards, Martin

--
Martin Wegmann

DLR - German Aerospace Center
German Remote Sensing Data Center
@
Dept.of Geography
Remote Sensing and Biodiversity Unit
&&
Dept. of Animal Ecology and Tropical Biology
University of Wuerzburg
Am Hubland
97074 Würzburg

phone: +49-(0)931 - 888 4797
mobile: +49-(0)175 2091725
fax: +49-(0)931 - 888 4961
http://www.biota-africa.org
http://www.biogis.de

Hello Martin,

On Thu, 25 Aug 2005 12:18:10 +0200 Martin Wegmann
<wegmann@biozentrum.uni-wuerzburg.de> wrote:

Hello,

since a few days I am back on the GRASS-Postgresql issue, this time
using GRASS 6, Postgis, Postgresql 7.4 (deb repository), however I am
stumbling over a few problems:

so far I did:

install GRASS
install Postgresql 7.4.7
> createuser
> createdb grass_pg

install PostGIS (deb unstable)
> createlang plpgsql grass_pg

same here, works flawlessly...

inside GRASS
>db.login driver=pg database=grass_pg
> db.connect driver=pg database=grass_pg

OK, correct. Now import our tables to postgres.
g.copy vect=soils,soils_pg

Be aware that now only your attribute-data is stored inside postgres.
PostGIS does not come into play here. geometry data is in native
GRASS6-vector-format.

to load your GRASS-vectors to postgis, you could use v.out.ogr to
import to PostGIS both geometry and attributes:

v.out.ogr input=polygons type=area dsn="PG:host=localhost
dbname=postgis user=postgres" olayer=soils format=PostgreSQL

To use the exported map in GRASS relink it to your grassdata using the
command v.external.

>v.db.connect map=soils driver=pg database=grass_pg table=test_tb
>key=cat
layer=1 -o
>GRASS_INFO_WARNING(6534,1): Table <test_tb> does not exist in
>database
<grass_pg>
>GRASS_INFO_WARNING(6534,2): The table <test_tb> is now part of
>vector map
<soils2> and may be deleted or overwritten by GRASS modules.

This assumes that the table test_tb is available in your db grass_pg.

>v.to.db map=soils2 type=point,line,boundary,centroid layer=1
>qlayer=1
option=cat units=meters
DBMI-Postgres driver error:
Cannot select:
SELECT cat FROM test_tb
ERROR: relation "test_tb" does not exist
Updating database ... Segmentation fault

which point did I miss?

However I would love to have a tutorial how to use GRASS in
conjunction with Postgresql which tells me which software I do need
and how I initialise this cross-package functionality. I haven't
found a link to a tutorial, in case I missed it, I would be glad if
you can send a link.

Actually I do not have a link at hand, but perhaps we should set up a
wiki-entry for this kind of problem?
Volunteers?

Best
  Stephan

--
GDF Hannover - Solutions for spatial data analysis and remote sensing
Hannover Office - Mengendamm 16d - D-30177 Hannover
Internet: www.gdf-hannover.de - Email: holl@gdf-hannover.de
Phone : ++49-(0)511.39088507 - Fax: ++49-(0)511.39088508

hello Stephan,

On Thursday 25 August 2005 12:41, Stephan Holl wrote:
[...]

> inside GRASS
>
> >db.login driver=pg database=grass_pg
> > db.connect driver=pg database=grass_pg

OK, correct. Now import our tables to postgres.
g.copy vect=soils,soils_pg

why that command? It is important for the pgsql connection or rather to have
it in the current mapset?

Be aware that now only your attribute-data is stored inside postgres.
PostGIS does not come into play here. geometry data is in native
GRASS6-vector-format.

to load your GRASS-vectors to postgis, you could use v.out.ogr to
import to PostGIS both geometry and attributes:

v.out.ogr input=polygons type=area dsn="PG:host=localhost
dbname=postgis user=postgres" olayer=soils format=PostgreSQL

v.out.ogr input=soils type=area dsn="PG:host=localhost dbname=grass_pg
user=baliola" olayer=soils format=PostgreSQL

works fine and entering pgsql

psql grass_pg
\d

shows up with the tables and it seems to be correct.

thanks!

Just one curious question, if I do

v.distance from=soils2 to=soils2 upload=dist column=dist out=test_dist_1000m

from_type=centroid to_type=centroid -a dmax=1000

g.copy vect=test_dist_1000m,test_dist_1000m_pg
v.out.ogr input=test_dist_1000m_pg type=point dsn="PG:host=localhost

dbname=grass_pg user=baliola" olayer=dist_1000m format=PostgreSQL

and enter PGSQL

psql grass_pg
select * from dist_1000m_p;

I get:

ogc_fid | wkb_geometry
    | cat
---------+----------------------------------------------------------------------
----+-----
       1 | \001\001\000\000\000\303\365(\\\340\217"Aq=\012\367\035\277RA
    |
       2 | \001\001\000\000\000\\\217\302\365\265\212"A\366(\\/\207\277RA
    |
       3 | \001\001\000\000\000\303\365(\334\322\227"A333\003D\277RA

which looks for me pretty weird. How do I solely extract the distance values
into PGSQL?
The general question would be, "how do I export single columns only?"

To use the exported map in GRASS relink it to your grassdata using the
command v.external.

[...]

>
> However I would love to have a tutorial how to use GRASS in
> conjunction with Postgresql which tells me which software I do need
> and how I initialise this cross-package functionality. I haven't
> found a link to a tutorial, in case I missed it, I would be glad if
> you can send a link.

Actually I do not have a link at hand, but perhaps we should set up a
wiki-entry for this kind of problem?
Volunteers?

yeeph, I would volunteer, however I can provide the rough first steps only;
the nifty bits and pieces are not yet in my repertoire.

cheers Martin

Hello Martin,

On Thu, 25 Aug 2005 14:28:32 +0200 Martin Wegmann
<wegmann@biozentrum.uni-wuerzburg.de> wrote:

hello Stephan,

On Thursday 25 August 2005 12:41, Stephan Holl wrote:
[...]
> > inside GRASS
> >
> > >db.login driver=pg database=grass_pg
> > > db.connect driver=pg database=grass_pg
>
> OK, correct. Now import our tables to postgres.
> g.copy vect=soils,soils_pg

why that command? It is important for the pgsql connection or rather
to have it in the current mapset?

No, this copies the dataset and adds the addtribute-data into Postgres.

> Be aware that now only your attribute-data is stored inside
> postgres. PostGIS does not come into play here. geometry data is in
> native GRASS6-vector-format.
>
> to load your GRASS-vectors to postgis, you could use v.out.ogr to
> import to PostGIS both geometry and attributes:
>
> v.out.ogr input=polygons type=area dsn="PG:host=localhost
> dbname=postgis user=postgres" olayer=soils format=PostgreSQL

v.out.ogr input=soils type=area dsn="PG:host=localhost
dbname=grass_pg user=baliola" olayer=soils format=PostgreSQL

works fine and entering pgsql

>psql grass_pg
>\d
shows up with the tables and it seems to be correct.

As I said, this has fed both geometr and attributes into postGIS. you
cannot digitize on this map any more (you "exported" the map into
postgis).

thanks!

Just one curious question, if I do

>v.distance from=soils2 to=soils2 upload=dist column=dist
>out=test_dist_1000m
from_type=centroid to_type=centroid -a dmax=1000

This results in a dataset with GRASS-geometries and postgres-attributes.

> g.copy vect=test_dist_1000m,test_dist_1000m_pg

not neccessary, because the db-setting for your location were set to
postgres before, so every dataset created afterwards attributes are
stored inside postgres.
Tools like pgadmin3 [1] can help browsing postgres.

>v.out.ogr input=test_dist_1000m_pg type=point dsn="PG:host=localhost
dbname=grass_pg user=baliola" olayer=dist_1000m format=PostgreSQL

and enter PGSQL
>psql grass_pg
>select * from dist_1000m_p;

I get:

ogc_fid | wkb_geometry
    | cat
---------+----------------------------------------------------------------------
----+-----
       1 |
\001\001\000\000\000\303\365(\\\340\217"Aq=\012\367\035\277RA |
       2 |
\001\001\000\000\000\\\217\302\365\265\212"A\366(\\/\207\277RA |
       3 | \001\001\000\000\000\303\365(\334\322\227"A333\003D\277RA

which looks for me pretty weird. How do I solely extract the distance
values into PGSQL?
The general question would be, "how do I export single columns only?"

As you are working with attribute-data, your last step (v.out.ogr) was
not neccessary, because the attributeinformation of test_dist_1000m are
already in postgres (table test_dist_1000m).

> To use the exported map in GRASS relink it to your grassdata using
> the command v.external.
[...]
> >
> > However I would love to have a tutorial how to use GRASS in
> > conjunction with Postgresql which tells me which software I do
> > need and how I initialise this cross-package functionality. I
> > haven't found a link to a tutorial, in case I missed it, I would
> > be glad if you can send a link.
>
> Actually I do not have a link at hand, but perhaps we should set up
> a wiki-entry for this kind of problem?
> Volunteers?

yeeph, I would volunteer, however I can provide the rough first steps
only; the nifty bits and pieces are not yet in my repertoire.

I could certainly help including information about this topic!

Best
  Stephan

[1] http://www.pgadmin.org/

--
GDF Hannover - Solutions for spatial data analysis and remote sensing
Hannover Office - Mengendamm 16d - D-30177 Hannover
Internet: www.gdf-hannover.de - Email: holl@gdf-hannover.de
Phone : ++49-(0)511.39088507 - Fax: ++49-(0)511.39088508