OSM Connector

Examples

This example implements the use of OSM Connector. The framework works with two manners to enrich data, one with radius around point and another without the radius. The first acts increasing the point resulting a polygon like a circle with this radius. The second doesn’t buffer the point and verify if the point is within the polygons downloaded using OSM. You can use a file that you’ve already downloaded with restriction, you must have at least one column in your CSV: “geometry”. The arguments key and value is available in Map Features.

# name of file: enrich-osm.py

from moredata.enricher import EnricherBuilder, Enricher
from moredata.enricher.osm_connector import OSMConnector
from moredata.models.data import Data
from moredata.parser import parse_document
from moredata.utils.util import read_json_from_file, Converter

user = Data(data_file=USER_DATA, parser_func=parse_document, data_type="json")

osm_enricher = Enricher(connector=OSMConnector(key="amenity", value="hospital", place_name="São Paulo", radius=100, dict_keys=["points_of_interest"]))

user_enriched = \
      EnricherBuilder(user) \
      .with_enrichment(osm_enricher) \
      .get_result()

import moredata.utils.util as util

util.write_json_generator_to_json("../../data/output/osm/amenity-cafe-mg", user_enriched, 100000)
$ python enrich-osm.py

OSM Connector

class moredata.enricher.osm.osm_places_connector.OSMPlacesConnector(key=None, value=None, dict_keys=[], place_name='Brasil', files=None, radius=None, geometry_intersected=False, buffered=False)

OSMconnector implements interface IEnricherConnector, so this is a connector that can be used to enrich data.

Parameters
  • dict_keys (List[str]) – dict_keys is the principal argument to the connector. The connector doesn’t know where to get data to make the relationship, so you have to pass the keys or if your data isn’t nested, just one key to the connector reach at the the right attribute.

  • key (str) – class of OSM. eg.: ‘amenity’, ‘leisure’.

  • value (str) – value of location of OSM. eg.: ‘hospital’, ‘stadium’.

  • place_name (str) – name of local. eg.: ‘Brasil’, ‘São Paulo’.

  • file (str, optional) – name of file in CSV of downloaded polygons with must columns: key, value, polygon.

  • radius (numeric, optional) – radius to around of point to intersect the polygon.

  • buffered (boolean) – True if the region is already buffered; False if you want buffer the region;

  • files (List[str]) –

dict_keys
Type

List[str]

key
Type

str

value
Type

str

place_name
Type

str

file
Type

str, optional

radius
Type

numeric, optional

enrich(data, **kwargs)

Method overrided of interface. This method do enrichment using OSM data as a enricher. It walk through the keys to reach at the data that will be used to intersect the polygons. It uses a R tree to index polygons and search faster. If the radius attribute is passed the algorithm returns all polygons that intersect the point buffered with this radius else the algorithm returns all polygons that contains the point.

Parameters

data (Data) –