Пример #1
0
def test_multi_results():
    g = geocoder.arcgis(location, maxRows='5')
    assert len(g) == 5

    expected_results = [
        'Ottawa, Ontario',
        'Ottawa, Ontario',
        'Ontario, Oklahoma'
    ]
    assert [result.address for result in g][:3] == expected_results
Пример #2
0
def get_location_geocoded(city_norm, city_real):
  geo_real = '' # send this to geocoder if one of the special cases
  if city_norm == 'bay area':
    geo_real = 'San Franciso'
  elif city_norm == 'nola':
    geo_real = 'New Orleans'
  elif city_norm == 'socal':
    geo_real = 'Anaheim'
  city, created = City.objects.get_or_create(norm_name=city_norm)
  if not created:
    return (city.lat, city.lng)
  city.real_name = city_real
  g = geocoder.arcgis(geo_real or city_real)
  city.lat, city.lng = g.latlng
  city.save()
  return (city.lat, city.lng)
Пример #3
0
def create_append2_std_address():
    engine_con = sqlalchemy.create_engine(FRANKSALARY_INSERT_CONNSTR_CONSOLIDATE)
    sql = """
        select 
            work_location_city1, work_location_state1 
        from perm 
        limit 10
    """
    df = pd.read_sql(sql, engine_con)

    # free geocoding service with no limit yet
    g_arc = geocoder.arcgis('New York, NY')
    js = g_arc.json
    if js['ok']:
        js['address']
        js['lat']
        js['lng']
def test_geocoder(address, method_name='geocoder'):
    """ geocoder
            - can use various providers (Google, OSM, etc.) https://geocoder.readthedocs.org/
            - can output GeoJSON
    """

    #g_geocoder = geocoder.google(address)
    g_geocoder = geocoder.osm(address)

    if g_geocoder.latlng == []:
        g_geocoder = geocoder.google(address)

    if g_geocoder.latlng == []:
        g_geocoder = geocoder.arcgis(address)

    if g_geocoder.latlng == []:
        g_geocoder = geocoder.yahoo(address)

    (latitude, longitude) = g_geocoder.latlng
    print ('{0}\t{1} {2}'.format(method_name, latitude, longitude))
    print(pprint(g_geocoder.geojson))
Пример #5
0
def geocode_address(infile, outfile):
    """
    This program takes the :param infile: and finds the ArcGIS geocoded address.  It writes the result
    to :param outfile: and to results.json.  if the address exists in results.josn, a call to ArcGIS isn't made
    """
    print(f"Geocoding Polling Location addresses")
    addrs = pd.read_csv(infile)
    print(f"Read Addresses {infile} ({len(addrs)})")
    try:
        found = result_file()
    except FileNotFoundError:
        found = dict()
    else:
        if found is None:
            found = dict()
    pbar = tqdm(desc="Geocoding Addresses", total=len(addrs), unit=' addrs')
    for idx, address in addrs.iterrows():
        address_1 = f"{address['addr']} {address['municipality']}, {address['province']} {address['post_code']} CANADA"
        pbar.set_postfix_str(address_1[:40])
        if address_1 in found:
            result = found[address_1]
        else:
            geocoder_object = geocoder.arcgis(address_1)
            result = geocoder_object.json
            found[address_1] = result
            result_file(found)
        try:
            addrs.at[idx, 'lat'], addrs.at[idx, 'lon'], addrs.at[idx, 'confidence'], addrs.at[idx, 'quality'], addrs.at[
                idx, 'score'] = \
                result['lat'], result['lng'], result['confidence'], result['quality'], result['score']
            easting, northing = to_lambert(result['lat'], result['lng'])
            addrs.at[idx, 'easting'], addrs.at[idx,
                                               'northing'] = easting, northing
        except TypeError:
            print(f"Address: \n{address_1}\n\twas not found")
        pbar.update()
    addrs.to_csv(outfile, encoding="UTF-8")
    print("\n\nFin")
Пример #6
0
    def geolocate(self, address, try_all=True):
        if address in self.geocache:
            return self.geocache[address]
        try:
            # should be installed from default skills
            from astral.geocoder import database, lookup
            # see https://astral.readthedocs.io/en/latest/#cities
            a = lookup(address, database())
            self.geocache[address] = (a.latitude, a.longitude)
            return a.latitude, a.longitude
        except:
            pass  # use online geocoder

        location_data = geocoder.osm(address)
        if not location_data.ok:
            location_data = geocoder.geocodefarm(address)
        if try_all:
            # more are just making it slow
            if not location_data.ok:
                location_data = geocoder.google(address)
            if not location_data.ok:
                location_data = geocoder.arcgis(address)
            if not location_data.ok:
                location_data = geocoder.bing(address)
            if not location_data.ok:
                location_data = geocoder.canadapost(address)
            if not location_data.ok:
                location_data = geocoder.yandex(address)
            if not location_data.ok:
                location_data = geocoder.tgos(address)

        if location_data.ok:
            location_data = location_data.json
            lat = location_data.get("lat")
            lon = location_data.get("lng")
            self.geocache[address] = (lat, lon)
            return lat, lon
        raise ValueError
Пример #7
0
def placeSingle(text):
    placeLists = []
    longitudeList = []
    latitudeList = []
    words, ners = fool.analysis(text)
    for itemSun in ners[0]:
        if itemSun[2] == 'location':
            places = geocoder.arcgis(itemSun[3])
            if places.latlng == None:
                continue
            placeLists.append(((places.address).split(','))[0])
            longitudeList.append(str(round(places.lng, 2)))
            latitudeList.append(str(round(places.lat, 2)))
    if placeLists == []:
        place = ''
        longitude = ''
        latitude = ''
        return place, longitude, latitude
    place = max(placeLists, key=placeLists.count)
    indexdata = placeLists.index(place)
    longitude = longitudeList[indexdata]
    latitude = latitudeList[indexdata]
    return place, longitude, latitude
Пример #8
0
def fetchtweets(query):
    tweets = []
    for tweet in tweepy.Cursor(api.search, q=query + ' -RT',
                               lang="en").items(150):
        location = tweet._json['user']['location']
        if len(location) != 0:
            jtweet = {}
            jtweet['created_at'] = tweet._json['created_at']
            jtweet['text'] = tweet._json['text']
            analysis = TextBlob((clean_tweet(jtweet['text'])))
            jtweet['sentiment'] = round(analysis.sentiment.polarity, 1)
            jtweet['location'] = tweet._json['user']['location']
            tweets.append(jtweet)

    for tweet in tweets:
        g = geocoder.arcgis(tweet['location'])
        try:
            tweet['latitude'] = g.json['lat']
            tweet['longitude'] = g.json['lng']
        except:
            pass
    print(len(tweets))
    return tweets
Пример #9
0
 async def hour(self, ctx, *, city: str):
     """Get the hour of a city"""
     if city.lower() in ['mee6', 'mee6land']:
         return await ctx.send(
             '**Mee6Land/MEE6**:\nEverytime (NoWhere)\n (Mee6Land - lat: unknown - long: unknown)'
         )
     g = geocoder.arcgis(city)
     if not g.ok:
         return await ctx.send(await self.translate(ctx.channel, "fun",
                                                    "invalid-city"))
     timeZoneStr = self.tz.tzNameAt(g.json['lat'],
                                    g.json['lng'],
                                    forceTZ=True)
     if timeZoneStr == 'uninhabited':
         return await ctx.send(await self.translate(ctx.channel, "fun",
                                                    "uninhabited-city"))
     timeZoneObj = timezone(timeZoneStr)
     d = datetime.datetime.now(timeZoneObj)
     format_d = await self.bot.cogs['TimeCog'].date(
         d,
         lang=await self.translate(ctx.channel, "current_lang", "current"))
     await ctx.send("**{}**:\n{} ({})\n ({} - lat: {} - long: {})".format(
         timeZoneStr, format_d, d.tzname(), g.current_result.address,
         round(g.json['lat'], 2), round(g.json['lng'], 2)))
Пример #10
0
    def get_coordinates(self, address):
        """ Using geocoder to decode address
            - can use various providers (Google, OSM, etc.) https://geocoder.readthedocs.org/
            - can output GeoJSON
            - proxies from http://www.proxy-listen.de/Proxy/Proxyliste.html
        """

        #proxies = {'149.202.249.227:3128', '144.76.232.58:3128'}

        #g_geocoder = geocoder.osm(address, proxies=proxies)
        g_geocoder = geocoder.osm(address)

        # in case OSM didn't provide anything use Google Maps
        if g_geocoder.latlng == []:
            g_geocoder = geocoder.google(address)

        # in case Google Maps didn't provide anything use ArcGIS
        if g_geocoder.latlng == []:
            g_geocoder = geocoder.arcgis(address)

        (latitude, longitude) = g_geocoder.latlng
        if DEBUG: print ('[i] location : {0} {1}'.format(latitude, longitude))

        return {'lat': latitude, 'lng': longitude}
Пример #11
0
	try:	
		for number in ('1','2','3','4','5'):
			storenameb = browser.find_element_by_xpath('//*[@id="results"]/table/tbody['+number+']/tr/td[2]').text
			if storenameb.find('@') != 0:
				storenameb = storenameb.replace('@', ' ')
			storename = storenameb[:storenameb.find("(",20)].replace('\n', ' ')
			storetype = browser.find_element_by_xpath('//*[@id="results"]/table/tbody['+number+']/tr/td[4]').text
			if browser.find_elements_by_xpath('//*[@id="results"]/table/tbody['+number+']/tr/td[5]/div') != []:
				storeplay = True
			else:
				storeplay = False
			if browser.find_elements_by_xpath('//*[@id="results"]/table/tbody['+number+']/tr/td[6]/div') != []:
				storedrive = True
			else:
				storedrive = False
			storelatlng = geocoder.arcgis(storename).latlng
			storefull = [storename.encode("utf-8"), storetype.encode("utf-8"), storeplay, storedrive, storelatlng]
			if storefull not in store_list:
				store_list.append(storefull)
				if storelatlng == []:
					print "lat-long for", storefull[0] , "is not found"
	except:
		count += 1
		print zipcode, "error!, no such thing :", str(count) ,"out of", str(ziplen)
	else:
		count += 1
		print zipcode, "is done :", str(count) ,"out of", str(ziplen)

browser.close()

#write all results to .csv
Пример #12
0
for c in casts:
    if c['RSS Feed'] and c['Link to Audiofile'] and 'guid' not in c:
        try:
            c['guid'] = getGuid(c['RSS Feed'], c['Link to Audiofile'])
        except Exception as e:
            print e

by_location = defaultdict(list)
for e in casts:
    if not e['Location']:
        continue
    by_location[e['Location']].append(e)

coords = {
    l: geocoder.google(l).latlng or geocoder.arcgis(l).latlng
    for l in by_location
}

print[k for k, v in coords.iteritems() if not v]

out = {
    "type":
    "FeatureCollection",
    "features": [{
        "type": "Feature",
        "properties": {
            "name": l,
            "casts": casts
        },
        "geometry": {
Пример #13
0
    destination_latitude = 0
    destination_name = ""
    departure_longitude = 0
    departure_latitude = 0
    departure_name = ""
    departure_id = 0
    destination_id = 0

    for word in words:
        for m in re.finditer(pattern, word):
            word_results.append(m.group(0))
            if len(m.group(0)) > 3:
                with requests.Session() as session:
                    searchString = m.group(0)
                    print("Geocode: " + searchString)
                    g = geocoder.arcgis(searchString, session=session)
                    print(g.json)
                    if not g.ok:
                        pass
                    else:
                        lat = 0
                        lng = 0
                        name = ""
                        for result in g:
                            lat = result.lat
                            lng = result.lng
                            name = result.address
                            pass
                        if lng > 36.6 or lng < -9.2 or lat > 58.5 or lat < 33.2:
                            pass
                        else:
Пример #14
0
import geocoder
import requests

g = geocoder.arcgis('Redlands, CA')
print(g.latlng)  # latlng is a tuple with a length of 2.

dest = [
'Space Needle',
'Crater Lake',
'Golden Gate Bridge',
'Yosemite National Park',
'Las Vegas, Nevada',
'Grand Canyon National Park',
'Aspen, Colorado',
'Mount Rushmore',
'Yellowstone National Park',
'Sandpoint, Idaho',
'Banff National Park',
'Capilano Suspension Bridge'
]

for point in dest:
  loc = geocoder.arcgis(point)
  print(f"{point} Located at {loc.latlng}")
Пример #15
0
    #state = file.split('_')[0]
    state = 'Vietnam'
    filename = file.split('.')[0]

    with open(os.path.join(folder, file), 'r') as f:
        df = pd.read_csv(f, names=['PERSNBR','BRANCHNBR','TAXID','ADDRNAME','latitude','longitude'], skiprows=1)
        places = df['ADDRNAME']
        count = 0

        for place in places:
            time.sleep(random.random())
            address = '{}, {}'.format(place, state)
            #print(address)
            #print(df.latitude[count])
			
            g = geocoder.arcgis(address)

            trials = 5
            for i in range(trials):
                #print(g.status)
                if g.status == 'OK':
                    df.latitude[count] = g.latlng[0]
                    df.longitude[count] = g.latlng[1]					
                    break
                elif g.status == 'ZERO_RESULTS':
                    g = geocoder.arcgis(address)
                    if i == trials - 1:
                        print("ERROR: No Result")
                else:
                    print('ERROR')
                    print(g.current_result)
Пример #16
0
draw = ImageDraw.Draw(img)

logging.info("Display dimensions: W %s x H %s", WIDTH, HEIGHT)

display_weather = False

if NEXT_DISPLAY == 'weather':
    weather_location = None
    if "WEATHER_LOCATION" in os.environ:
        weather_location = os.environ["WEATHER_LOCATION"]
    # Get the latitute and longitude of the address typed in the env variable if latitude and longitude are not set
    if weather_location and (not LAT or not LONG):
        logging.info(f"Location is set to {weather_location}")
        try:
            geo = geocoder.arcgis(weather_location)
            [LAT, LONG] = geo.latlng
        except Exception as e:
            print(f"Unexpected error: {e.message}")

    # If no address or latitute / longitude are found, retrieve location via IP address lookup
    if not LAT or not LONG:
        location = get_location()
        [LAT, LONG] = [float(x) for x in location['loc'].split(',')]
    weather = get_weather(LAT, LONG)
    # Set latitude and longituted as environment variables for consecutive calls
    os.environ['LATLONG'] = f"{LAT},{LONG}"
    # If weather is empty dictionary fall back to drawing quote
    if len(weather) > 0:
        img = draw_weather(weather, img, SCALE)
        display_weather = True
Пример #17
0
def find_location(city: str) -> str:
    """
    find geocode by city
    """
    g = geocoder.arcgis(city)
    return str(g.latlng)
Пример #18
0
    + "Coordinates"
    + "	"
    + "City"
    + "	"
    + "State"
    + "	"
    + "Postal"
    + "\n"
)


# In[9]:

for i in xrange(3113, len(add_list)):
    print i
    arcResult = geocoder.arcgis(add_list[i].decode("utf8"))
    print arcResult
    coordinates = arcResult.latlng
    address = arcResult.address
    gooResult = geocoder.google(coordinates, method="reverse")
    print gooResult
    city = gooResult.city
    postal = gooResult.postal
    state = gooResult.state
    if arcResult.status == "OK" and gooResult.status == "OK":
        geo_file.write(
            str(i)
            + "	"
            + add_list[i].strip("\n")
            + "	"
            + address
        address = address.replace("                          ","")

        #format postcode
        list = address.split(', ');
        postcode = list[len(list)-1]

        #format station name
        stationname = str(header[0].contents[0])
        stationname = stationname[:-2]

    except:
        #error calling url. Continue to next crs code
        print 'Networkrail ERROR:' + crscode
        continue

    try:
        #geocode postcode. Try arcgis and then mapquest if arcgis fails.
        g = geocoder.arcgis(postcode)
        if not g.lat:
            g = geocoder.mapquest(postcode, key='PXstG2wqhxmTuWThW0lC6RhDWJ89DHTe')

        line = '"' + crscode +'", "'+ str(g.lat) +'", "'+ str(g.lng) +'", "'+stationname +'", "'\
               + postcode +'", "' + operator + '", "'+ address +'"'
        print line
        f.write(line+'\n')  # python will convert \n to os.linesep
    except:
        print 'geocoding ERROR:' + crscode
    continue

f.close()
Пример #20
0
import geocoder
add_list = list(open('address'))
print len(add_list)

geo_file = open('geo_file-left','w')
geo_file.write('LineID' + '	' + 'OrignalAddress' + '	' + 'NewAddress' + '	' + 'Coordinates' + '	' + 'City' + '	' + 'State' + '	' + 'Postal' + '\n')


# In[9]:

LeftIDList = list(open('Left LineID', 'r'))

for i in LeftIDList:
    i = int(i.strip())
    print i
    arcResult = geocoder.arcgis(add_list[i].decode('utf8'))
    print arcResult
    coordinates = arcResult.latlng
    address = arcResult.address
    gooResult = geocoder.google(coordinates, method = 'reverse')
    print gooResult
    city = gooResult.city
    postal = gooResult.postal
    state = gooResult.state
    if arcResult.status == 'OK' and gooResult.status == 'OK':
        geo_file.write(str(i) + '	' + add_list[i].strip('\n') + '	' + 
                       address + '	' + 
                       str(coordinates) + '	' + 
                       city + '	' + 
                       state  + '	' + 
                       str(postal) + '\n')
Пример #21
0
def test_arcgis():
    g = geocoder.arcgis(location)
    assert g.ok
    osm_count, fields_count = g.debug()[0]
    assert osm_count == 0
    assert fields_count == 8
Пример #22
0
 def blocking_refresh(self):
     self._g = geocoder.arcgis(self._name)
     self._result = QGeoCoordinate(self._g[0].lat, self._g[0].lng)
     self.geocodeUpdated.emit(self._result)
Пример #23
0
def test_arcgis_reverse():
    g = geocoder.arcgis(ottawa, method='reverse')
    assert g.ok
Пример #24
0
import geocoder
g = geocoder.arcgis(u"上海")
dir(g)
help(g.y)
help(g)
g.street
type(g)
type(g.street)
l = [2,34,5]
type(l)
isinstance(l, list)
l = [12,"a"]
l
s = {"a":1}
s
type(s)
ll
ll
pwd
ls
ll
g.ok
g.latl
g.latlng
type([])
frozenset
help("frozenset")
f = frozenset()
f.difference
f.difference()
d = {"a":1,"b":2}
Пример #25
0
import geocoder

with open("assets/native-seattle-places-geocoded.csv", "w", encoding="utf8") as geofp:
    geofp.write("name, frequency, lat, lng\n")
    with open("assets/native-seattle-places.csv", "r", encoding="utf8") as fp:
        for line in fp.readlines():
            location = line.split(",")[0]
            freq = int(line.split(",")[1])
            try:
                g = geocoder.arcgis(location)
                lat = g.current_result.lat
                lng = g.current_result.lng
                geofp.write("%s, %d, %f, %f\n" % (location, freq, lat, lng))
                print(location, freq, lat, lng)
            except:
                pass
print("finished!")
Пример #26
0
import requests
import geocoder
api_base_url = "https://api.darksky.net/forecast/71321cb803dc4539cd35795c6b9d3d78/"

destinations = [
    "Space Needle", "Crater Lake", "Golden Gate Bridge",
    "Yosemite National Park", "Las Vegas, Nevada",
    "Grand Canyon National Park", "Aspen, Colorado", "Mount Rushmore",
    "Yellowstone National Park", "Sandpoint, Idaho", "Banff National Park",
    "Capilano Suspension Bridge"
]

for place in destinations:
    lat = geocoder.arcgis(place).lat
    lng = geocoder.arcgis(place).lng
    full_api_url = (f"{api_base_url}{lat},{lng}")
    result = requests.get(full_api_url).json()
    summ = result["currently"]["summary"]
    temp = "{0:.1f}".format(result["currently"]["temperature"])
    print(
        f"{place} is located at ({lat}, {lng}). The weather is {summ} with a temperature of {temp}\u00B0F.\n"
    )
Пример #27
0
def get_location(location):
    try:
        g = geocoder.arcgis(location)
        return g.latlng
    except:
        return "Not found"
Пример #28
0
    # one approach is to use pandas json functionality:
    elevation = pd.io.json.json_normalize(r, 'results')['elevation'].values[0]
    return elevation


def get_coords(text):
    """ Returns (latitude, longitude, elevation) triple geocoded text. """
    g = geocoder.osm(text)
    lat = g.json['lat']
    lon = g.json['lng']
    print("%.4f, %.4f" % (lat, lon))
    h = get_elevation(lat, lon)
    return (lat, lon, h)


g = geocoder.arcgis('Lysa hora, okres Frydek')
g.json

g = geocoder.yahoo('Lysa hora, okres Frydek')
g.json

h = get_elevation(g.json['lat'], g.json['lng'])

get_coords('Lysa hora, okres Frydek')

# https://cgiarcsi.community/data/srtm-90m-digital-elevation-database-v4-1/
# http://www.viewfinderpanoramas.org/dem3.html

graphhopper_api_key = "3aa82fd4-5229-4983-9ec3-27a49339cd4e"
geocode_url = "https://graphhopper.com/api/1/geocode?q=berlin&locale=de&debug=true&key=%s" % graphhopper_api_key
r = requests.get(geocode_url).json()
Пример #29
0
def test_arcgis():
    g = geocoder.arcgis(location)
    assert g.ok
Пример #30
0
def getLatLngArcGIS(key, address):   ##key is not used.  Only present to support googleMaps.  
    g = geocoder.arcgis(address)
    if g.latlng == []:
        return 0
    h = [str(g.latlng[0]), str(g.latlng[1])]
    return h
Пример #31
0
<b>Rating:</b> {rating}
""".format(
        link_href=link.attrs["href"],
        alert_msg=alert_msg,
        reserve_phone=reserve_phone,
        info_phone=info_phone,
        email=email,
        rv_checkout_checkin=rv_checkout_checkin,
        address_1=address_1,
        address_2=address_2,
        rating=rating,
    )

    # note: this is a free and simple geocoder but not the most accurate
    # google might be best but costs $$
    geocode_result = geocoder.arcgis(", ".join([address_1, address_2]))
    latlng_str = ",".join(
        [str(_) for _ in geocode_result.current_result.latlng[::-1]])
    placemark = KML.Placemark(
        KML.name(name),
        KML.description(description),
        KML.Point(KML.coordinates(latlng_str), ),
    )
    folder.append(placemark)

with open("koa-campgrounds.kml", "w") as fh:
    fh.write(
        etree.tostring(
            format_xml_with_cdata(folder),
            method="xml",
            encoding="unicode",
Пример #32
0
stationDict = {}

#but bike stations and location into local dict
with open('bikeShareData.csv', 'w', newline='') as f:
    fieldnames = ['id', 'name', 'lat', 'long']

    for each in stationJson['data']['stations']:
        #print(each['name'])
        id = int(each['station_id'])
        stationDict[id] = [each['name'], each['lat'], each['lon']]

#print(stationDict)

loc = input("Please enter your address or zipcode: ")

g = geocoder.arcgis(loc)  #coodinates of your address
print("Your location: \n", g.latlng)

while 1:
    coords_1 = g.latlng

    ebikeDict = {}

    sum = 0
    timeNow = datetime.datetime.now()
    print("\nLast checked: {:%m/%d/%Y  %I:%M %p}\n".format(timeNow))

    for each in stationStatus['data']['stations']:
        id = int(each['station_id'])
        ebikeNum = each['num_ebikes_available']
        #print(stationDict[id][0])
import geocoder

spots = [
    'Space Needle', 'Crater Lake', 'Golden Gate Bridge',
    'Yosemite National Park', 'Las Vegas, Nevada',
    'Grand Canyon National Park', 'Aspen, Colorado', 'Mount Rushmore',
    'Yellowstone National Park', 'Sandpoint, Idaho', 'Banff National Park',
    'Capilano Suspension Bridge'
]

# g = geocoder.arcgis(spots)

locationList = []

for location in spots:
    print("{} is in: {}".format(location, geocoder.arcgis(location).latlng))
    # print(geocoder.arcgis(location).latlng)
Пример #34
0
import pandas as pd
import numpy as np

postcode = pd.read_csv(
    '/Users/luhao/Desktop/Geocoder_tool/Registered_Landfills.csv', usecols=[8])
postcode_list = np.array(postcode['SitePostCode'].tolist()).tolist()
poco = [x.replace('nan', 'NA') for x in postcode_list]

location = pd.read_csv(
    '/Users/luhao/Desktop/Geocoder_tool/Registered_Landfills.csv',
    usecols=[2, 3, 4, 5, 6, 7])
location_array = np.array(location.values.tolist())
loc_list = [','.join(x) for x in location_array]
loc = [x.replace('nan,', '') for x in loc_list]

regi_code = []
for i in range(0, 564):
    if poco[i] != 'NA':
        if geocoder.arcgis(poco[i]).latlng != None:
            geocode = geocoder.arcgis(poco[i]).latlng
        print('Done +1 using poco')
    else:
        geocode = geocoder.arcgis(loc[i]).latlng
        print('Done +1 using loc')
    if geocode != None:
        regi_code.append(geocode)
        print('-------Success +1--------')
regi_array = np.array(regi_code)
regi_df = pd.DataFrame({'Lat': regi_array[:, 0], 'Lon': regi_array[:, 1]})
regi_df.to_csv('regi_code.txt', index=None)
Пример #35
0
import geocoder

destinations = [
    "The Space Needle", "The Golden Gate Bridge", "Yosemite National Park",
    "Las Vegas, Nevada", "Grand Canyon National Park", "Aspen,Colorado",
    "Mount Rushmore", "Yellowstone National Park", "Sandpoint, Idaho",
    "Banff National Park", "Capilano Suspension Bridge"
]

for point in destinations:
    location = geocoder.arcgis(point)

    print("{0} is located at ({1:.4f}, {2: .4f})".format(
        point, location.latlng[0], location.latlng[1]))
Пример #36
0
with arcpy.da.UpdateCursor(
    Locations, [MatchStatus, "X", "Y", Address, city, state, zipCode, MatchAddress, "Addr_type"]
) as cursor:
    for row in cursor:

        # check if row has unmatched status
        if row[0] == "U":
            addr = "{0}, {1} {2} {3}".format(row[3], row[4], row[5], int(row[6]))

            # -------------------------------------------------------------------------------------------
            # Check if the current address is in the dictionary. If it isn't, go ahead and geocode it.
            # -------------------------------------------------------------------------------------------
            if not AddressDict[addr]:
                arcpy.SetProgressorLabel("Locating {0}".format(addr))

                loc = geocoder.arcgis(addr)
                st = stDict[row[5]]
                z = str(row[6])
                # check that the quality is sufficient, and zip code and state match the current candidate location
                if loc.quality in qualList:  # and loc.postal == z: #and st == loc.address.split(',')[-2].strip():

                    arcpy.SetProgressorLabel("Match found for {0}".format(addr))

                    row[2] = loc.lat
                    row[1] = loc.lng
                    row[0] = "M"
                    row[7] = loc.address
                    row[8] = loc.quality

                    cursor.updateRow(row)
Пример #37
0
import os
import unicodecsv
wd = "I:/Dropbox/NDAD/Visualizing-Empire/OpeNER/test"
os.chdir(wd)

filename = "1880-p1-test.csv"

# In[ ]:

with open(filename, 'r') as f:
    cfile = unicodecsv.reader(f, delimiter=",")
    output = codecs.open(filename + ".geocoded.csv", "w", encoding="utf8")
    output.write("LOC,FREQ,LAT,LON\n")
    for row in cfile:
        #g=geocoder.google(row[0])  #google also includes g.city,g.state,g.country,
        g = geocoder.arcgis(row[0])
        if g.latlng:
            lat = g.latlng[0]
            lon = g.latlng[1]
        l = [unicode(row[0]), row[1], lat, lon]
        export_text = ",".join(unicode(x) for x in l) + "\n"
        output.write(export_text)
        print "OUTPUT: " + export_text,
    output.close()

# In[50]:

output.close()

# In[ ]:
import csv
import geocoder

f = open('latlng-arcgis.csv', 'w')
reader = csv.reader(open("train/train.tsv"), delimiter="	")
flats = []

for xi in reader:
    flats.append(xi)

i = 1

for flat in flats:
    g = geocoder.arcgis(flat[4])
    print(i)
    if ('lat' in g.json and 'lng' in g.json):
        f.write(str(g.json['lat']) + "," + str(g.json['lng']) + "\n")
    else:
        g2 = geocoder.google(flat[4])
        if (hasattr(g2, 'latlng')): f.write(str(g.latlng) + "\n")
        else: f.write("brak, brak")
    i += 1
f.close()
Пример #39
0
  def address_to_latlng(self, address):

    g = geocoder.arcgis(address)
    return (g.lat, g.lng)
geo_df[1:50]


# In[ ]:

# create a separate dataframe for visualization
geo_df = df_all[['from_user_location', 'content', 'coordinates','from_user_followers_count', 'RT_or_not']]


# In[51]:

for index, row in geo_df[50001:].iterrows():
    a = row['from_user_location']
    if a!='':
        try:
            g = geocoder.arcgis(a)
            #print g, '\n', '\n', '\n'
            k = abs(g.lat)+abs(g.lng) #used to minimize errors in geodecoding process
            if k >0:
                print ("currently processing index number:", index)
                print ([unicode(g.lat)], [unicode(g.lng)])
                #geo_df.ix[index,'lat'] = g.lat
                geo_df.loc[index,'lat'] = g.lat
                #geo_df.ix[index,'lng'] = g.lng
                geo_df.loc[index, 'lng'] = g.lng
        except: pass
        


# In[ ]:
Пример #41
0
    state = line.split(",")[-3]
    county = line.split(",")[-2]
    try:
        note = line.split(",")[3].replace("\n", " ").replace(
            "\r",
            " ").replace("\t", " ").replace('"', '').replace('"', '').replace(
                '  ', ' ').replace('  ', ' ').replace('  ', ' ').strip()
    except:
        note = ""
    try:
        reference = line.split(",")[-1].strip().replace("\n", " ")
    except:
        reference = ""

    try:
        g = geocoder.arcgis(county + " county, " + state + ", U.S.A.")
        lat = g.current_result.lat
        lng = g.current_result.lng
    except:
        lat = 0
        lng = 0
    # time.sleep(1)
    id += 1
    print(no, date, county, state, lat, lng, note, reference)
    output = '%d,"%s","%s","%s","%s",%f,%f,"%s","%s"\n' % (
        id, no, date, county, state, lng, lat, note, reference)
    outputs.append(output)

with open("reformed.csv", "a", encoding="utf-8") as fp:
    #fp.write("id,no,date,county,state,lng,lat,note,reference\n")
    for output in outputs:
Пример #42
0
import requests
from secrets import API_KEY

# Vars
API_BASE_URL = "http://api.openweathermap.org/data/2.5/weather"

destinations = [
    'Space Needle', 'Crater Lake', 'Golden Gate Bridge',
    'Yosemite National Park', 'Las Vegas, Nevada',
    'Grand Canyon National Park', 'Aspen, Colorado', 'Mount Rushmore',
    'Yellowstone National Park', 'Sandpoint, Idaho', 'Banff National Park',
    'Capilano Suspension Bridge'
]

#Loop
for point in destinations:
    lat, lon = geocoder.arcgis(point).latlng
    result = requests.request(
        'GET', f'{API_BASE_URL}?lat={lat}&lon={lon}&APPID={API_KEY}').json()
    weather = result["weather"][0]["description"]
    # print(weather)
    temp_data = result["main"]
    temp = temp_data["temp"]
    f_temp = (temp - 273.15) * 9 / 5 + 32
    f_temp_rounded = float("{:.2f}".format(f_temp))
    rounded_lat = float("{:.2f}".format(lat))
    rounded_lon = float("{:.2f}".format(lon))
    print(
        f'🌐 {point}:\n latitude: {rounded_lat}, longitude: {rounded_lon}).\n 🌀 Weather: {weather}, 🌡 Temperature: {f_temp_rounded} ℉     \n'
    )
Пример #43
0
 def geocode_address(address, s):
     g = geocoder.arcgis(address, session=s.Arcgis)
     if (g.ok == False):
         g = geocoder.komoot(address, session=s.Komoot)
     return g
Пример #44
0
def get_coords(address):
    g = geocoder.arcgis(address)
    coords = g.latlng
    logging.info("Location coordinates: %s", coords)
    return coords
Пример #45
0
destinations = [
    "Space Needle",
    "Crater Lake",
    "Golden Gate Bridge",
    "Yosemite National Park",
    "Las Vegas, Nevada",
    "Grand Canyon National Park",
    "Aspen, Colorado",
    "Mount Rushmore",
    "Yellowstone National Park",
    "Sandpoint, Idaho",
    "Banff National Park",
    "Capilano Suspension Bridge",
]

import geocoder

# Declare destinations list here.

# Loop through each destination.
for point in destinations:
    g = geocoder.arcgis(point)
    print(point, " is located at ", g.latlng)
#   Get the lat-long coordinates from `geocoder.arcgis`.
#   Print out the place name and the coordinates.
Пример #46
0
def test_arcgis():
    g = geocoder.arcgis(location)
    assert g.ok