Discussion:
[gdal-dev] ogr2ogr projecting from postgis to postgis
Bryan Hempen
2011-07-31 11:40:21 UTC
Permalink
Hi!

I have a little trouble figuring out how to use ogr2ogr to read spatial data from a postgis table, project it and store it back in the database. I do not want to create a shapefile or something like that and load the data back into the database again.

Using ogr2ogr for data other than stored in a PostGIS database works perfectly fine, but I can't even export PostGIS data to a shapefile or GML (always empty) and I don't know why...

What worked out well so far is loading the PostGIS data with QGIS, save it as a shapefile, THEN project it to another shapefile and finally load the shapefile into the database. Yet, as I said before, I would like to directly project the data from database to database.

I know that PostGIS provides a function called st_transform for exactly this purpose, but I need to use ogr2ogr.

Here is the command which does not work so far, hopefully you guys can give me some help:

ogr2ogr -f "PostgreSQL" -s_srs "+proj=longlat +a=3396190 +b=3376200 +no_defs" -t_srs "+proj=tmerc +lat_0=0 +lon_0=0 +k=0.9996 +x_0=0 +y_0=0 +a=3396190 +b=3376200 +units=m +no_defs" PG:"dbname='test4' host='localhost' port='5432' user='postgres' password='xxx'" PG:"dbname='test3' host='localhost' port='5432' user='postgres' password='xxx'" alldata

Notes:

- the table containing the geometry column is called alldata
- the_geom is added with AddGeometryColumns
- alldata contains some more non-spatial columns
- I need the results to be stored in the database. In this command above I try to store the results in a different database on the same server. The database is empty so far. What would be even better is to add an additional column in the same database as the original data like the_geom_projected and store the projected geometries in there.

I am using the last FWTools, PostGIS 2.0, PostgreSQL 8.4.

When I run the command above I get the following message:

Warning 1: Multi-column primary key in 'raster_columns' detected but not supported.
Warning 1: Multi-column primary key in 'raster_columns' detected but not supported.
ERROR 1: AddGeometryColumn failed for layer alldata, layer creation has failed.
ERROR 1: Terminating translation prematurely after failed
translation of layer alldata (use -skipfailures to skip errors)

I have tried a lot of the examples on the website and some tutorials, but nothing worked. Even simple simple exports like

ogr2ogr "C:\Documents and Settings\user\Deskto
p\new1.shp" PG:"dbname='test3' host='localhost' port='5432' user='postgres' password='xxx'" alldata

produce an empty shapefile. What am I doing wrong? Thanks for your help.

Kind regards,
Bryan
Chaitanya kumar CH
2011-07-31 15:54:08 UTC
Permalink
Bryan,

OGR is reading the layer definition of the source. The problem must be when
reading the features.

Run your commands after setting the environment variable CPL_DEBUG to ON.
Report any new messages.
What is the output of ogrinfo with the options -al and -so on the database?
Post by Bryan Hempen
Hi!
I have a little trouble figuring out how to use ogr2ogr to read spatial
data from a postgis table, project it and store it back in the database. I
do not want to create a shapefile or something like that and load the data
back into the database again.
Using ogr2ogr for data other than stored in a PostGIS database works
perfectly fine, but I can't even export PostGIS data to a shapefile or GML
(always empty) and I don't know why...
What worked out well so far is loading the PostGIS data with QGIS, save it
as a shapefile, THEN project it to another shapefile and finally load the
shapefile into the database. Yet, as I said before, I would like to directly
project the data from database to database.
I know that PostGIS provides a function called st_transform for exactly
this purpose, but I need to use ogr2ogr.
ogr2ogr -f "PostgreSQL" -s_srs "+proj=longlat +a=3396190 +b=3376200
+no_defs" -t_srs "+proj=tmerc +lat_0=0 +lon_0=0 +k=0.9996 +x_0=0 +y_0=0
+a=3396190 +b=3376200 +units=m +no_defs" PG:"dbname='test4' host='localhost'
port='5432' user='postgres' password='xxx'" PG:"dbname='test3'
host='localhost' port='5432' user='postgres' password='xxx'" alldata
- the table containing the geometry column is called alldata
- the_geom is added with AddGeometryColumns
- alldata contains some more non-spatial columns
- I need the results to be stored in the database. In this command above I
try to store the results in a different database on the same server. The
database is empty so far. What would be even better is to add an additional
column in the same database as the original data like the_geom_projected and
store the projected geometries in there.
I am using the last FWTools, PostGIS 2.0, PostgreSQL 8.4.
Warning 1: Multi-column primary key in 'raster_columns' detected but not supported.
Warning 1: Multi-column primary key in 'raster_columns' detected but not supported.
ERROR 1: AddGeometryColumn failed for layer alldata, layer creation has failed.
ERROR 1: Terminating translation prematurely after failed
translation of layer alldata (use -skipfailures to skip errors)
I have tried a lot of the examples on the website and some tutorials, but
nothing worked. Even simple simple exports like
ogr2ogr "C:\Documents and Settings\user\Deskto
p\new1.shp" PG:"dbname='test3' host='localhost' port='5432'
user='postgres' password='xxx'" alldata
produce an empty shapefile. What am I doing wrong? Thanks for your help.
Kind regards,
Bryan
_______________________________________________
gdal-dev mailing list
http://lists.osgeo.org/mailman/listinfo/gdal-dev
--
Best regards,
Chaitanya kumar CH.

+91-9494447584
17.2416N 80.1426E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110731/f48f48b3/attachment-0001.html
Continue reading on narkive:
Search results for '[gdal-dev] ogr2ogr projecting from postgis to postgis' (Questions and Answers)
10
replies
what is GIS?
started 2006-06-13 03:41:34 UTC
science & mathematics
Loading...