2

I have a map of England where counties are polygons. I would like to fill them with 2 colours; each half corresponding to a specific set of data. Is there a way to do that?

I have included an example below where the Isle of Wight would be divided in yellow (population density) and orange (vegetable consumption per capita), both colours expressed in one or more layers and assigned via data entered into the software:

The colour division I need to achieve

6
  • Could you use a gradient? Commented Jan 20, 2021 at 19:16
  • I have been using gradients already for each set of data, so I don’t think that would work in the end, I’m afraid... I really appreciate your comment anyway! Commented Jan 20, 2021 at 19:50
  • 5
    Don't do it. Please. The whole Department of Cartography practically begs you to not to do this. This is confusing, it is not efficient, and your choice of colours is way too similar. If you need to represent two different data sets in one map, use a colour for the first, and a pattern (preferrably black) for the second. Alternatively use a colour for the more continuous data and present the second using a label. Just don't try splitting your areas. Because people will think it's two different areas, not one. Just out of spite. Or because they don't know how to read maps.
    – Erik
    Commented Jan 20, 2021 at 20:45
  • Please just put two maps next to each other Commented Jan 20, 2021 at 22:13
  • 1
    Maybe you could use a bivariate map (ukdataservice.ac.uk/media/622462/qgisbivariate.pdf)
    – Ian Turton
    Commented Jan 21, 2021 at 8:20

3 Answers 3

2

If you just want to use different styling for visualization, without creating a new layer, you can do this adding a new symbol layer. Set it to Geometry generator and select polygon as Geometry type. Than paste the following expression. Then your polygon gets visually (but not actually) split in two parts and you can use the whole power of QGIS styling separately for each part.

with_variable (
    'midline',
    extend (
        make_line ( 
            centroid( $geometry ), 
            project (
                centroid ( $geometry    ), 
                100000,
                0
            )
        ), 100000,0
    ),
    intersection (
        $geometry,
        make_rectangle_3points (
            end_point ( @midline ),
            start_point ( @midline ),
            make_point (
                x_max ($geometry), 
                y_min ($geometry)
            )
        )
    )
)

enter image description here

How the expression works - see the screenshot at the bottom for each step:

  1. Create the centroid of the polygon: centroid($geometry)
  2. Create a new point by shifting (projecting) the centroid for a distance (here: 100000) in the direction of north (azimuth=0): project (centroid ( $geometry), 100000, 0 )
  3. Create a line connecting the points from 1 to 2: make_line (1,2) (replace 1 and 2 with the expressions from there)
  4. Extend the line from 3 to the south: extend (3, 100000,0) - replace 3 with the epxression from 3

You now have a line running north/south through the centroid, splitting the polygon in 2 parts

  1. Create a variable called midline from this line using with_variable ( 'midline', 4, expression) - replace 4 with the expression from there. expression is what we want to do with this variable (what follows in the next steps).

  2. Create start- and end point of the line of 4: start_point ( @midline ) and end_point ( @midline ) - the variable @midline is what we defined before in step 5: the line running N/S

  3. Create a point at the south eastern (lower right) corner of the extent of the polygon: make_point (x_max ($geometry), y_min ($geometry))

  4. Create a rectangle from the two points from 6 + the point from 7: ``make_rectangle_3points ( 6_start, 6_end, 7)` (replace again the arguments with the input from steps 6 and 7)

  5. Now find the area where the rectangle from 8 interescts the input polygon ($geometry): intersection ( $geometry, 8) - replace 8 with the expression from step 8.

  6. Now we combine the expression from 5 by adding the expression from 9 as third argument.

An illustration visualizing steps 1 to 10. Legend: orange: original polygon; 1. white dot; 2. brown dot; 3. pink line; 4. blue line; 5. [not visible]; 6. gray dots; 7. red dot; 8. black hashured lines; 9. & 10. black dotted surface: enter image description here

1

May it will help, if you split polygon into two parts. Use advanced digitizing. Then add each part it's own features.

https://docs.qgis.org/3.16/en/docs/user_manual/working_with_vector/editing_geometry_attributes.html?highlight=split%20polygon#split-parts

1
  • Thank you so much, I will definitely give that a try! Commented Jan 20, 2021 at 19:49
1

I would recommend displaying this in another way. Maybe use a hatched fill where the thickness of the line represents density and the colour of the line represents vegetable consumption. Would make the map more readable and able to quickly see any trend in density against vegetable consumption as you are viewing both sets of data at once, not looking at them side by side.

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.