geopy

Convert between coordinate systems with GeoDjango

拥有回忆 提交于 2019-12-05 15:22:43
I'm trying to add coordinate information to my database, adding django.contrib.gis support to my app. I'm writing a south data migration that takes the addresses from the database, and asks Google for the coordinates (so far I think my best bet is to use geopy for this). Next I need to convert the returned coordinates from WGS84:4326 , Google's coordinate system, to WGS84:22186 , my coordinate system. I'm lost among the GeoDjango docs trying to find a way to do this. This far, I gather I need to do this: gcoord = SpatialReference("4326") mycoord = SpatialReference("22186") trans =

Plotting a Map with geopy and matplotlib in Jupyter Notebook

我与影子孤独终老i 提交于 2019-12-05 08:08:19
问题 I am trying to plot a map of the US and mark the various cities across the country. I got the map to work. But I am having two issues: the first is, I am getting this error message: AttributeError: 'NoneType' object has no attribute 'longitude' Secondly, I have tried to enlarge the graph using the plt.figsize attribute however my map still stays the same size. Lastly, this is not really an issue but what if i wanted to label the dots with the city names How can i do so? Here is my code for

How can I generate a regular geographic grid using python?

旧巷老猫 提交于 2019-12-03 07:56:28
问题 I want to retrieve all lat/lon coordinate pairs of a regular grid over a certain map area. I have found the geopy library, but didn't manage at all to approach the problem. For example, I have a rectangular geographic area described by its four corners in lat/lon coordinates, I seek to calculate the grid with spacing of e.g. 1km covering this area. 回答1: Preliminary Considerations It makes a slight difference how your certain area is defined. If it's just a rectangular area (note: rectangular

HTTP Error 429: Too Many Requests by python geopy

若如初见. 提交于 2019-12-02 08:19:50
问题 I have a problem that I am not sure how to solve. I want to iterate through a file where I want to convert the coordinates to the geolocation address.The code works fine but after it iteretes through a certain number of lines in the file the problem occurs. from __future__ import print_function from geopy.geocoders import Nominatim from shapely.wkt import loads as load_wkt from shapely.geometry import Point, Polygon import io import re import ast import time geolocator = Nominatim() with io

HTTP Error 429: Too Many Requests by python geopy

人盡茶涼 提交于 2019-12-02 04:23:00
I have a problem that I am not sure how to solve. I want to iterate through a file where I want to convert the coordinates to the geolocation address.The code works fine but after it iteretes through a certain number of lines in the file the problem occurs. from __future__ import print_function from geopy.geocoders import Nominatim from shapely.wkt import loads as load_wkt from shapely.geometry import Point, Polygon import io import re import ast import time geolocator = Nominatim() with io.open('sample_test2.txt', encoding="utf-8") as f, io.open('sample_test3.txt', 'w',encoding="utf-8") as g:

Best way to pass repeated parameter to a Numpy vectorized function

落花浮王杯 提交于 2019-12-01 21:00:28
So, continuing from the discussion @TheBlackCat and I were having in this answer , I would like to know the best way to pass arguments to a Numpy vectorized function. The function in question is defined thus: vect_dist_funct = np.vectorize(lambda p1, p2: vincenty(p1, p2).meters) where, vincenty comes from the Geopy package . I currently call vect_dist_funct in this manner: def pointer(point, centroid, tree_idx): intersect = list(tree_idx.intersection(point)) if len(intersect) > 0: points = pd.Series([point]*len(intersect)).values polygons = centroid.loc[intersect].values dist = vect_dist_funct

error (429) Too Many Requests while geocoding with geopy in Python

梦想的初衷 提交于 2019-11-29 11:01:39
I have a Pandas dataframe with ~20k rows, and I am trying to geocode by address column into lat/long coordinates. How do I use time.sleep() or maybe other function to stop OSM Nominatim from Too Many Requests 429 error that I am getting now? Here's the code I use for this: from geopy.geocoders import Nominatim from geopy.distance import vincenty geolocator = Nominatim() df['coord'] = df['address'].apply(geolocator.geocode).apply(lambda x: (x.latitude, x.longitude)) df.head() Thanks in advance! geopy since 1.16.0 includes a RateLimiter class which provides a convenient way to deal with the Too

Geopy: catch timeout error

我与影子孤独终老i 提交于 2019-11-29 01:19:53
I am using geopy to geocode some addresses and I want to catch the timeout errors and print them out so I can do some quality control on the input. I am putting the geocode request in a try/catch but it's not working. Any ideas on what I need to do? Here is my code: try: location = geolocator.geocode(my_address) except ValueError as error_message: print("Error: geocode failed on input %s with message %s"%(a, error_message)) I get the following exception: File "/usr/local/lib/python2.7/site-packages/geopy/geocoders/base.py", line 158, in _call_geocoder raise GeocoderTimedOut('Service timed out'

new column with coordinates using geopy pandas

坚强是说给别人听的谎言 提交于 2019-11-28 20:33:48
问题 I have a df: import pandas as pd import numpy as np import datetime as DT import hmac from geopy.geocoders import Nominatim from geopy.distance import vincenty df city_name state_name county_name 0 WASHINGTON DC DIST OF COLUMBIA 1 WASHINGTON DC DIST OF COLUMBIA 2 WASHINGTON DC DIST OF COLUMBIA 3 WASHINGTON DC DIST OF COLUMBIA 4 WASHINGTON DC DIST OF COLUMBIA 5 WASHINGTON DC DIST OF COLUMBIA 6 WASHINGTON DC DIST OF COLUMBIA 7 WASHINGTON DC DIST OF COLUMBIA 8 WASHINGTON DC DIST OF COLUMBIA 9

Calculate point based on distance and direction

人走茶凉 提交于 2019-11-28 19:01:16
I would like to calculate a point based on direction and distance using GeoDjango or GeoPy. For example, If I have a point that is (-24680.1613, 6708860.65389) I would like to find out a point 1KM North, 1KM East, 1KM Sourh and 1KM west using Vincenty distance formula. I closest thing I can find is a "destination" function in distance.py ( https://code.google.com/p/geopy/source/browse/trunk/geopy/distance.py?r=105 ). Although I cannot find this documented anywhere and I'm yet to figure out how to use it. Any help is much appreciated. Jan-Philip Gehrcke Edit 2 Okay, there is an out-of-the-box