5

I'm working with a point layer (airports from OpenFlights), and I want to create a map of distance to the nearest airport.

I thought I might be able to do this by using radial fill on the voronoi polygons.

I created the voronoi polygons. These included the original fields from the airports layer, so I have (lat, lon) of the airport for each polygon.

When it comes to styling, I tried to create a radial fill centred on the airport. It's very easy to center on the centroid, but the centroid is nowhere near the airport in most cases.

I set up a radial fill with reference points (0.5,0.5) and (1.0,1.0), mode: reflect.

You can see here the result.. how can I centre it so the brightest point in the radial fill for each polygon aligns with its airport?

enter image description here

There doesn't seem to be an option to set a centre point coordinate. The data-driven option to the right of the centroid isn't for setting up a coordinate, it's a binary field for the centroid setting.

I could try computing an offset (between the centroid and the airport) but there aren't any data-driven options for the offset fields, so they would need to be set manually.

Shapeburst fill isn't suitable for this (although it does give some interesting results!)

I've also looked at raster and svg fill, but again these appear to offer no way to set the centre coordinate (I suspect they align using the bounding box)

  • Is there some way to do this with QGIS? Am I overlooking something?

  • Also, is there way to prevent QGIS from scaling the gradients to fit the bounding box? I've tried switching from 'object' to 'viewport' but the polygons all vanish.


Dmitry helped fix the first question - aligning up the gradients to the airport locations

I added 6 new real fields to my polygons with the field calculator...

xmin -> x_min(bounds($geometry))
ymin -> y_min(bounds($geometry))
xmax -> x_max(bounds($geometry))
ymax -> y_max(bounds($geometry))
xoff -> (airportx - xmin)/(xmax-xmin)
yoff -> 1 - ((airporty - ymin)/(ymax-ymin))

I then used the values of xoff and yoff in the data-driven x1 and y1 fields. The bounding box appears to be in the bottom-left, not the top-left, hence the "1-" in the last function.

Results now look a lot better...

enter image description here

This still leaves me with the problem of the best option for x2 and y2; for now, I've set the second control point to (1,1). Need to have a think about that.

Given that this is pegged to the bounding box, I suspect the answer to the second question (can I avoid the gradient being scaled) is 'no' :)

So I'll probably do this as a python gdal raster script.. also has the advantage that I can use PostGIS to calculate spheroid distances.

1
  • 1
    Interesting idea.. shame you can't have the outer point not normalised. I used the following expression to avoid having lots of new columns in the data ("X" - xmin( $geometry ) ) / ((xmax ( $geometry )) - (xmin( $geometry ) ))
    – Sethinacan
    Aug 3, 2015 at 11:51

1 Answer 1

4

There are X and Y field for point 1 and point 2 of a gradient.

enter image description here

And they may be linked to fields of object. They sets a relative coordinates, as a fraction of bbox height and width. So if you could calculate a distance between airport and Voronoy's cell centroid, you may calculate these fractional offsets.

1
  • aaah.. thank you! that was the first thing I tried, but I hadn't made the mental connection to normalising to the [0,1] range within the bounding box...
    – Steven Kay
    Aug 2, 2015 at 16:19

Your Answer

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

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