7

I have a shapefile of polygons, which are effectively borders of a geographic unit (consider as an example the 50 u.s. states, each state has within it some number of points.).

I'd like to create Voronoi polygons from the points, with the caveat that the state borders effectively constrain the Voronoi polygons created from the points within that state.

The labor-intensive way to do this would be to create 50 individual shapefiles for each state, create Voronoi polygons within each, then manually merge them back together.

Is there an easier way to do this, ideally in QGIS (am using 2.18 on Mac)?

1

Similarly to the answer that @csk gave you you could try this two alternatives:

1- Include Nodes of state polygons into Voronoi tool.

  • Nodes from States layer (Use Extract nodes).
  • Merge points and Nodes.

enter image description here - Voronoi tool with Points and Nodes.

enter image description here

  • Last step is to clip your Voronoi pols with States layer (if you need it).

    2- Use Voronoi directly over Point layer using buffer to "expand" these to full State extension.

enter image description here

  • Clip with State layer.

As you see you will get different results. It depends on what are you looking for.

1

It's a multi-step process, so you should create a custom model or script. In order to avoid slivers of polygons that belong to neighboring polygon points, you'll need to iterate through your states layer. Working with state polygons and a set of random points, I'll go through the process so that you can understand what's going on inside our model.

state points

Inside the Model

  1. Extract by location
    • Extract features from: points_layer
    • Where the features: intersect
    • By comparing to the features from: polygons_layer

state extracts of points

  1. Voronoi polygons
    • Input layer: 'Extracted (location)' from algorithm 'Extract by location'
    • Buffer region: 500 (It seems excessive, but we want to ensure that your Voronoi polygons completely cover the state they're in. Since we'll clip this layer in the next step, it's irrelevant how big we make this.)
    • Parent algorithms: Extract by location

voronoi by state

  1. Clip
    • Input layer: 'Voronoi polygons' from algorithm 'Voronoi polygons'
    • Overlay layer: polygons_layer
    • Clipped: output
    • Parent algorithms: Extract by location and Voronoi polygons

clipped

As you can see, we have our state-constrained Voronoi polygons in which points from neighboring states do not affect their arrangement.

Here's an image of the model:

processing model

The image doesn't convey this, but note that the polygon layer input of the model is a Vector Features object, not a Vector Layer.

Running the Model

When you go to run your model it is vital that you click on the icon to iterate through the features of your States layer.

iterate option

Once you've run the model, you can simply run Merge vector layers on the outputs to get a single-layer output, if that is important to you. Unfortunately, I'm not aware of an easy way to merge multiple model outputs within the model itself (please, someone correct me if there is something).

If you're comfortable with Python, you can easily modify the exported script of this model to handle that additional step. As you did not mention code-based solutions in your question, however, I will leave that out.

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.