簡體   English   中英

嘗試使用python生成常規地理網格-緯度/經度超出限制

[英]Attempting to generate a regular geographic grid using python - lat/lng exceeds limits

我想檢索全美國常規網格的所有緯度/經度坐標對。 我從先前的堆疊問題中獲取了以下代碼:

import shapely.geometry
import pyproj

# https://stackoverflow.com/questions/40342355/how-can-i-generate-a-regular-geographic-grid-using-python
# Set up projections
p_ll = pyproj.Proj(init='epsg:4326') #4326
p_mt = pyproj.Proj(init='epsg:3857') # espg:3857 metric; same as EPSG:900913

# Create corners of rectangle to be transformed to a grid
nw = shapely.geometry.Point((24.0,-89))  #actually SW
print(nw)
se = shapely.geometry.Point((25.0,-65)) #actually NE

# 24.0,-89
# 50.0,-65

stepsize = 50000 # 5 km grid step size

# Project corners to target projection
s = pyproj.transform(p_ll, p_mt, nw.x, nw.y) # Transform NW point to 3857
e = pyproj.transform(p_ll, p_mt, se.x, se.y) # .. same for SE
print(s)
print(e)
# Iterate over 2D area
gridpoints = []
x = s[0]
while x < e[0]:
    y = s[1]
    while y < e[1]:
        p = shapely.geometry.Point(pyproj.transform(p_mt, p_ll, x, y))
        gridpoints.append(p)
        y += stepsize
    x += stepsize

# with open('testout.csv', 'wb') as of:
#     of.write('lon;lat\n')
for p in gridpoints:
    print(str(p.x)+"," +str(p.y))
    # of.write('{:f};{:f}\n'.format(p.x, p.y))

資料來源: 如何使用python生成常規的地理網格?

當我的經度超過-89.9999(-90到-180)時,該代碼將不起作用,這將導致以下錯誤:

MacBook-Pro:Desktop user$ python updated_calculate_points.py 
Traceback (most recent call last):
  File "updated_calculate_points.py", line 19, in <module>
    s = pyproj.transform(p_ll, p_mt, nw.x, nw.y) # Transform NW point to 3857
  File "/Users/user/anaconda3/lib/python3.6/site-packages/pyproj/__init__.py", line 504, in transform
    _proj._transform(p1,p2,inx,iny,inz,radians)
  File "_proj.pyx", line 361, in _proj._transform (_proj.c:3762)
RuntimeError: b'latitude or longitude exceeded limits'

我不完全理解這些預測是如何工作的。 有人可以協助嗎?

h3庫與已定義的geos結合使用(例如,從Openstreetmap中提取)是一種不錯的解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM