0

I have a folder with multiple SpatiaLite databases. I'd like to use ogrmerge.py to merge them into a single database... But if I use the command:

ogrmerge.py -f SQLite -single -o output.sqlite *.sqlite

I receive the error:

    - 'VirtualXPath'    [XML Path Language - XPath]
Traceback (most recent call last):
  File "/usr/bin/ogrmerge.py", line 11, in <module>
    sys.exit(main(sys.argv))
  File "/usr/lib/python3/dist-packages/osgeo/utils/ogrmerge.py", line 618, in main
    return process(argv[1:])
  File "/usr/lib/python3/dist-packages/osgeo/utils/ogrmerge.py", line 456, in process
    writer.open_element('OGRVRTLayer',
  File "/usr/lib/python3/dist-packages/osgeo/utils/ogrmerge.py", line 168, in open_element
    xml_attrs = xml_attrs + ' %s=\"%s\"' % (key, _Esc(attrs[key].encode('utf-8')))
UnicodeEncodeError: 'utf-8' codec can't encode characters in position 12-13: surrogates not allowed

What am I missing? When I try merging the same files as Shapefiles with ogrmerge.py -f "ESRI Shapefile" -single *.shp -o output.shp it works fine. How can I merge SpatiaLite files with ogrmerge.py?

3
  • Which version of GDAL/OGR and OS are you using? This sounds like a character encoding issue (non utf-8). Try to find out the exact encoding used for creating these data and replace xml_attrs = xml_attrs + ' %s=\"%s\"' % (key, _Esc(attrs[key].encode('utf-8'))) If you cannot find out the exact encoding, try some common ones, e.g., windows-1252
    – PDash
    Commented Mar 28, 2022 at 6:44
  • @PDash I'm using Ubuntu 20.04 with the GDAL 3.0.4... Actually, I'm not completely sure if ogrmergy.py can merge input files that are not Shapefiles since the examples that I find are always using Shapefiles as input (gdal.org/programs/ogrmerge.html). My Spatialite files look ok when I open them with QGIS. I'd like to find a solution that doesn't require me to change the ogrmerge.py source code.
    – raylight
    Commented Mar 28, 2022 at 13:37
  • Did you try setting a different encode spec? any change? On your sqlite db Q, valid thought but I think it will; may need additional geopackages, e.g. sqlite spatialite & additional keys in your script. Also, look at: https://gis.stackexchange.com/questions/195160/merge-natural-earth-sqlite-country-polygons-using-ogr2ogr-and-st-union Installing a complete Sys on Linux was painful. Here are some packages u will need: https://www.gaia-gis.it/gaia-sins/libspatialite-sources/libspatialite-$spatialite_version.tar.gz https://www.sqlite.org/2020/sqlite-autoconf-3320300.tar.gz
    – PDash
    Commented Mar 29, 2022 at 7:35

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.