# How to Specify Haversine when using Buffer Method in Shapely and how to get Haversine distance between two Shapely Point objects?

I have a series of latitude/longitude pairs and I form Point() objects for each pair. I would like to form buffer regions around each point using a Haversine distance argument instead of Euclidean distance. That way, points on the boundary of the buffer are an equal Haversine distance away from the center of the buffer. Is there a way I can do this?

Also, is there a built-in method for getting the Haversine distance between two Shapely Point() objects? I know I can use the Haversine formula for the lat/long pairs, but I was wondering if there was anything built-in.

Instead of Haversine distance formula, you can use directly pyproj python module. For instance, for producing a 1000 m buffer (EPSG:32612) around this point (-112.171129818, 40.1731054115), EPSG:4326, next code does the job.

``````from shapely.geometry import Point, Polygon

import pyproj

srcProj = pyproj.Proj(init='EPSG:4326')
dstProj = pyproj.Proj(init='EPSG:32612')

pt = (-112.171129818, 40.1731054115)

x, y = pyproj.transform(srcProj, dstProj, pt, pt)

pt = Point(x,y)

buffer = pt.buffer(1000)

buffer_points =  zip(buffer.exterior.coords.xy, buffer.exterior.coords.xy)

proj_buffer_points = []

for point in buffer_points:
x = point
y = point
x, y = pyproj.transform(dstProj, srcProj, x, y)
proj_buffer_points.append((x, y))

print Polygon(proj_buffer_points)
``````

After running the code, at console is printed buffer (WKT format) in long/lat coordinates (EPSG:4326). With the help of QuickWKT plugin, it is visualized (EPSG:4326) at next image with QGIS. When 'on the fly' CRS transformation to EPSG:32612 is enabled, it can be observed circular buffer shape. • Thank you very much! I will have to install pyproj. What do the 4326 and 32612 codes refer to? 4326 refers to a coordinate system and 32612 refers to a 1000m buffer? What if I want a different sized buffer? Do these codes work for 1000m buffers about any point in the United States? Aug 15, 2017 at 19:25
• EPSG:32612 is for UTM/12N WGS84. In this case, you need to use a EPSG code compatible for your study area (meters or feet). If you want a different sized buffer only change 1000 (in my example it was in meters) for your value. Aug 15, 2017 at 19:40
• What if my study area was the entire lower 48 states of the US? Can I do this? Is it correct that I need EPSG:5070 for this? Aug 16, 2017 at 15:21
• I'm only interested in forming buffers around points in the United States using geodetic distance measured in meters. Would I use codes EPSG:5070 and what else? I'm sorry, I've never heard of any of this stuff before yesterday. Aug 16, 2017 at 15:42
• I'm only interested in forming buffers around points in the United States using geodetic distance measured in meters. Would I use codes EPSG:5070 and what else? I'm sorry, I've never heard of any of this stuff before yesterday. Aug 22, 2017 at 18:22