首页 > 解决方案 > 使用 Shapely 从四个经纬度角创建多边形

问题描述

我正在尝试使用来自臭氧监测仪器 (OMI) 的数据文件,并将来自该来源的数据与监测类似数据的地表仪器进行比较。

最终,我想找出是否在特定的多边形内。不过,要做到这一点,我需要创建我想象的多边形。

我有以下变量

latmat

latmat[1] = array([-62.2546, -62.371 , -62.4871, -62.6032], dtype=float32)
latmat[2] = array([-62.7195, -62.8356, -62.9519, -63.0676], dtype=float32)

lonmat

lonmat[1] = array([135.579, 135.606, 135.633, 135.66 ], dtype=float32)
lonmat[2] = array([135.688, 135.717, 135.745, 135.774], dtype=float32)

当然,latmat 和 lonmat 都比两个索引大得多,但我试图保持这些简单。这些值分别代表一个四角卫星像素的纬度和经度点。

最重要的是,我还有表格中的数据

data[1] = 1E+15
data[2] = 3E+15

我如何使用 geopandas 创建一个地理数据框,将 4 个纬度/经度点的每个组合识别为一个多边形?

标签: pythonpandasgeopandasshapely

解决方案


您需要为此使用zip()

from shapely.geometry import Polygon    
import numpy as np

latmat1 = np.array([-62.2546, -62.371 , -62.4871, -62.6032], dtype=np.float32)
latmat2 = np.array([-62.7195, -62.8356, -62.9519, -63.0676], dtype=np.float32)
lonmat1 = np.array([135.579, 135.606, 135.633, 135.66 ], dtype=np.float32)
lonmat2 = np.array([135.688, 135.717, 135.745, 135.774], dtype=np.float32)

pol1 = Polygon([(i,j) for i,j in zip(lonmat1, latmat1 ) ])
pol2 = Polygon([(i,j) for i,j in zip(lonmat2, latmat2 ) ])

推荐阅读