NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum

Hello,

I hope you're all doing well!

First of all, unfortunately, my knowledge regarding javascript query building in Overpass is relatively limited. I would like to create a map of German postalcode areas that are colored differently. It can happen that several postal code areas should have the same color. The following code is already functioning:

[out:json][timeout:25];

{{geocodeArea:Germany}}->.searchArea;

// gather results
(      
  relation["postal_code"="45529"](area.searchArea);
  relation["postal_code"="45527"](area.searchArea);  
  relation["postal_code"="45525"](area.searchArea);
);


{{style:
  relation[postal_code=45529]
    { color:red; fill-color:red; text: note;}
  relation[postal_code=45527]
    { color:red; fill-color:red; text: note;}
  relation[postal_code=45525]
    { color:yellow; fill-color:yellow; text: note;}
}}

// print results
out body;
>;
out skel qt;

However, I'm pretty sure that there is room for improvement for shortening the code and, therefore, the URL link created from this query. Maybe it is possible to place several postal codes in one relation? Maybe the style code can be improved to merge the postal codes with the same color?

Thank you very much in advance!

All the best Josh

asked 31 Oct '22, 09:39

Joshua1511's gravatar image

Joshua1511
0112
accept rate: 0%


{{geocodeArea:Germany}};rel[postal_code~"45529|45527|45525"](area);{{style:relation{fill-color:red;text:note}relation[postal_code=45525]{fill-color:yellow} }}out geom;
  • Combine search for similar entities into one command.
  • Use 'rel' instead of relation
  • Remove unnecessary parenthesis
  • Remove timeout
  • Remove out:json if you're not interested in data format
  • use out geom; if you're not interested in data format
  • Remove whitespace
  • Remove all comments
  • Remove carriage returns so it's all on one line (note space is required between the style closing curly brackets)
  • Remove comma after 'note' & 'yellow'
  • Is color: required?

MapCss works on a default system so you can specify a colour for the relations you want red & specify postal_codes for those with a different colour. If you want labels to display in all areas it only needs to be declared once.

In your specific example there's no requirement to search using the area as the postal_codes are unique, but that might no be true in every case.

In your specific example you could also reduce the search to postal_code~"4552."

permanent link

answered 31 Oct '22, 11:02

DaveF's gravatar image

DaveF
3.3k8498133
accept rate: 16%

edited 31 Oct '22, 11:03

This is awesome! Thank you very much! I'll play a bit around with your code.

(31 Oct '22, 11:09) Joshua1511
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×483
×236
×27
×10

question asked: 31 Oct '22, 09:39

question was seen: 766 times

last updated: 31 Oct '22, 11:09

NOTICE: help.openstreetmap.org is no longer in use from 1st March 2024. Please use the OpenStreetMap Community Forum