Using Leaflet combined with D3, I'm trying to apply a style (e.g. colorize or draw a border) to units that share a same property value.

Further explanations

Context: townships in France are grouped in local 'federations' ("communauté de communes" used as frameworks to carry local tasks: collecting garbage, managing schools...). It is usually admitted that these federations are formed according to a concept called "bassin de vie" (https://fr.wikipedia.org/wiki/Bassin_de_vie) which is the smallest territorial girth where people live. However, these federations may also be formed according to the global income of their townships's inhabitants, and this is what I'm trying to visualise.

The data I'm using is shown below, and contains the ID of the federation every township is part of.

How can I draw the external borders of the townships being part of the same federation?

The data structure I use:

{"features": [{
    "type": "Feature",
    "geometry": {
        "type": "Polygon",
        "coordinates": [
                [x1, y1],
                [x2, y2], ...
                [x3, y3]]]
    "properties": {
        "zip_code": "xxx",
        "township_name": "xxx",
        "township_income": xxx,
        "township_population": xxx,
        "federation_code": xxx

What you sound to be seeking for is merging the polygons that represent the coverage of your cities, so that it becomes the polygon of coverage of the entire federation.

If you can do that in development and save the new static polygons, you should refer to these other questions:

I personally recommend the Mapshaper solution, which you can also use online.

Now if you have to do this operation on client side dynamically, this is a whole different story… Bon courage !

  • Indeed, this is an interesting solution. However, I still want to be able to use the individual properties of each township on the map (e.g. total income), and merging those entities would disable this use. When you say doing this on client side, do you have any hint to give me? Or would you advice using multiple layers (one for the federations and one for the townships)? – LeCoco Oct 29 '15 at 11:47
  • Yes using a layer for the federation and others for each city does not harm. The idea of merging the polygon is for the pure sake of displaying the federation boundaries. You can still have your townships as individual features at the same time. – ghybs Oct 29 '15 at 11:50

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.