从左下角坐标创建一个方形多边形

问题描述

我确实有坐标(纬度、经度),我需要创建 100 米的多边形。 现在我只能创建一个多边形(正方形),其中点是它的中心而不是左下角。

import geopandas as gpd
from shapely.geometry import Point


# Generate some sample data 
p1 = Point((-122.431297,37.773972))
points = gpd.GeoSeries([p1])

# Buffer the points using a square cap style
# Note cap_style: round = 1,flat = 2,square = 3
buffer = points.buffer(1,cap_style = 3)

解决方法

使用 geopy 生成/构建剩余的点。

import geopy
import geopy.distance as distance
from shapely.geometry import Polygon

#Assume each site is 100m (question not clear)
d = distance.distance(kilometers=100/1000)

# Going clockwise,from lower-left to upper-left,upper-right...
p1 = geopy.Point(( 37.773972,-122.431297))
p2 = d.destination(point=p1,bearing=0)
p3 = d.destination(point=p2,bearing=90)
p4 = d.destination(point=p3,bearing=180)

points = [(p.latitude,p.longitude) for p in [p1,p2,p3,p4]]
polygon = Polygon(points)