def film_layer(contents): """ list -> layer Takes a list of lists and returns a layer with marked locations where the movie was set. """ fg = folium.FeatureGroup(name="Pointers") count = 0 # Receive a numbers of films user want to be shown on the map film_number = int( input("How much films do you want to receive from {} films: ".format( len(contents)))) if film_number > len(contents): return "Wrong input" for line in contents: if count == film_number: break count += 1 try: # Decoding an address of location geolocator = ArcGIS(timeout=10) location = geolocator.geocode(line[1]) fg.add_child( folium.Marker(location=[location.latitude, location.longitude], popup=line[0], icon=folium.Icon(color="red"))) except AttributeError: continue return fg
def process(): # Load enviroment variables from .env file load_dotenv(verbose=True) stores = [] api_key = os.getenv("PLACES_API_KEY") gmaps = googlemaps.Client(key=api_key) text_search_results = googlemaps.places.places_autocomplete(gmaps, "Aldi in New Jersey") pprint.pprint(text_search_results) # Connect to ArcGIS username = os.getenv('ARCGIS_USERNAME') password = os.getenv('ARCGIS_PASSWORD') referer = os.getenv('ARCGIS_REFERER') arcgis = ArcGIS(username, password, referer) # Retrieve the latitude and longitude for each store for store in stores: result = arcgis.geocode(store.get_full_address()) store.longitude = result.longitude store.latitude = result.latitude time.sleep(0.1) # Create a CSV file with open(output_path, 'a') as csvfile: writer = csv.writer(csvfile, delimiter=',') for store in stores: writer.writerow([store.latitude, store.longitude, store.streetAddress, store.locality, store.state, store.postal])
def post(self, request): try: user = request.user latitude = request.data.get('latitude') longitude = request.data.get('longitude') if latitude is None or longitude is None or latitude == 0 or longitude == 0: response = Response(helpers.fail_context( message="koordinat lokasi tidak valid"), status=status.HTTP_200_OK) else: geolocator = ArcGIS() location = geolocator.reverse( str(latitude) + ", " + str(longitude)) user_location = UserLocation.objects.filter(user=user).first() if user_location is None: user_location = UserLocation.objects.create(user=user) user_location.latitude = latitude user_location.longitude = longitude user_location.current_address = location.address user_location.updated_at = datetime.utcnow() user_location.save() data = UserLocationSerializer(user_location).data response = Response(helpers.success_context(location=data), status=status.HTTP_200_OK) except Exception as e: print(str(e)) response = Response(helpers.fatal_context(), status=status.HTTP_500_INTERNAL_SERVER_ERROR) return response
def process(): soup = get_soup(data_url) entries = [x for x in soup.findAll('a', {'class': 'Directory-listLink'})] data_links = [] for entry in entries: if (int(entry['data-count'][1:-1]) > 1): sub_soup = get_soup(link_base + str(entry['href'])) links = [ x for x in sub_soup.findAll('a', {'class': 'Teaser-titleLink'}) ] for link in links: data_links.append(link_base + str(link['href'])[2:]) else: data_links.append(link_base + str(entry['href'])) for link in data_links: print(link) stores = [] for link in data_links: print(link) soup = get_soup(link) streetAddress = soup.find(itemprop='streetAddress').get('content') locality = soup.find(itemprop='addressLocality').get('content') state = soup.find('abbr', {'class': 'c-address-state'}).text postal = soup.find('span', {'class', 'c-address-postal-code'}).text stores.append(Store(streetAddress, locality, state, postal)) # Connect to ArcGIS username = os.getenv('ARCGIS_USERNAME') password = os.getenv('ARCGIS_PASSWORD') referer = os.getenv('ARCGIS_REFERER') arcgis = ArcGIS(username, password, referer) # Retrieve the latitude and longitude for each store for store in stores: result = arcgis.geocode(store.get_full_address()) store.longitude = result.longitude store.latitude = result.latitude time.sleep(0.1) # Create a CSV file with open(output_path, 'w') as csvfile: writer = csv.writer(csvfile, delimiter=',') for store in stores: writer.writerow([ store.latitude, store.longitude, store.streetAddress, store.locality, store.state, store.postal ])
def get_geo_position_ArcGIS(loc): """ (str) -> tuple Function geocode adress and returns it's latitude and longitude using ArcGIS API """ locator = ArcGIS(timeout=10) place = locator.geocode(loc) return (place.latitude, place.longitude)
def main(user_lst, friends_lst, num): map_html = folium.Map() marker_cluster = MarkerCluster().add_to(map_html) geolocator = ArcGIS(timeout=10) lst = [ "Name: ", "Location: ", "Description: ", "url: ", "Followers: ", "Friends: ", "Listed: ", "Created: ", "Favourites: ", "Posts: " ] # Adding User on map place = geolocator.geocode(user_lst[1]) if place == None: popup_message = '<img src="{}"/><br>'.format(user_lst[-1]) for i in range(len(user_lst) - 1): popup_message += "{}{}<br>".format(lst[i], user_lst[i]) marker_cluster.add_child( folium.Marker(location=[randint(-90, 90), randint(-180, 180)], popup=popup_message, icon=folium.Icon(color='green'))) else: popup_message = '<img src="{}"/><br>'.format(user_lst[-1]) for i in range(len(user_lst) - 1): popup_message += "{}{}<br>".format(lst[i], user_lst[i]) marker_cluster.add_child( folium.Marker(location=[place.latitude, place.longitude], popup=popup_message, icon=folium.Icon(color='green'))) # Adding friends on map for i in range(len(friends_lst)): place = geolocator.geocode(friends_lst[i][1]) if place == None: popup_message = '<img src="{}"/><br>'.format(friends_lst[i][-1]) for j in range(len(friends_lst[i]) - 1): popup_message += "{}{}<br>".format(lst[j], friends_lst[i][j]) marker_cluster.add_child( folium.Marker(location=[randint(-90, 90), randint(-180, 180)], popup=popup_message, icon=folium.Icon(color='red'))) else: popup_message = '<img src="{}"/><br>'.format(friends_lst[i][-1]) for j in range(len(friends_lst[i]) - 1): popup_message += "{}{}<br>".format(lst[j], friends_lst[i][j]) marker_cluster.add_child( folium.Marker(location=[place.latitude, place.longitude], popup=popup_message, icon=folium.Icon(color='red'))) map_html.save("templates/map_html.html")
def process(): # Load enviroment variables from .env file load_dotenv(verbose=True) with open(data_path) as file: # Create BS4 Object from Data File soup = BeautifulSoup(file.read(), 'html.parser') # Create a list of the relevant list entries entries = [ x for x in soup.findAll( 'li', {'itemtype': 'http://schema.org/GroceryStore'}) ] # Iterate over each entry to and create a Store object for it. stores = [] for entry in entries: streetAddress = entry.find('span', { 'itemprop': 'streetAddress' }).text locality = entry.find('span', {'itemprop': 'addressLocality'}).text state = entry.find('span', {'itemprop': 'addressRegion'}).text postal = entry.find('span', {'itemprop': 'postalCode'}).text stores.append(Store(streetAddress, locality, state, postal)) # Connect to ArcGIS username = os.getenv('ARCGIS_USERNAME') password = os.getenv('ARCGIS_PASSWORD') referer = os.getenv('ARCGIS_REFERER') arcgis = ArcGIS(username, password, referer) # Retrieve the latitude and longitude for each store for store in stores: result = arcgis.geocode(store.get_full_address()) store.longitude = result.longitude store.latitude = result.latitude time.sleep(0.1) # Create a CSV file with open(output_path, 'w') as csvfile: writer = csv.writer(csvfile, delimiter=',') for store in stores: writer.writerow([ store.latitude, store.longitude, store.streetAddress, store.locality, store.state, store.postal ])
def process(): # Load enviroment variables from .env file load_dotenv(verbose=True) with open(data_path) as file: # Create BS4 Object from Data File soup = BeautifulSoup(file.read(), 'html.parser') # Create a list of the relevant list entries entries = [x for x in soup.findAll('div', {'class': 'storeAddress'})] # Iterate over each entry to and create a Store object for it. stores = [] for entry in entries: data = [ x for x in entry.findAll( 'div', {'class': 'w-store-finder-mailing-address'}) ] streetAddress = data[0].text locality = data[1].text.split(',')[0] state = data[1].text.split(',')[1].strip().split(' ')[0] postal = data[1].text.split(',')[1].strip().split(' ')[1] stores.append(Store(streetAddress, locality, state, postal)) # Connect to ArcGIS username = os.getenv('ARCGIS_USERNAME') password = os.getenv('ARCGIS_PASSWORD') referer = os.getenv('ARCGIS_REFERER') arcgis = ArcGIS(username, password, referer) # Retrieve the latitude and longitude for each store for store in stores: result = arcgis.geocode(store.get_full_address()) store.longitude = result.longitude store.latitude = result.latitude time.sleep(0.1) # Create a CSV file with open(output_path, 'w') as csvfile: writer = csv.writer(csvfile, delimiter=',') for store in stores: writer.writerow([ store.latitude, store.longitude, store.streetAddress, store.locality, store.state, store.postal ])
def okean_elzy_layer(): """ -> layer Returns a layer with marked locations where the Okean Elzy group concerts will take place in 2018 """ okean_elzy = folium.FeatureGroup(name="Concerts of Slavko") geolocator = ArcGIS(timeout=10) # Takes only one address because only one is given on the official site location_conc = geolocator.geocode('Velyka Vasylkivska St, 55, Kyiv') # Adding image of icon we want to use icon_v = folium.features.CustomIcon('vakarchuk.png', icon_size=(40, 40)) okean_elzy.add_child( folium.Marker( location=[location_conc.latitude, location_conc.longitude], popup="Concerts of Okean Elzy", icon=icon_v)) return okean_elzy
def map_formation(twi): js = parser(twi) fg = folium.FeatureGroup(name="Pointers") for line in js['users']: try: # Decoding an address of location geolocator = ArcGIS(timeout=10) location = geolocator.geocode(line['location']) fg.add_child( folium.Marker(location=[location.latitude, location.longitude], popup=line['name'], icon=folium.Icon(color="red"))) except AttributeError: continue return fg
def get_locations(lst, max_locat=50): """ (list, int) -> (list) :param lst: list of locations and films :param max_locat: a max number of locations function finds :return: list of tuples = [(film_name,(location.latitude, location.longitude)] """ locations = [] geolocator = ArcGIS(timeout=10) for element in lst: try: location = geolocator.geocode(element[1]) locations.append((element[0], (location.latitude, location.longitude))) if len(locations) == max_locat: break except: continue return locations
def locator(place): locator = Nominatim(user_agent="myGeocoder") try: locator = ArcGIS(timeout = 10) location = locator.geocode(place) coord = (location.latitude, location.longitude) except AttributeError: return None except: return None return coord
def process(): stores = [] stores.append(Store("724 Route 202 South", "Bridgewater", "NJ", "08807")) stores.append(Store("2100 Route 70 West", "Cherry Hill", "NJ", "08002")) stores.append(Store("34 Sylvan Way", "Hanover", "NJ", "07054")) stores.append(Store("55 US Highway 9", "Englishtown", "NJ", "07726")) stores.append(Store("100 Farm View", "Montvale", "NJ", "07645")) stores.append(Store("2 Centerton Road", "Mt. Laurel", "NJ", "08054")) stores.append(Store("1104 Highway 35 S", "Ocean", "NJ", "07712")) stores.append(Store("240 Nassau Park Blvd", "Princeton", "NJ", "08540")) stores.append( Store("15 Woodbridge Center Drive", " Woodbridge", "New Jersey", "07095")) # Connect to ArcGIS username = os.getenv('ARCGIS_USERNAME') password = os.getenv('ARCGIS_PASSWORD') referer = os.getenv('ARCGIS_REFERER') arcgis = ArcGIS(username, password, referer) # Retrieve the latitude and longitude for each store for store in stores: result = arcgis.geocode(store.get_full_address()) store.longitude = result.longitude store.latitude = result.latitude time.sleep(0.1) # Create a CSV file with open(output_path, 'w') as csvfile: writer = csv.writer(csvfile, delimiter=',') for store in stores: writer.writerow([ store.latitude, store.longitude, store.streetAddress, store.locality, store.state, store.postal ])
def find_loc(loc): """ str -> tuple Take name of location and return coordinats of this location """ locator = Nominatim(user_agent="myGeocoder") try: locator = ArcGIS(timeout = 10) location = locator.geocode(loc) coord = (location.latitude, location.longitude) except AttributeError: return None except: return None return coord
class ArcGIS(Provider): def __init__(self): self.geocoder = ArcGIS_geopy() def raw_location_keys(self) -> Tuple: return tuple(['score']) def max_requests(self) -> int: return internal_config['max-requests'] def identifier(self) -> str: return 'arcgis' def geocode(self, address) -> Location: return self.geocoder.geocode(address)
# Creating map # ------------ print("Creating map...") map = folium.Map() # ------------------------ # Setting locations on map # ------------------------ print("Setting locations...") i = 0 for key, value in dictionary.items(): geolocator = ArcGIS(timeout=10) place = geolocator.geocode(key) films = "" for j in range(usr_films): if j >= len(value): break films += "{}. {}<br>".format(j+1, value[j]) map.add_child(folium.Marker(location=[place.latitude, place.longitude], popup=films, icon=folium.Icon(color='orange'))) print("{} from {}".format(i+1, usr_num)) i += 1 if i >= usr_num: break # ------------------------- # Creating population layer
def __init__(self): self.geocoder = ArcGIS_geopy()
import geopy from geopy.extra.rate_limiter import RateLimiter from geopy import ArcGIS import json import pandas as pd import time locator = ArcGIS(user_agent="myGeocode") def get_lat_long(address): location = locator.geocode(address) if (location == None): time.sleep(3) API_KEY = "INSERT API KEY HERE" components = address.split(",") url = "https://us1.locationiq.com/v1/search.php" data = { 'key': API_KEY, 'street': components[0], 'city': components[1], 'state': components[2], 'country': 'US', 'format': 'json' } response = requests.get(url, params=data) json_file = json.loads(response.content) try: lat = json_file[0]["lat"] lon = json_file[0]["lon"] return lat, lon
import pandas import folium import os from geopy import ArcGIS nom = ArcGIS() data = pandas.read_csv("practice/Volcanoes.txt") lat = list(data["LAT"]) lng = list(data["LON"]) elv = list(data["ELEV"]) def color(elevation): if elevation < 1000: return 'green' elif 1000 <= elevation < 3000: return 'orange' else: return 'red' map = folium.Map(location=[38.58, -99.09]) fgv = folium.FeatureGroup(name="Volcanoes") for lt, ln, el in zip(lat, lng, elv): fgv.add_child( folium.CircleMarker(location=[lt, ln], radius=6, popup=str(el) + " m", fill_color=color(el), fille=True, color='grey', opacity=1))