Hot answers tagged

12 votes
Accepted

Shapely Distance different from Geopy/Haversine

Because the principles and the algorithms are different (look at Geographical distance) Shapely use the euclidean distance in a cartesian plane and the shortest distance between two points in a plane ...
  • 53.4k
11 votes
Accepted

Avoid time out error Nominatim Geopy OpenStreetMap

You could make a recursive function. Just typing Python-esque pseudo-code: from geopy.exc import GeocoderTimedOut def do_geocode(address, attempt=1, max_attempts=5): try: return geopy....
11 votes
Accepted

User_Agent argument in Nominatim in GeoPy

User_Agent is an http request header that is sent with each request. Nominatim requires this value to be set to your application name. The goal is to be able to limit the number of requests per ...
  • 37.8k
10 votes
Accepted

Bulk reverse geocoding with Geopy using built-in rate_limiter

The correct usage of RateLimiter for reverse geocoding would be: from geopy.geocoders import Nominatim from geopy.extra.rate_limiter import RateLimiter geolocator = Nominatim(user_agent="application"...
7 votes
Accepted

inaccurate distance measurements in Python

If you inverse the coordinates, it does not work (geopy uses (latitude,longitude) in the WGS84 crs) dublin = (53.33306,-6.24889) liverpool = ( 53.41058,-2.97794) print distance(dublin, liverpool)....
  • 53.4k
7 votes
Accepted

Difference in destination location between pyproj and geopy

It looks like you've done everything correctly. You can evaluate the errors from each method by performing the inverse calculations to find the distance given the origin and destination coordinates, ...
  • 41.1k
5 votes

Difference between Vincenty and great-circle distance calculations?

My apologies for posting a second answer here, but I taking the opportunity to respond to the request by @craig-hicks to provide accuracy and timing comparisons for various algorithms for computing ...
  • 3,176
5 votes
Accepted

Get lat-long of US cities and plot them on a map using matplotlib and basemap

I was able to use the API to put together the program I wanted. Here it is: # Draw the locations of cities on a map of the US import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemap ...
  • 269
5 votes

Plot a circle with a given radius around points on map using Python

What you want: Create a circle from the center of each marker This can be easily solved with geopandas buffer functions. You can see the description here. #make circle from point new_df = geo_df.copy()...
  • 608
5 votes
Accepted

Python function to get the co-ordinate pair of a point

The geolocator.reverse() method is expecting a Point obejct or a tuple with two coordinates. However, you are passing redshape, which is a fiona.collection.Collection object with all the features in ...
4 votes
Accepted

Get state but want country in GeoPy and Nominatim

When you try embedding exactly_one=False parameter (by default it is True) into your code, like from geopy.geocoders import Nominatim geolocator = Nominatim(user_agent='anonymous@gmail.com', timeout=...
  • 27.9k
4 votes
Accepted

Having difficulty retrieving city and area names using Geopy (Google V3)

Be careful with your variable names. You're dangerously re-defining the variable c within your list comprehensions. Do this instead: counties = [x['long_name'] for x in c if 'neighborhood' in x['...
4 votes

What kind of margin of error can I expect in figuring distance?

Pre-Answers The word accuracy carries different meanings in Survey Engineering and in GIS even though both are related. In the former, it is explained here. In the latter, it was discussed here. ...
  • 1,652
3 votes
Accepted

Extracting GPS points inside the region boundary

Use within: Returns a Series of dtype('bool') with value True for each geometry that is within other. from shapely import geometry import geopandas as gpd import pandas as pd file = r'C:\folder\...
  • 60.7k
3 votes
Accepted

differences in distance between shapely and geopy

1) For calculate the Vincenty distance, you need coordinates in longitude, latitude (degrees) and you choose WGS84 (look at with Geopy:distance) 2) The coordinates of your points are in meters: u'...
  • 53.4k
3 votes

Difference in destination location between pyproj and geopy

The geopy pull request fixes your issue with geopy. You will need to install the python package geographiclib first with pip install geographiclib
  • 3,176
3 votes

Shapely Distance different from Geopy/Haversine

And here's another distance calculation from GeographicLib: from geographiclib.geodesic import Geodesic g = Geodesic.WGS84.Inverse(39.435307, -76.799614, 39.43604, -76.79989) print(g['s12']) # 84....
  • 41.1k
3 votes

Reverse geocoding of Pandas DataFrame with Lat/Long columns

A solution: from geopy.geocoders import Nominatim locator = Nominatim(user_agent="myGeocoder") print(test) id Latitude Longitude 0 1 30.197535 -97.662015 1 2 34.895699 -82....
  • 53.4k
3 votes
Accepted

Reverse geocoding of Pandas DataFrame with Lat/Long columns

Here the Nominatim geocoder (free to choose) from the GeoPy geocoding Python library was used, for more details, please check the documentation. Coordinates of point features should be passed as a ...
  • 27.9k
3 votes

ValueError: Columns must be same length as key

pandas is expecting two values (columns) to be returned as you specified two keys ['Latitude', 'Longitude']. However, when there's an exception, e.g. no geocoding result, you only return a single ...
  • 58.4k
2 votes

Difference between Vincenty and great-circle distance calculations?

Whether using vincenty or haversine or the spherical law of cosines, there is wisdom in becoming aware of any potential issues with the code you are planning to use, things to watch out for and ...
2 votes

Difference between Vincenty and great-circle distance calculations?

It appears that the geopy.distance package offers a function "distance()" which defaults to vincenty(). I would recommend using distance() on principle, as it is the package recommendation, in case ...
2 votes

Get lat-long of US cities and plot them on a map using matplotlib and basemap

With Python, you could use the geopy module: >>> from geopy.geocoders import Nominatim >>> geolocator = Nominatim() >>> loc = geolocator.geocode("New York, NY") >>>...
  • 12.7k
2 votes
Accepted

When calcuating distance between points on Earth why are my Haversine vs. Geodesic calculations wildy diverging?

I appreciate your code because it contributes to geodesy, by allowing to make some interesting analyzes in a practical way, regarding spherical approximations for the calculation of length of geodesic ...
2 votes

When calcuating distance between points on Earth why are my Haversine vs. Geodesic calculations wildy diverging?

There was a matrix algebra error in the Haversine formula. I updated the code in the question. I am getting much better agreement between Haversine and geodesic now: On my actual dataset:
  • 193
2 votes
Accepted

Getting output in different language in GeoPy

As per the doc, you can specify the language as a str type in the parameters of the reverse() method. By default it is language=False, that matches the language of the country for which the geocoder ...
  • 37.8k
2 votes

Making ellipse geometry from some known parameters using PostGIS?

I would go with CIRCULARSTRING. You already know the coordinates of start point and end point, and the coordinates for the peak radius can be easily calculated. Thus, the half of your desired ...
2 votes
Accepted

Python: Trying to figure out Geopy in python for reverse look ups

Don't use an external command to set your proxy. If you are on Windows and your proxy is already setup in your internet options, you don't need to set it up in the script at all, it will be ...
  • 58.4k
2 votes
Accepted

Getting list of result from GeoPy Nominatim

Look at the Taras's answer in Get state but want country in GeoPy and Nominatim: When you try embedding exactly_one=False parameter (by default it is True) into your code And in geopy.geocoders....
  • 53.4k
2 votes

How do I get zipcodes from longitude and latitude on python?

You are passing in the latitude and longitude Series instead of the latitude and longitude column names. import geopy import pandas as pd def get_zipcode(df, geolocator, lat_field, lon_field): ...
  • 58.4k

Only top scored, non community-wiki answers of a minimum length are eligible