1

I'm trying to get some administrative boundaries,and in the map it shows correctly, but when I try to export the result as GeoJSON nothing happens- also no error message or so. Seems that something is wrong with my request?

[out:json][timeout:25];

(
  relation
    ["boundary"="administrative"]
    ["admin_level"="5"]

  ({{bbox}}); 

);

out body;
>;
out skel qt;

1
  • I think the result I get is too big for exporting (~30mb). When I reduce the size of the bbox I can export the data.
    – i.i.k.
    Commented Nov 2, 2023 at 9:49

2 Answers 2

1

You could try to download the result as OSM XML data instead. Then, perform the conversion from XML to GeoJSON on your side by using one of these libraries:

1
  • I did try the python library, and it seems to work (even though one object seems to not be translated), but then I have a dict (geojson) or a list (shape). How do I then store them as files?
    – i.i.k.
    Commented Nov 4, 2023 at 13:32
1

The answer from scai is partially correct,thank you! However not complete as you need to take some more steps. For example I had to use the request library to actually query the data as I couldn't download the data from overpass turbo as osm-xml (too big, I guess) So my python code to get the data and store as geojson is:

import requests
import json
import codecs
import osm2geojson

overpass_url = "http://overpass-api.de/api/interpreter"

# Here the query from overpass-turbo

overpass_query = """
[out:json][timeout:25];
area[name="Deutschland"];

(
  relation
    ["boundary"="administrative"]
    ["admin_level"="6"](area); 
);

out body;
>;
out skel qt;
"""

response = requests.get(overpass_url, 
                        params={'data': overpass_query})
data = response.json()

# Dump the data as json 
with open(r'path/to/file.json', 'w') as f:
    json.dump(data, f)


# Reread the json file and convert it to geojson with the osm2geo library
with codecs.open(r'path/to/file.json', 'r', encoding='utf-8') as data:
    json = data.read()


# restructure to geojson
geojson = osm2geojson.json2geojson(json)

# Store restructured json as json to your local disk
with open(r'path/to/geofile.json', 'w') as f:
    json.dump(geojson, f)

This stored json-file is then readable in e.g. QGIS and can then (if needed) exported as shapefile or so from QGIS.

I'm pretty sure that there is no need to first store it as json and then read it and then store it as geojson, but will try this out later.

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.