Based on an irregular distribution of points (longitude,latitude), I obtained the convex hull below (I use saga_cmd with polygon convexity in 1). Would you have a way to create a convex hull that closely follows this irregular shape using one-liner commands or similar? I call commands from a bash terminal in Linux.

enter image description here

  • 1
    there are concave hulls as well, an implementation exists in postgis, st_concave_hull – Elio Diaz Oct 27 '20 at 16:38
  • @ElioDiaz using ogr2ogr -f "ESRI Shapefile" tmp.shp tmp.gmt -a_srs EPSG:4326 -dialect sqlite -sql "SELECT ST_AsBinary(ST_ConcaveHull(geometry,0.90))" produces no such column: geometry. Without the word geometry, it only gives the DBF and PRJ files from the SHP file (ie. the SHP and SHX files are missing). My input is a two-columns GMT file. – Gery Oct 27 '20 at 23:41
  • 1
    ogr2ogr -f GPKG tmp.gpkg puntos_monitoreo_2020_2021.gpkg -nln concava -dialect sqlite -sql "select 'a', ST_ConcaveHull(st_collect(geometry),0.9) from puntos_monitoreo_2020_2021" – Elio Diaz Oct 28 '20 at 0:03
  • 1
    i used the code above for some points, you were very close, just missing the st_collect(geometry) (because in your case you have points and cannot make a hull on a single point, so you have to collect the layer) and from table_name; you get the table name with ogrinfo tmp.gmt then it will print the layer name like: 1. layer_name (Point) – Elio Diaz Oct 28 '20 at 0:12
  • 1
    @ElioDiaz lo maximo! esta pensando ahorita... – Gery Oct 28 '20 at 0:31

Using PostGIS ST_ConcaveHullyou may get the envelope to follow more closely the irregular shape, as stated in your post;

ogr2ogr -f GPKG concave.gpkg points.gpkg -nln concave_layer -dialect sqlite -sql "select 'a', ST_ConcaveHull(st_collect(geometry),0.9) from points_layer"

A few remarks:

  1. You are using a point layer, so if you call st_concave_hull directly on your geometry it will try to make a polygon for each point, which will return empty geometries, so first we call st_collect(geometry);

  2. The layer name in the sql query can be retrieved with ogrinfo file.gpkg, it is often not the same name as the layer.

  3. For some functions to work in ogr2ogr you need a non-geometry field, that's why I passed 'a' to the command, here it works without it.

  4. It is an expensive algorithm, to test it you may use a subset of your layer passing where fid < 1000 to the query

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.