Re: [gdal-dev] GPKG to PG single transaction, different schemas

2024-05-15 Thread Matteo Ghetta via gdal-dev

Hi Even,

thanks for the reply!

I downloaded the 
https://github.com/OSGeo/gdal/blob/master/swig/python/gdal-utils/osgeo_utils/samples/ogr2vrt.py 
file and used like:


python3 ogr2vrt.py export_db.gpkg export_db.vrt first_layer second_layer

but I get the following error:

Traceback (most recent call last):
  File "/home/matteo/import_export/ogr2vrt.py", line 353, in 
sys.exit(main(sys.argv))
 ^^
  File "/home/matteo/import_export/ogr2vrt.py", line 329, in main
if src_fd.GetComment():
   ^
AttributeError: 'FieldDefn' object has no attribute 'GetComment'

while with the ogr2vrt file in 
/usr/lib/python3/dist-packages/osgeo_utils/samples/ogr2vrt.py it works 
nice! Not sure what I'm missing.


So basically the content of the resulting file that I've adapted is:



shared="1">export_db.gpkg

first_layer


shared="1">export_db.gpkg

second_layer 
...

and with ogr2ogr it's working nice in a single transaction!

The vrt file generation is also adding layer metadata, is there a way to 
avoid them or should I remove them manually after the file creation?


Cheers and thanks again!

Matteo
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


Re: [gdal-dev] GPKG to PG single transaction, different schemas

2024-05-14 Thread Even Rouault via gdal-dev


Le 14/05/2024 à 17:30, Matteo Ghetta via gdal-dev a écrit :

Hi all,

I've a geopackage with many layers (in the following example let's 
pretend just 2) that I want to import in a single transaction 
(important!) into a PG database.


GPKG and PG table names are the same, but it can happen that the 
tables are in different schemas. I couldn't find the correct flags 
combination to specify the destination schema.table_name.


With the following command features of first_table are appended to the
second_table table:

ogr2ogr --debug ON -f PostgreSQL "PG:host=localhost user=matteo 
password=my_pws dbname=test" -append /home/matteo/export_db.gpkg 
first_schema.first_layer second_schema.second_layer


same with the -nln option:

ogr2ogr --debug ON -f PostgreSQL "PG:host=localhost user=matteo 
password=my_pws dbname=test" -append /home/matteo/export_db.gpkg 
first_layer -nln first_schema.first_layer second_layer -nln 
second_schema.second_layer


There's no formal concept of schema in GeoPackage. You can't use -nln 
multiple times. It works only when importing a single layer


Yes, you'll likely have to use ogr2vrt 
(https://github.com/OSGeo/gdal/blob/master/swig/python/gdal-utils/osgeo_utils/samples/ogr2vrt.py) 
and rename manually the layers


And add "-ds_transaction -gt unlimited" to make sure everything is 
imported in the same transaction



--
http://www.spatialys.com
My software is free, but my time generally not.

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev


[gdal-dev] GPKG to PG single transaction, different schemas

2024-05-14 Thread Matteo Ghetta via gdal-dev

Hi all,

I've a geopackage with many layers (in the following example let's 
pretend just 2) that I want to import in a single transaction 
(important!) into a PG database.


GPKG and PG table names are the same, but it can happen that the tables 
are in different schemas. I couldn't find the correct flags combination 
to specify the destination schema.table_name.


With the following command features of first_table are appended to the
second_table table:

ogr2ogr --debug ON -f PostgreSQL "PG:host=localhost user=matteo 
password=my_pws dbname=test" -append /home/matteo/export_db.gpkg 
first_schema.first_layer second_schema.second_layer


same with the -nln option:

ogr2ogr --debug ON -f PostgreSQL "PG:host=localhost user=matteo 
password=my_pws dbname=test" -append /home/matteo/export_db.gpkg 
first_layer -nln first_schema.first_layer second_layer -nln 
second_schema.second_layer


Should I specify a vrt catalog or am I missing some options?

Cheers and thanks!

Matteo

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
https://lists.osgeo.org/mailman/listinfo/gdal-dev