Ejemplo n.º 1
0
class Geocoder(object):
    def __init__(self, API_KEY=None):
        if not API_KEY:
            # get keys from os.environ, because we may not have current_app context
            API_KEY = os.environ.get('GEOCODE_API_KEY')
        self.client = GeocodioClient(API_KEY)

    def zipcode(self, zipcode, cache=None):
        if cache:
            districts = cache.get_district(zipcode)
            if len(districts) == 1:
                d = districts[0]
                d['source'] = 'local district cache'
                return Location(d)
            else:
                # TODO, how to handle districts that span states?
                return self.geocode(zipcode)
        else:
            return self.geocode(zipcode)

    def geocode(self, address):
        results = self.client.geocode(address).get('results')
        if not results:
            return None
        else:
            return Location(results[0])

    def reverse(self, latlon):
        results = self.client.reverse(latlon).get('results')
        if not results:
            return None
        else:
            return Location(results[0])
print(f"{geocoded_addresses.coords}")
print(f"{geocoded_addresses[0].coords}")
print(f'{geocoded_addresses[1].coords}')

# get co-ordinates
cord = geocoded_addresses.get('2 15th St NW, Washington, DC 20024').coords
print(f'{cord}')

#parsing address
par = client.parse('1600 Pennsylvania Ave, Washington DC')
print(f'{par}')

#Find matching address

location = client.reverse((56.58, -15.40))
addre =  location.formatted_address
print(f'{addre}')

#Find multiple address
locations = client.reverse([
        (33.738987, -116.4083),
        (-33.738987, -1.511),
        (38.890083, -76.983822)
    ])
loca_multi = locations.formatted_addresses
print(f'{loca_multi}')

#Specific address from the tuple
speci_loc = locations.get("38.890083,-76.983822").formatted_address
print(f'{speci_loc}')
from geocodio import GeocodioClient

client = GeocodioClient("09f66ff507f2e50f5ee026f5254550727e46504")

output = client.reverse([(32.810355, -117.142829), (33.480838, -86.907183), (33.513202, -86.801166), (33.632882, -117.732152), (33.69279, -117.766254), (33.719281, -116.218805), (33.765394, -117.851618), (33.777466, -118.188487), (33.787966, -117.873633), (33.864429, -118.053932), (33.953355, -117.396162), (34.056488, -118.273743), (34.058731, -118.444143), (34.108345, -117.289765), (34.142346, -118.248367), (34.168339, -118.60592), (34.424497, -119.705378), (34.424497, -119.705378), (34.469994, -118.196742), (35.282753, -120.659616), (35.622506, -117.669941), (36.105194, -86.762784), (36.625809, -121.817036), (36.739442, -119.784831), (36.825228, -119.702919), (37.453827, -122.182187), (37.469569, -121.93685), (37.639097, -120.996878), (37.947979, -122.060796), (37.957702, -121.29078), (38.440468, -122.714431), (38.572398, -121.464128), (39.728495, -121.837478), (38.6056815, -121.5142751), (34.0621882, -118.2900329), (34.0613735, -118.3033932), (33.6975535, -117.9163724), (37.3309703, -121.887089), (32.7633355, -117.0222967), (34.4353926, -119.8107478), (34.26706, -119.2154704), (37.8077556, -122.411767), (42.65717, -71.140878), (35.96517, -83.922268), (36.134657, -86.792156), (33.6796268, -117.7443642), (41.594268, -70.979442), (43.615046, -116.204443), (21.304547, -157.855676), (25.690552, -80.235009), (25.942075, -80.239753), (26.075729, -80.284109), (26.142036, -81.79481), (27.746197, -82.712723), (28.553474, -81.323161), (29.4246, -98.49514), (29.651907, -82.324798), (29.724583, -95.36261), (29.727317, -95.338293), (29.753499, -95.364975), (29.937075, -90.128452), (29.937519, -90.118619), (30.271129, -97.743699), (30.332184, -81.655651), (30.438083, -84.280933), (31.549333, -97.146669), (32.083541, -81.099834), (32.221742, -110.926476), (32.366966, -86.300648), (32.410438, -90.162065), (32.710136, -117.154193), (32.721739, -117.162491), (32.753177, -97.332746), (32.776272, -96.796856), (32.787601, -79.940273), (32.840695, -83.632402), (33.26684, -87.486218), (33.414631, -111.909376), (33.446768, -112.075672), (33.577863, -101.855166), (33.646868, -117.835225), (33.663339, -117.903317), (33.756673, -84.38721), (33.793214, -116.502356), (33.793384, -117.852938), (33.793676, -84.388835), (33.795478, -84.321354), (33.870822, -117.929416), (33.959597, -83.376678), (34.000749, -81.034331), (34.018069, -118.284902), (34.049114, -118.270388), (34.060324, -118.289186), (34.074207, -118.438629), (34.366413, -89.518766), (34.746481, -92.289595), (35.084103, -106.650985), (35.149022, -90.051628), (35.222572, -97.439482), (35.227087, -80.843127), (35.472989, -97.517054), (35.780402, -78.639078), (35.9132, -79.055844), (35.957701, -83.929505), (35.972194, -78.897669), (35.995462, -78.946847), (36.062584, -94.157433), (36.072636, -79.791975), (36.099817, -80.244144), (36.155681, -95.992911), (36.166286, -115.149225), (36.718371, -76.24668), (37.270703, -76.70745), (37.277889, -82.099022), (37.354113, -121.955174), (37.40088, -79.184492), (37.426565, -122.170188), (37.538509, -77.43428), (37.727469, -89.216655), (37.776569, -122.453889), (37.781304, -122.415821), (37.784021, -79.442816), (37.78916, -122.398485), (37.870839, -122.272864), (38.046407, -84.497039), (38.052048, -78.509474), (38.053275, -78.509263), (38.254238, -85.759407), (38.545379, -121.744583), (38.549274, -121.472949), (38.637332, -90.194652), (38.647128, -90.302661), (38.839894, -83.50517), (38.890396, -77.084158), (38.897833, -77.012599), (38.899384, -77.045247), (38.942721, -77.059603), (38.945867, -77.079738), (38.946225, -77.065201), (38.951883, -92.333737), (38.971938, -95.23595), (39.03309, -84.452151), (39.049011, -95.677556), (39.084469, -94.56303), (39.101454, -84.51246), (39.16704, -86.534288), (39.289773, -76.622697), (39.305835, -76.615886), (39.629526, -79.955897), (39.739154, -104.984703), (39.745947, -75.546589), (39.758948, -84.191607), (39.768333, -86.15835), (25.7567687, -80.3801018), (36.1481438, -86.8022651), (40.7479289, -73.9461615), (30.5233151, -91.1984904), (28.5448058, -81.385435), (38.936097, -76.9989966), (41.878985, -87.6442927), (32.7716655, -117.1910477), (33.4629377, -86.7928276), (40.7239575, -73.7947677), (41.8963359, -87.619839), (30.4142766, -91.1771987), (39.944844, -75.119869), (39.953908, -75.193999), (39.962801, -75.247146), (39.963774, -82.987073), (39.979049, -75.157731), (39.996877, -83.00835), (40.014986, -105.270546), (40.0463, -75.359549), (40.111717, -88.207301), (40.201824, -77.189389), (40.233844, -111.658534), (40.266311, -76.886112), (40.43699, -79.993022), (40.44429, -79.949289), (40.691944, -73.989722), (40.706213, -73.61874), (40.725336, -73.996813), (40.730164, -73.999039), (40.734715, -73.994132), (40.737276, -74.169906), (40.740526, -74.17319), (40.767013, -111.890431), (40.771639, -73.984889), (40.790654, -73.201781), (40.800055, -96.6674), (40.806753, -73.960483), (41.033986, -73.76291), (41.083064, -81.518485), (41.258732, -95.937873), (41.308214, -72.925052), (41.311367, -105.591101), (41.395929, -72.896872), (41.473095, -87.061141), (41.501406, -81.678641), (41.51129, -81.608971), (41.591064, -93.603715), (41.661256, -91.529911), (41.677046, -71.26616), (41.678675, -83.512728), (41.6992, -86.237369), (41.765558, -72.690613), (41.785416, -87.598579), (41.877771, -87.628449), (41.878028, -87.626389), (41.897001, -87.627097), (41.929474, -88.750365), (42.112412, -72.546714), (42.268157, -83.731229), (42.330417, -83.038858), (42.337041, -71.209221), (42.339216, -71.091252), (42.350471, -71.108859), (42.351008, -71.06618), (42.356701, -71.061058), (42.359519, -83.073405), (42.377274, -71.130574), (42.439604, -76.496802), (42.651167, -73.754968), (42.733771, -84.55538), (42.735542, -84.485247), (42.779442, -96.92921), (42.886447, -78.878369), (43.034993, -87.922497), (43.048122, -76.147424), (43.074761, -89.383761), (43.207106, -71.537022), (43.661028, -70.25486), (43.815901, -72.545654), (44.101181, -123.152384), (44.939157, -123.033121), (44.941469, -93.137157), (44.973082, -93.244271), (44.974496, -93.276338), (45.520247, -122.674195), (46.732388, -117.000165), (46.87008, -113.99528), (47.608974, -122.315838), (47.65886, -117.424713), (47.660505, -122.309742), (47.907824, -97.059203)])

f = open('workfile', 'w')

f.write(output)
Ejemplo n.º 4
0
from geocodio import GeocodioClient
import os
from dotenv import load_dotenv
load_dotenv()
GEOCODIO_API_KEY = os.getenv("GEOCODIO_API_KEY")
client = GeocodioClient(GEOCODIO_API_KEY)

geocoded_addresses = client.geocode(["2405 Legislative Drive, Regina, SK"])
# print(geocoded_addresses)
print(geocoded_addresses.coords)

print(geocoded_addresses[0].coords)

locations = client.reverse([(45.61625, -61.630912), (43.685815, -79.759934)])
print(locations.formatted_addresses)