Exemplo n.º 1
0
    def __init__(self, lion_version, crs='epsg:2263',
                 lion_loader=load_lion_gdf, force_rebuild=False,
                 network_type='cscl',
                 include_spatial_index=False, spatial_index_crs=None, **kwargs):

        self.crs = crs
        self.lion_version = lion_version.lower()
        self.lion_loader = lion_loader
        self.force_rebuild = force_rebuild
        self.cache_path = MICHI_HOME / self.lion_version / 'geocoder'
        if not self.cache_path.exists():
            self.cache_path.mkdir(parents=True)

        # ensure CRS parameters are parsable before instantiation
        pyproj.crs.CRS(crs)
        if spatial_index_crs:
            pyproj.crs.CRS(spatial_index_crs)

        # Instantiate Geosupport
        try:
            if geosupport_version is None:
                geosupport_version = self.lion_version
            self.geosupport = Geosupport(geosupport_version=version)
        except:
            # Use default geosupport
            self.geosupport = Geosupport()
            warn(
                "Using default Geosupport. "
                "May not match LION %s" % self.lion_version
            )

        (
            self.lion_df, self.nodes_df,
            self.lion_segments, self.streets,
            self.street_code_map
        ) = self._load_lion_data()

        self.street_names = self._build_search_data()

        self.network_type = network_type
        if network_type == 'cscl':
            self.segment_column = 'physical_id'
            self.segment_dict = 'cscl_segments'
        elif network_type == 'lion':
            self.segment_column = 'segment_id'
            self.segment_dict = 'lion_segments'

        # A regex to parse geometry strings, to be used by `self.parse_geometry`
        self.geometry_regex = re.compile(r'([a-z_]*):*(\d+)([A-Z]{0,1})')

        (
            self.cscl_segments_df, self.cscl_segments,
            self.node_network, self.segment_network,
            self.nodes_df, self.nodes
        ) = self._build_networks(self.network_type)

        self.segments = getattr(self, self.segment_dict)

        # SearchMixin
        # TODO Don't skip this, testing!
        #super().__init__(clear_cache=clear_cache, **kwargs)

        # get cache key to uniquely recognize spatial indexes
        #cache_key = get_cache_key(('_load_lion_data',) + (self,) + ({},))

        # load spatial indexes
        self.include_spatial_index = include_spatial_index
        self.spatial_index_crs = spatial_index_crs

        if self.include_spatial_index:
            self.lion_index = _get_spatial_index(
                self.lion_df, self.crs, self.spatial_index_crs, lion_version,
                'segment_index', 'segment_id'
            )
            self.node_index = _get_spatial_index(
                self.nodes_df, self.crs, self.spatial_index_crs, lion_version,
                'node_index', 'node'
            )
Exemplo n.º 2
0
from multiprocessing import Pool, cpu_count
from sqlalchemy import create_engine
from geosupport import Geosupport, GeosupportError
from pathlib import Path
import pandas as pd
import usaddress
import json
import re
import os

g = Geosupport()


def geocode(inputs):
    bin = inputs.get('bin', '')

    try:
        geo = g['BN'](bin=bin, mode='tpad')
        #geo = g['BN'](bin=bin, mode_switch='X')
        #geo = g.BN(mode='extended', bin=bin)
        #print(geo)
    except GeosupportError as e:
        geo = e.result

    geo = geo_parser(geo)
    geo.update(inputs)
    return geo


def geo_parser(geo):
    #million_bins = ['1000000', '2000000', '3000000', '4000000', '5000000']
Exemplo n.º 3
0
 def setUpClass(cls):
     g = Geosupport()
     cls.suggest = GeosupportSuggest(g)
     cls.app = api.app.test_client()
Exemplo n.º 4
0
 def setUpClass(cls):
     g = Geosupport()
     cls.suggest = GeosupportSuggest(g)
Exemplo n.º 5
0
 def setUpClass(cls):
     cls.geosupport = Geosupport()