Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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))
Ejemplo n.º 5
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}
Ejemplo n.º 6
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
Ejemplo n.º 7
0
def test_arcgis():
    g = geocoder.arcgis(location)
    assert g.ok
        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()
Ejemplo n.º 9
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')
Ejemplo n.º 10
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
Ejemplo n.º 11
0
def test_arcgis_reverse():
    g = geocoder.arcgis(ottawa, method='reverse')
    assert g.ok
Ejemplo n.º 12
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}
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[ ]:
Ejemplo n.º 14
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)
Ejemplo n.º 15
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
Ejemplo n.º 16
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)