Functional Connector
Examples
This example implements the use of Functional Region Connector. It uses a simple file extracted from OSM tag called: leisure - fitness_centre that has all fitness centre of a place. Here it counts all fitness centre that is within a raidus around a point of interest specified in user_profile_17092019_preprocessed.json file.
import os
import sys
sys.path.insert(0, os.path.abspath('../../'))
from moredata.enricher import EnricherBuilder, Enricher
from moredata.models.data import Data
from moredata.parser import parse_document
from moredata.utils.util import read_json_from_file, Converter
from moredata.enricher.osm.functional_region_connector import FunctionalRegionConnector
DATASETS_DIR = "../../../datasets/"
FITNESS_CENTRE = DATASETS_DIR + "Locais_OSM/csv/leisure-fitness_centre.csv"
USER_DATA = DATASETS_DIR + "user_profile_17092019_preprocessed.json"
if __name__ == "__main__":
user = Data(data_file=USER_DATA, parser_func=parse_document, data_type="json")
osm_enricher = Enricher(connector=FunctionalRegionConnector(file=FITNESS_CENTRE, radius=500, 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/functional-fitness-centre", user_enriched, 100000)
$ python enrich-osm.py
Functional Region Connector
- class moredata.enricher.osm.functional_region_connector.FunctionalRegionConnector(files, key, dict_keys=[])
FunctionalRegionConnector implements IEnricherConnector interface, so this is a connector that can be used to enrich data. This connector counts how much elements is within a radius of a lat/lon specified by your data.
- Parameters
files (List[str]) – An array of files that will be used to enrich your data. Each file must have 1 attribute, an geometry specifying the polygon to index in RTree.
dict_keys (List[str]) – 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) – Key attribute is the name of the new column of your data that stores the counting.
- files
- Type
List[str]
- dict_keys
- Type
List[str]
- key
- Type
str
- enrich(data, **kwargs)
Method overrided of interface. 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. For optimization purposes we recommend to buffer the point, using
geodesic_point_bufferfunction, creating, necessarily, a label namedarea_point, and save the file with points buffered to use as base of enrichment. After buffer the points, you can use the Functional Region Connector to create your enrichment passing proper attributes.