示例#1
0
    def __photon(self):
        try:
            from geopy.geocoders import Photon
            geolocator = Photon(timeout=15)
            location = geolocator.reverse(str(self.location["latitude"]) + "," +
                                          str(self.location["longitude"]), exactly_one=True)

            if not self.location.get("country", None) and "country" in location.raw["properties"]:
                self.location["country"] = location.raw["properties"]["country"]
            if not self.location.get("region", None) and "state" in location.raw["properties"]:
                self.location["region"] = location.raw["properties"]["state"]

            if not self.location.get("town", None) and "city" in location.raw["properties"]:
                self.location["town"] = location.raw["properties"]["city"]
        except:
            pass
def geo_extraction(latitude, longitude):
    # 通过经纬度解析地址
    try:
        geolocator = Photon(user_agent="my-application")
        position = geolocator.reverse(str(latitude) + ',' + str(longitude),
                                      limit=1)
        addr = position.address.split(',')
        result = []
        for attribute in addr:
            # 剔除address非中文部分,大概能精确到市
            if attribute.strip(' ').encode('UTF-8').isalpha():
                result.append(attribute)
    except Exception as err:
        result = []
        print(err)
    return result
示例#3
0
    def __photon(self):
        try:
            from geopy.geocoders import Photon
            geolocator = Photon(timeout=15)
            location = geolocator.reverse(str(self.location["latitude"]) +
                                          "," +
                                          str(self.location["longitude"]),
                                          exactly_one=True)

            if not self.location.get(
                    "country",
                    None) and "country" in location.raw["properties"]:
                self.location["country"] = location.raw["properties"][
                    "country"]
            if not self.location.get(
                    "region", None) and "state" in location.raw["properties"]:
                self.location["region"] = location.raw["properties"]["state"]

            if not self.location.get(
                    "town", None) and "city" in location.raw["properties"]:
                self.location["town"] = location.raw["properties"]["city"]
        except:
            pass
from geopy.geocoders import Photon
from geopy.point import Point
import csv

coords_by_state = {'ME': [],'VT': [],'NH': [],'NY': [],'MA': [],'CT': [],'RI': [],'PA': [],'NJ': [],'ND':[],'MN': [],'SD': [],'NE': [],'IA': [],'KS': [],'MO': [],'IL': [],'WI': [],'MI': [],'OH': [],'IN': [],'WA': [],'MT': [],'OR': [],'ID': [],'WY': [],'CA': [],'NV': [],'UT': [],'CO': [],'AZ': [],'NM': [],'OK': [],'TX': [],'AR': [],'LA': [],'KY': [],'TN': [],'MS': [],'AL': [],'WV': [],'VA': [],'MD': [],'DE': [],'NC': [],'SC': [],'GA': [],'FL': [],'AK': [],'HI':[] }


        geolocator = Photon()with open('latlong.csv') as csvfile:
    reader = csv.reader(csvfile,delimiter=',')
    for row in reader:
        print(row)

        print(geolocator)
#        p = 
        result = geolocator.reverse(', '.join(row))
        print(result)
        break;
        
#photon.komoot.de/reverse?lon=47.5279679v&lat=-122.1976519
示例#5
0
def calcDistanceView(request):
    distance = None
    destination = None
    form = MeasurementForm(request.POST or None)
    geolocator = Photon(user_agent="measurements")

    # Location Coordinates
    g = geocoder.ip('me')
    lat = g.latlng[0]
    lon = g.latlng[1]
    location = geolocator.reverse(f"{lat}, {lon}")
    pointA = [lat, lon]

    # Initial Folium Map
    m = folium.Map(width='100%',
                   height='100%',
                   location=get_center_coordinates(lat, lon))
    # Location Marker
    folium.Marker([lat, lon],
                  tooltip='Click here for more',
                  popup=location,
                  icon=folium.Icon(color='blue', icon='home')).add_to(m)

    if form.is_valid():
        instance = form.save(commit=False)

        # destination coordinates
        destination_ = form.cleaned_data.get('destination')
        destination = geolocator.geocode(destination_)
        d_lat = destination.latitude
        d_lon = destination.longitude
        pointB = (d_lat, d_lon)

        # calc distance
        distance = round(geodesic(pointA, pointB).km, 2)  # calc the distance

        # Destination Marker
        m = folium.Map(width='100%',
                       height='100%',
                       location=get_center_coordinates(lat, lon, d_lat, d_lon),
                       zoom_start=get_zoom(distance))
        # Location Marker
        folium.Marker([lat, lon],
                      tooltip='Click here for more',
                      popup=get_center_coordinates(lat, lon),
                      icon=folium.Icon(color='blue', icon='home')).add_to(m)
        folium.Marker([d_lat, d_lon],
                      tooltip='Click here for more',
                      popup=destination,
                      icon=folium.Icon(color='red', icon='cloud')).add_to(m)

        # Draw a line between location and destination
        line = folium.PolyLine(locations=[pointA, pointB],
                               weight=3,
                               color='blue')
        m.add_child(line)  # Append the Line to the Map

        # Location
        instance.location = location
        # Distance
        instance.distance = distance
        instance.save()
    # Map Representation
    m = m._repr_html_()
    context = {
        'distance': distance,
        'destination': destination,
        'form': form,
        'map': m,
    }
    return render(request, 'measurements/main.html', context)
                            if key == 'Model':
                                model = exif[key].__str__()
                                #print 'model',model
            except IOError:
                print 'can not open and get exif'

            # locate the address from coordinates
            country = ''
            state = ''
            city = ''
            address = ''
            event_id = -1
            if lat != -999 and lon != -999:
                geolocator = Photon()
                #print str(lat)+','+str(lon)
                location = geolocator.reverse(str(lat)+','+str(lon))
                if location != None:
                    address = location.address.encode("utf-8")
                    for key in location.raw['properties']:
                        if key == 'country':
                            country = location.raw['properties'][key].encode(
                                "utf-8")
                        if key == 'state':
                            state = location.raw['properties'][key].encode(
                                "utf-8")
                        if key == 'city':
                            city = location.raw['properties'][key].encode(
                                "utf-8")

            # write image data into csv
            imagedata = json.loads(req.content)['res']