I want to convert WFS to GeoPackage, everything is working fine but I need to change the name of each layer before converting to GeoPackage because the layer name has a special character ":" that throws an exception in the application that using the GeoPackage file.

enter image description here

  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Oct 7 at 11:10
  • 1
    If you read the documentation of ogr2ogr gdal.org/programs/ogr2ogr.html you should find option -nln.
    – user30184
    Oct 7 at 11:25
  • @user30184 yeah, I already read the documentation but I didn't know how to use this command with multiple layers. Oct 7 at 11:34
  • That is not possible for multiple layers. Many other options in ogr2ogr are also per-layer. Converting a whole datastore with all layers into another datastore is a special use case. You must add and rename the layers one by one.
    – user30184
    Oct 7 at 11:39
  • 1
    I understood that and laundering does that automatically for some forbidden characters with some drivers. I believe that what you can do is just to write the new name as a whole into -nln parameter. Of course you can write a script and make it more automatic but that gets off-topic.
    – user30184
    Oct 7 at 12:16

If you mean the ':' in the layer name "MODEE_MODEE_TEST1:Landmar_Infog_PILOT", then it's not so much of a 'special' character, but it means that "MODEE_MODEE_TEST1" is the (xml/gml) namespace/prefix of the layer type.

It is normal for xml/gml to have namespaces for elements, though off course it does not work if you use the whole typename as name for a table in another data format.

I googled the OGR WFS-driver docs, to see if you can maybe 'strip' the namespace in the gml output, but that seems not the case (others please correct me if I'm wrong).

Then, I looked at the GDAL GML driver docs (that is what the WFS is returning): https://gdal.org/drivers/vector/gml.html#creation-issues and that one has an option: STRIP_PREFIX Defaults to FALSE. Can be set to TRUE to avoid writing the prefix of the application target namespace in the GML file. So I do not think you can use that as an option for the ogr2ogr WFS input, but maybe you an first request the data as GML, stripping the prefix from it, and THEN ogr2ogr into a geopackage? Note all this needs some scripting because you do this per layer.

But user30184 is stating rightfully, you can set a new name for a layer.

Some examples:

# this wfs service has a layer 'bestuurlijkegrenzen:landsgrens' in which 'bestuurlijkegrenzen' is the prefix/namespace:
ogrinfo -geom=NO "WFS:https://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs" bestuurlijkegrenzen:landsgrens

# writing it to geopackage your layername will 'bestuurlijkegrenzen:landsgrens'
ogr2ogr -f gpkg output.gpkg "WFS:https://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs" bestuurlijkegrenzen:landsgrens
# inspect:
ogrinfo output.gpkg
# 1: bestuurlijkegrenzen:landsgrens (title: landsgrens)

# using -nln (new layer name, stripping the prefix):
ogr2ogr -f gpkg output.gpkg -nln landsgrens "WFS:https://geodata.nationaalgeoregister.nl/bestuurlijkegrenzen/wfs" bestuurlijkegrenzen:landsgrens
# inspect:
ogrinfo output.gpkg
# 1: landsgrens (title: landsgrens)
  • Thanks for the nice explaining, i will surely write a script for that. Oct 10 at 4:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.