python - 我有一个有 4 个角的多边形,而不是正方形。如何在 python 中获取它的较小部分的纬度和经度?

标签 python gis

我有一个有 4 个角的多边形,一个 GIS 投影。它不是一个精确的正方形。我如何获得它的较小部分的纬度和经度。网格将被分解成更小的正方形(每个 500x500 米,由此产生的 2d 分布的尺寸为 1728x1984)。我需要每个正方形一个角的纬度和经度。我正在查看 np.mgrid 或 np.meshgrid,但它们似乎无法获得我的输入。我有 4 个点,每个点有 2 个值。

LL_lat = 52.29427206432812
LL_lon = 4.379082700525593
LR_lat = 52.29427206432812
LR_lon = 18.893280870398133
UL_lat = 60.0
UL_lon = 3.0
UR_lat = 59.827708427801085
UR_lon = 20.735140174892805 

所以我认为我需要将二维数组分成更小的间隔。我怎样才能做到这一点。间隔是固定的spacing。

右边的多边形是我的那个。我想要一种方法来为每个立方体找到左下角的纬度和经度(它们的大小都相同)。 1

最佳答案

所以如果你们都好奇的话,我的老板帮我弄清楚了:)

我们正在从 DMI 转换丹麦天气数据 GIS 网格

from pyproj import Proj, transform
import h5py

projection = ""
tmpfile = "file_path"
with h5py.File(tmpfile_in, 'r') as h5file:
    projection = h5file['where'].attrs['projdef'].decode('utf-8')

#projection = '+proj=stere+ellps=WGS84+lat_0=56+lon_0=10.5666+lat_ts=56' 
dmi_proj = Proj(projparams=projection)  # DMI input, custom stereographic projection
wgs_proj = Proj(init='EPSG:4326')  # WGS84

###Lat and lon in corners are known from file
LL_lat = 52.29427206432812
LL_lon = 4.379082700525593

###Get start projections as wgs projections instead of lat and lon (for the `calculation)`
x0, y0 = pyproj.transform(wgs_proj, dmi_proj, LL_lon, LL_lat)
print(x0, y0)
xscale = 500.0 
yscale = 500.0

latitude = []
longitude = []
###Whether or not the j and k orders need to be decending 
### will figure out, but `thats more based on the set up of your datafile.` 
for j in range(0, (1984 -1)):
    print(j)
    for k in range(0, (1728 -1)):
        east = x0 + j*xscale
        north = y0 + k*yscale
        ### convert back to lat and lon
        lon, lat = pyproj.transform(dmi_proj, wgs_proj, east, north)
        longitude.append(lon)
        latitude.append(lat)

print(longitude)
print(latitude)

关于python - 我有一个有 4 个角的多边形,而不是正方形。如何在 python 中获取它的较小部分的纬度和经度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58856414/

相关文章:

python - 将图像添加到 Tkinter Entry

python - 在 "pip3 install cython"之后在 Ubuntu 22.04 上找不到 cythonize

python - 从数据帧中的当前索引反向搜索

php - 在mysql中查询显示纬度经度多边形

c# - 将两个 C# DbGeography 多边形连接成一个多边形

python - 如何获取django中最畅销的10个产品?

python - 鸭子类型(duck typing) : how to avoid name collisions?

javascript - 在传单 map 中绘制之前将 GeoJSON 多边形转换为点

r - ggplot2:组合来自两个不同地理数据集的形状文件

java - GeoTools WebMapServer GetMapRequest 问题