def find_addr(callback_map, g): try: callback_map.draw(g) geocoded = geocoding.reverse_geocode(g) print(geocoded['address']['Match_addr']) except: print("Couldn't match address. Try another place...")
def geolocation(lat: float, long: float): results = reverse_geocode([long, lat]) if results: print(results) return { 'name': results['address']['LongLabel'], 'address': results['address']['Address'], } return {}
def reverseGeocode(coordinates): try: gis = GIS('http://www.arcgis.com', '*****', '*****') #result = rg.search(coordinates) results = reverse_geocode([coordinates[1],coordinates[0]]) # result is a list containing ordered dictionary. return results['address'] except(): return {'Subregion':'','Region':''}
def reverse_geocode_addr(coord_list): """ Given a list of [Long, Lat] values, reverse geocode to identify which city and state those values are. Used to ensure that a certain provided address is in Boston, MA :param coord_list: a list of [Long, Lat] :return: a descriptive location """ return reverse_geocode(coord_list)
def reverseGeocode(coordinates): try: gis = GIS('http://www.arcgis.com', '*****', '*****') #Search up corndinates using the arcGIS API results = reverse_geocode([coordinates[1], coordinates[0]]) # result is a list containing ordered dictionary. return results['address'] except (): #If the county cannot be found with the API return {'Subregion': '', 'Region': ''}
def reverse_geocode(self, locations): '''Get address from coordinate pairs''' addresses = [] for location in locations: unknown_pt = Point(location) address = reverse_geocode(unknown_pt) addresses.append(address) print(addresses) return addresses
def get_address_by_gis(lon, lat): reverse_geocode = None try: reverse_geocode = geocoding.reverse_geocode({ "x": lon, "y": lat }, lang_code='en') except Exception as exp: print(exp) return reverse_geocode['address']['LongLabel']
def get_geo_location_info_by_OD_matrix(lon, lat): origin_coords = [ '50.448069, 30.5194453', '50.448616, 30.5116673', '50.913788, 34.7828343' ] # origin_coords = ['-117.187807, 33.939479', '-117.117401, 34.029346'] origin_features = [] for origin in origin_coords: reverse_geocode = geocoding.reverse_geocode({ "x": origin.split(',')[0], "y": origin.split(',')[1] }) origin_feature = Feature(geometry=reverse_geocode['location'], attributes=reverse_geocode['address']) origin_features.append(origin_feature) origin_fset = FeatureSet(origin_features, geometry_type='esriGeometryPoint', spatial_reference={'latestWkid': 4326}) destinations_address = r"data/destinations_address.csv" destinations_df = pd.read_csv(destinations_address) destinations_sdf = pd.DataFrame.spatial.from_df(destinations_df, "Address") destinations_fset = destinations_sdf.spatial.to_featureset() try: results = generate_origin_destination_cost_matrix( origins=origin_fset, # origins_fc_latlong, destinations=destinations_fset, # destinations_fs_address, cutoff=200, origin_destination_line_shape='Straight Line') od_df = results.output_origin_destination_lines.sdf # filter only the required columns od_df2 = od_df[[ 'DestinationOID', 'OriginOID', 'Total_Distance', 'Total_Time' ]] # user pivot_table od_pivot = od_df2.pivot_table(index='OriginOID', columns='DestinationOID') return od_pivot except Exception as exp: print(exp) return None
def find_addr(hello_map, g): # try: hello_map.draw(g) global address geocoded = geocoding.reverse_geocode(g) address = geocoded['address']['Match_addr'] # adres_read = Adres_read(address) # print(adres_read.get_points()) try: print('creating') # a = Osm_reader(adres_read.get_points()) # a.create_file() print('file created') except: print("beda")
def fetch_geocoding_data_with_caching(input_data, reverse=False): global HIT_API_YET if reverse == True: # Convert longitude latitude pair into a string to serve as a key in the cache dictionary input_string = str(input_data[0]) + ', ' + str(input_data[1]) else: input_string = input_data if input_string in CACHE_DICTION: # print("** Pulling data from cache **") return CACHE_DICTION[input_string] else: print("** Fetching new data from API **") if not HIT_API_YET: gis = GIS() HIT_API_YET = True if reverse == False: data = geocode(input_string) # geocode() argument is a string else: data = reverse_geocode(input_data) # reverse_geocode() argument is a list CACHE_DICTION[input_string] = data cache_file_open = open(ARCGIS_CACHE_FILE_NAME, "w") cache_file_open.write(json.dumps(CACHE_DICTION, indent=4)) cache_file_open.close() return data
# run with ArcGIS API for Python 3 # Find an address using ArcGIS World Geocoding Service from arcgis.gis import * from arcgis.geocoding import geocode, reverse_geocode from arcgis.geometry import Point # Log into ArcGIS Online as an anonymous user dev_gis = GIS() # Search for the Hollywood sign geocode_result = geocode(address="200 Lincoln Ave Salinas CA", as_featureset=True) print(geocode_result) # Reverse geocode a coordinate print("") location = { 'Y': 36.67526264843514, 'X': -121.65731271093892, 'spatialReference': { 'wkid': 4326 } } unknown_pt = Point(location) address = reverse_geocode(location=unknown_pt) print(address)