2

I am playing around with Geopackages for the first time. I've searched hard for valid syntax to generate a geometry field from lat long fields for an attribute-only table in a Geopackage.

The PostGIS method is alter table a add column geom geometry(Point,4326); update a set geom = ST_MakePoint(x,y)

I can't get anything similar to work in the SQLite GPK syntax.

2

1 Answer 1

1

If you don't mind creating a new layer, there are at least two possibilities: using QGIS expressions or using a virtual layer.

  1. QGIS expressions: Go to Menu Processing / Toolbox / Geoemtry by expression: set your Geopackage (saved without geometry, but containing an attribute for lat and lon) as input layer, select point as output geometry type and add this expression: make_point ( "lon" , "lat" ). The created layer is what you're looking for.

  2. Create a virtual layer (Menu Layer / Create Layer / New virtual layer...) with this query (where temp is the geometry-less Geopackage layer):

    select make_point (t.lon, t.lat)
    from temp as t
1
  • That worked, thanks! I still find it strange that there isn't a native way to do this in the GPKG. But the Spatialite syntax doesn't seem to be working either.
    – Encomium
    Commented Mar 17, 2021 at 17:14

Your Answer

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

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