gpt4 book ai didi

dictionary - 如何从中心点计算矩形的纬度和经度

转载 作者:行者123 更新时间:2023-12-02 02:19:38 25 4
gpt4 key购买 nike

我想根据中心点纬度和经度绘制一个矩形,假设给定长度和宽度,分别为 4.5m 和 1.5m。我想,我们也需要轴承。我通过在 Google Earth 上绘制一个矩形、获取位置并将其放入我的代码中进行了模拟。但是,我需要一些自动的东西。我的问题是如何将笛卡尔坐标链接到以米为单位的这四个点(矩形)。

这是我的代码:

import geopandas as gpd
from shapely.geometry import Polygon

lat_point_list = [41.404928, 41.404936, 41.404951, 41.404943]
lon_point_list = [2.177339, 2.177331, 2.177353, 2.177365]

polygon_geom = Polygon(zip(lon_point_list, lat_point_list))
import folium
m = folium.Map([41.4049364, 2.1773560], zoom_start=20)
folium.GeoJson(polygon_geom).add_to(m)
folium.LatLngPopup().add_to(m)
m

我想要这个:

enter image description here

更新:

我知道这是基本的三角学。如果我将矩形分成三角形,我们可以找到不同的点。我知道这是简单练习的基础,但是,我不知道使用笛卡尔坐标时它会发生变化。然后,我的目标是得到点 A、B、C 和 D,并知道矩形中心的经纬度、长度和宽度。

enter image description here

最佳答案

获取点的矩形(NE、SW)边界,并将其用作 folium.Rectangle 的边界。

例如,使用您的数据。 4.5m和1.5m看矩形有点小:

import geopy
import geopy.distance
import math
import folium

def get_rectangle_bounds(coordinates, width, length):
start = geopy.Point(coordinates)
hypotenuse = math.hypot(width/1000, length/1000)

# Edit used wrong formula to convert radians to degrees, use math builtin function
northeast_angle = 0 - math.degrees(math.atan(width/length))
southwest_angle = 180 - math.degrees(math.atan(width/length))

d = geopy.distance.distance(kilometers=hypotenuse/2)
northeast = d.destination(point=start, bearing=northeast_angle)
southwest = d.destination(point=start, bearing=southwest_angle)
bounds = []
for point in [northeast, southwest]:
coords = (point.latitude, point.longitude)
bounds.append(coords)

return bounds

# To get a rotated rectangle at a bearing, you need to get the points of the the recatangle at that bearing
def get_rotated_points(coordinates, bearing, width, length):
start = geopy.Point(coordinates)
width = width/1000
length = length/1000
rectlength = geopy.distance.distance(kilometers=length)
rectwidth = geopy.distance.distance(kilometers=width)
halfwidth = geopy.distance.distance(kilometers=width/2)
halflength = geopy.distance.distance(kilometers=length/2)

pointAB = halflength.destination(point=start, bearing=bearing)
pointA = halfwidth.destination(point=pointAB, bearing=0-bearing)
pointB = rectwidth.destination(point=pointA, bearing=180-bearing)
pointC = rectlength.destination(point=pointB, bearing=bearing-180)
pointD = rectwidth.destination(point=pointC, bearing=0-bearing)

points = []
for point in [pointA, pointB, pointC, pointD]:
coords = (point.latitude, point.longitude)
points.append(coords)

return points

start_coords = [41.4049364, 2.1773560]
length = 4.50 #in meters
width = 1.50
bearing = 45 #degrees

m = folium.Map(start_coords, zoom_start=20)
bounds = get_rectangle_bounds(tuple(start_coords),width, length )
points = get_rotated_points(tuple(start_coords), bearing, width, length)

folium.Rectangle(bounds=bounds,
fill=True,
color='orange',
tooltip='this is Rectangle'
).add_to(m)

# To draw a rotated rectangle, use folium.Polygon
folium.Polygon(points).add_to(m)

关于dictionary - 如何从中心点计算矩形的纬度和经度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66619323/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com