3

I managed to generate geopackage with GDAL/OGR Python API using this example from the official website. However, there's no information on how to write style information into the geopackage file. Any suggestions?

4

The GeoPackage standard does not have anything defined about how to save the styles yet. Styles are coming to the standard but it is hard to say when. Here is a report about one experiment that has been done for OGC http://docs.opengeospatial.org/per/16-037.pdf.

What you can do with GDAL is to add a new field "OGR_STYLE" into the feature table and write rendering styles for each feature into this field. Field should contain a text string and rendering rules must be written as defined in http://www.gdal.org/ogr_feature_style.html.

Even it is rather easy to write data into the OGR_STYLE field it may be hard to find a software than can utilize it for rendering. MapServer can.

At the moment I believe that QGIS has the best implementation for storing the styles inside the gpkg database.

enter image description here

When the styles are saved into the gpkg database a new table is created as:

CREATE TABLE "layer_styles" ( "id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "f_table_catalog" TEXT(256), "f_table_schema" TEXT(256), "f_table_name" TEXT(256), "f_geometry_column" TEXT(256), "styleName" TEXT(30), "styleQML" TEXT, "styleSLD" TEXT, "useAsDefault" BOOLEAN, "description" TEXT, "owner" TEXT(30), "ui" TEXT(30), "update_time" DATETIME DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ','now')));

A couple of triggers are created as well as can be seen in this diagram:

enter image description here

QGIS can re-use the saved styles but there is not much interoperability with other software. The styleSLD field does contain OGC SLD style definition as a complete XML document and that document should work for example with GeoServer but unfortunately GeoServer can't read styles directly from gpkg database. You must extract the XML document out of the database with some SQLite SQL tools and save it as a text file for GeoServer. Spatialite-gui is one, rather easy to use program for extracting the SLD.

  • I.would add to the above answer that if you want labels you need to manually add those to the SLD. SLD supports it but QGIS does not output labels as part of its SLD – GeospatialInformationTech Jan 23 '18 at 2:21

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.