class County: counties = { county['properties']['name']: GEOSGeometry(json.dumps(county['geometry'])) for county in datafile('california-counties.geojson')['features'] if county['properties']['name'] in [ 'Fresno', 'Kern', 'Kings', 'Madera', 'Merced', 'San Joaquin', 'Stanislaus', 'Tulare', ] } names = list(sorted(counties.keys())) @classmethod def lookup(cls, point, default=''): for name, geometry in cls.counties.items(): if geometry.contains(point): return name return default
def load_counties(self): geometry = [ shape(county['geometry']) for county in datafile('california-counties.geojson')['features'] if county['properties']['name'] in [ 'Fresno', 'Kern', 'Kings', 'Madera', 'Merced', 'San Joaquin', 'Stanislaus', 'Tulare', ] ] return gpd.GeoDataFrame({'geometry': geometry})
def load_datafile(name): return datafile(name)