4

I'm trying to create Voronois in Namibia but it seems like they aren't filling the entire country polygon (the one being used as the cookie cutter).

I have tried multiple queries and joins but they all seems to result in the same broken Voronois

Here is the Country poly enter image description here

Here are the two points enter image description here

And here is the broken result enter image description here

For some reason the two Voronoi polygons aren't filling up the entire country. I've checked validity of the polygon and all seems fine.

Here is the query I'm using

with countries as
    (
          select code, wkb_geometry as country_wkb_geometry
          from countries
          where code = 'NA'
    ),
       airports as (
           select code, country_code, wkb_geometry as airport_wkb_geometry
           from airports
           and country_code = 'NA'
       )
   select
        st_intersection((ST_Dump(ST_VoronoiPolygons(ST_Collect(airports.airport_wkb_geometry)))).geom, countries.country_wkb_geometry) as geom
   from airports
       inner join countries
           on countries.code = airports.country_code
   group by countries.country_wkb_geometry

The expectation is the voronoi to fill completely (up to red top and bottom) enter image description here

What would cause the broken result like this?

1 Answer 1

6

From the documentation of ST_VoronoiPolygons https://postgis.net/docs/ST_VoronoiPolygons.html

Optional parameters:

'tolerance' : The distance within which vertices will be considered equivalent. Robustness of the algorithm can be improved by supplying a nonzero tolerance distance. (default = 0.0)

'extend_to' : If a geometry is supplied as the "extend_to" parameter, the diagram will be extended to cover the envelope of the "extend_to" geometry, unless that envelope is smaller than the default envelope (default = NULL, default envelope is boundingbox of input geometry extended by about 50% in each direction).

Your two points are close to each other in the middle of the area of Namibia and therefore the default extend does not cover the whole country. You must use the extent_to parameter for making the Voronoi polygons so large that you can then clip them with the country borders. See the polygons with default extent (highlight) and with extended extent:

enter image description here

The query that I used for creating the larger Voronoi polygons:

select st_voronoipolygons('MULTIPOINT ((15.096830929306929 -22.929700767871285), (18.103552685782176 -23.05710423212871))',0,'POLYGON ((19.895768 -24.76779, 19.894734 -28.461105, 19.002127 -28.972443, 18.464899 -29.045462, 17.836152 -28.856378, 17.387497 -28.783514, 17.218929 -28.355943, 16.824017 -28.082162, 16.344977 -28.576705, 15.601818 -27.821247, 15.210472 -27.090956, 14.989711 -26.117372, 14.743214 -25.39292, 14.408144 -23.853014, 14.385717 -22.656653, 14.257714 -22.111208, 13.868642 -21.699037, 13.352498 -20.872834, 12.826845 -19.673166, 12.608564 -19.045349, 11.794919 -18.069129, 11.734199 -17.301889, 12.215461 -17.111668, 12.814081 -16.941343, 13.462362 -16.971212, 14.058501 -17.423381, 14.209707 -17.353101, 18.263309 -17.309951, 18.956187 -17.789095, 21.377176 -17.930636, 23.215048 -17.523116, 24.033862 -17.295843, 24.682349 -17.353411, 25.07695 -17.578823, 25.084443 -17.661816, 24.520705 -17.887125, 24.217365 -17.889347, 23.579006 -18.281261, 23.196858 -17.869038, 21.65504 -18.219146, 20.910641 -18.252219, 20.881134 -21.814327, 19.895458 -21.849157, 19.895768 -24.76779))')
1
  • Ah thanks for answering even though its in the docs. I used the same cookie cutter polygon as the bounds, as in your example, and works perfect. Feb 13, 2023 at 5:21

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.