[GRASS5] GRASS5.7: trouble converting shapefile to postgis with v.convert

Hello,

I have a shapefile registered in GRASS5.7:

*******
GRASS 5.7.-cvs:~ > g.list vect
----------------------------------------------
vector files available in mapset mlennert:
communes.shp

----------------------------------------------
************

I can display and query this file without any problems.

It is connected to a dbf file:

*************
GRASS 5.7.-cvs:~ > v.db.connect -p communes.shp
Vector map <communes.shp> is connected by:
field <1> table <communes> in database </home/mlennert/SHAPEFILES/>
through driver <shp> with key <shp_fid>
**************

Following the tutorial, I tried to store this map in PostGIS format:

*************
GRASS 5.7.-cvs:~ > v.database driver=pg database="dbname=digit_belgium"
GRASS 5.7.-cvs:~ > v.convert input=communes.shp output=communes
*************

but I got the error message: "ERROR: Input vector was not found."

What am I doing wrong ?

Moritz

On Thursday 04 December 2003 19:17, Moritz Lennert wrote:

Hello,

I have a shapefile registered in GRASS5.7:

*******
GRASS 5.7.-cvs:~ > g.list vect
----------------------------------------------
vector files available in mapset mlennert:
communes.shp

----------------------------------------------
************

I can display and query this file without any problems.

It is connected to a dbf file:

*************
GRASS 5.7.-cvs:~ > v.db.connect -p communes.shp
Vector map <communes.shp> is connected by:
field <1> table <communes> in database </home/mlennert/SHAPEFILES/>
through driver <shp> with key <shp_fid>
**************

Following the tutorial, I tried to store this map in PostGIS format:

*************
GRASS 5.7.-cvs:~ > v.database driver=pg database="dbname=digit_belgium"
GRASS 5.7.-cvs:~ > v.convert input=communes.shp output=communes
*************

but I got the error message: "ERROR: Input vector was not found."

What am I doing wrong ?

v.convert converts old GRASS vector files (GRASS 4.0,5.0) to 5.1/7 format.
v.database is used to set the database for attributes.
If you want to write a vector in PostGIS format, you have first set
the output vector format to PostGIS either in
v.format -> output format -> PostGIS
or by g.gisenv:
g.gisenv store=mapset set=GV_FORMAT=POSTGIS
g.gisenv store=mapset set=GV_PGIS_DATABASE=host=liptakov,dbname=cimrman,user=jara

Once you set vector format to PostGIS, all new vectors are written to the database.
Attributes are by default written to dbf files, so until you set also
v.database driver=pg database="dbname=digit_belgium"
you get geometry in Postgres and attributes in dbf, isn't it funny?

To convert the vector you can run g.copy for example, but that is not what you want
as communes will be polygons and you have to clean such vector first.
I would recommend v.in.ogr as it does all the cleaning. See the statistics about
areas at the end.

Radim

Radim Blazek said:

On Thursday 04 December 2003 19:17, Moritz Lennert wrote:

Hello,

I have a shapefile registered in GRASS5.7:

*******
GRASS 5.7.-cvs:~ > g.list vect
----------------------------------------------
vector files available in mapset mlennert:
communes.shp

----------------------------------------------
************

I can display and query this file without any problems.

It is connected to a dbf file:

*************
GRASS 5.7.-cvs:~ > v.db.connect -p communes.shp
Vector map <communes.shp> is connected by:
field <1> table <communes> in database </home>
through driver <shp> with key <shp_fid>
**************

Following the tutorial, I tried to store this map in PostGIS format:

*************
GRASS 5.7.-cvs:~ > v.database driver=pg database="dbname=digit_belgium"
GRASS 5.7.-cvs:~ > v.convert input=communes.shp output=communes
*************

but I got the error message: "ERROR: Input vector was not found."

What am I doing wrong ?

v.convert converts old GRASS vector files (GRASS 4.0,5.0) to 5.1/7 format.
v.database is used to set the database for attributes.
If you want to write a vector in PostGIS format, you have first set
the output vector format to PostGIS either in
v.format -> output format -> PostGIS
or by g.gisenv:
g.gisenv store=mapset set=GV_FORMAT=POSTGIS
g.gisenv store=mapset
set=GV_PGIS_DATABASE=host=liptakov,dbname=cimrman,user=jara

Once you set vector format to PostGIS, all new vectors are written to the
database.
Attributes are by default written to dbf files, so until you set also
v.database driver=pg database="dbname=digit_belgium"
you get geometry in Postgres and attributes in dbf, isn't it funny?

I did all these steps, just following the tutorial, but the problem was
the usage of v.convert. May I conclude that the description in the
tutorial at
http://grass.itc.it/grass51/tutorial/geom_storage.html#PostGRASS is wrong
then ?

To convert the vector you can run g.copy for example, but that is not what
you want
as communes will be polygons and you have to clean such vector first.
I would recommend v.in.ogr as it does all the cleaning. See the statistics
about
areas at the end.

So you would recommend this rather than just using the shp2pgsql program
that comes with postgis ?

Moritz

On Fri, Dec 05, 2003 at 05:38:44PM +0100, Moritz Lennert wrote:

Radim Blazek said:
> On Thursday 04 December 2003 19:17, Moritz Lennert wrote:
>> Hello,
>>
>> I have a shapefile registered in GRASS5.7:
>>
>> *******
>> GRASS 5.7.-cvs:~ > g.list vect
>> ----------------------------------------------
>> vector files available in mapset mlennert:
>> communes.shp
>>
>> ----------------------------------------------
>> ************
>>
>> I can display and query this file without any problems.
>>
>> It is connected to a dbf file:
>>
>> *************
>> GRASS 5.7.-cvs:~ > v.db.connect -p communes.shp
>> Vector map <communes.shp> is connected by:
>> field <1> table <communes> in database </home>
>> through driver <shp> with key <shp_fid>
>> **************
>>
>> Following the tutorial, I tried to store this map in PostGIS format:
>>
>> *************
>> GRASS 5.7.-cvs:~ > v.database driver=pg database="dbname=digit_belgium"
>> GRASS 5.7.-cvs:~ > v.convert input=communes.shp output=communes
>> *************
>>
>> but I got the error message: "ERROR: Input vector was not found."
>>
>> What am I doing wrong ?
>
> v.convert converts old GRASS vector files (GRASS 4.0,5.0) to 5.1/7 format.
> v.database is used to set the database for attributes.
> If you want to write a vector in PostGIS format, you have first set
> the output vector format to PostGIS either in
> v.format -> output format -> PostGIS
> or by g.gisenv:
> g.gisenv store=mapset set=GV_FORMAT=POSTGIS
> g.gisenv store=mapset
> set=GV_PGIS_DATABASE=host=liptakov,dbname=cimrman,user=jara
>
> Once you set vector format to PostGIS, all new vectors are written to the
> database.
> Attributes are by default written to dbf files, so until you set also
> v.database driver=pg database="dbname=digit_belgium"
> you get geometry in Postgres and attributes in dbf, isn't it funny?

I did all these steps, just following the tutorial, but the problem was
the usage of v.convert. May I conclude that the description in the
tutorial at
http://grass.itc.it/grass51/tutorial/geom_storage.html#PostGRASS is wrong
then ?

Possibly yes. The tutorial *tries* to keep pace with the 5.7 development.
But that's not always possible due to (my) time constraints.
Sorry for any inconvenience, I am happy to receive corrections.

> To convert the vector you can run g.copy for example, but that is not what
> you want
> as communes will be polygons and you have to clean such vector first.
> I would recommend v.in.ogr as it does all the cleaning. See the statistics
> about
> areas at the end.
>

So you would recommend this rather than just using the shp2pgsql program
that comes with postgis ?

Note that areas are treated differently in PostGIS and PostGRASS (the latter
with pseudo-topology, correct me if I am wrong). So it will work only for
lines and points.

Markus