Search code examples
mongodbgeojson

Import GeoJSON data into MongoDB


I have two geojson files

  1. GeoJSON file for Provinces (here)
  2. GeoJSON file for Municipalities (here)

Municipalities resides inside Provinces

My goal is to import these files into MongoDB. In MongoDB I have a collection called "Grocery", a collection with a geolocation field (long/lat)

Part of the goal is for each Grocery row to get the associated Province and Municipality by using the data from the two GeoJSON available. So say a Grocery row have a (X,Y) geolocation field stored, using these coordinates we will query the Provinces and Municipalities from the GeoJSON data to return the Province name and Municipality name, e.g. it will return "Mountain Province" plus "Lake City" (Municipality)

What is the general approach to achieving this?


Solution

  • Best approach in my opinion would (trivially) be to perform this transformation with the programming language you prefer, interfacing your MongoDB.

    You will find many libraries allowing you to perform operations with GeoJSON objects, including testing a GeoJSON point inclusion within any GeoJSON shape. You may want to take a look to d3-geo (w/ Node.JS) or Python GeoJSON as well as Shapely.