since last few days I am trying to import data from OpenStreetMap to MongoDB. After importing geojson to database cant create any index, beacuse of various errors described below.
Hello, since last few days I am trying to import data from OpenStreetMap to MongoDB. After importing geojson to database cant create any index, beacuse of various errors described below. Steps to download and load files to databse, maybe you can find what I am doing wrong.
- Download data with overpass api and save as JSON file using python
import requests
import json
overpass_url = "http://overpass-api.de/api/interpreter"
overpass_query = """
[out:json][timeout:600];
area["ISO3166-1"="PL"][admin_level=2];
(way["natural"="water"]["water"="lake"](area);
relation["natural"="water"]["water"="lake"](area);
);
out geom;
"""
response = requests.get(overpass_url,
params={'data': overpass_query})
data = response.json()
- Format data with
osmtojson
andjq
:
node --max_old_space_size=10000 `which osmtogeojson` input.json | ./jq-linux64 --compact-output ".features" > ../data_geojson/output.geojson
I was following instructions from here.
- Insert data with mongoimport:
mongoimport -d <db> -c <col> --file output.geojson --jsonArray -j 4 --batchSize=1000
Inserting is successful but when trying to create 2dsphere
index I am getting errors about Unclosed Loop
for polygons or duplicates in nodes.
Do you know any package or script to help clear my data before inserting to db? Or maybe I am missing something in my steps?
Thanks :)