Is it possible to export a raster map created using r.water.outlet to PostGIS in GRASS 78? The documentation indicates using r.out.gdal with PostGISRaster as format. The command I’m trying is the following:
The postgresql server is running with locally and the database “mydb” can be accessed without having to enter a password using psql client. However, this command fails with the error:
ERROR 6: PostGISRasterDataset::CreateCopy() only works on source datasets that are PostGISRaster
Is something wrong in the command? The error message seems to suggest that it is impossible to export the raster map created with r.water.outlet to PostGIS because it is not sourced from PostGIS. Can someone please confirm?
piektd., 2022. g. 26. aug., plkst. 10:48 — lietotājs Asim via
grass-user (<grass-user@lists.osgeo.org>) rakstīja:
Hello
Is it possible to export a raster map created using r.water.outlet to PostGIS in GRASS 78? The documentation indicates using r.out.gdal with PostGISRaster as format. The command I'm trying is the following:
The postgresql server is running with locally and the database "mydb" can be accessed without having to enter a password using psql client. However, this command fails with the error:
ERROR 6: PostGISRasterDataset::CreateCopy() only works on source datasets that are PostGISRaster
Is something wrong in the command? The error message seems to suggest that it is impossible to export the raster map created with r.water.outlet to PostGIS because it is not sourced from PostGIS. Can someone please confirm?
Thank you for pointing out the read-only limitation of GDAL library. A natural workaround is to convert the raster to vector with r.to.vect and then use v.out.postgis. However, there are some hurdles with regards to the type of resulting geometries (boundary, centroid and area) arising after the conversion to vector. I will start a separate thread if I can articulate the problem somewhat precisely.
You could try to use raster2pgsql after making sure you have the GDAL-GRASS plugin installed.
Then you should be able to load GRASS GIS raster maps directly into PostGIS by pointing to the header of your GRASS GIS maps. Something like:
raster2pgsql -s 4326 -C -l 2,4 -I -F -t 2700x2700 /your_grassdb/location/mapset/cellhd/your_raster_map output_pg_shema_name. output_table_name | psql -h your_host -p 5432 -U postgres -d your_pg_database
(obviously you have to adjust options and flags of raster2pgsql to your case...).
Hope that helps.
Cheers
Stefan
-----Original Message-----
From: grass-user <grass-user-bounces@lists.osgeo.org> On Behalf Of Asim via grass-user
Sent: lørdag 27. august 2022 11:38
To: Maris Nartiss <maris.gis@gmail.com>
Cc: grass-user@lists.osgeo.org
Subject: Re: [GRASS-user] Export raster to PostGIS
Hi Māris
Thank you for pointing out the read-only limitation of GDAL library. A natural workaround is to convert the raster to vector with r.to.vect and then use v.out.postgis. However, there are some hurdles with regards to the type of resulting geometries (boundary, centroid and area) arising after the conversion to vector. I will start a separate thread if I can articulate the problem somewhat precisely.
Then you should be able to load GRASS GIS raster maps directly into PostGIS by pointing to the header of your GRASS GIS maps. Something like:
raster2pgsql -s 4326 -C -l 2,4 -I -F -t 2700x2700 /your_grassdb/location/mapset/cellhd/your_raster_map output_pg_shema_name. output_table_name | psql -h your_host -p 5432 -U postgres -d your_pg_database
(obviously you have to adjust options and flags of raster2pgsql to your case…).