python - 在地理上将一个国家划分为等距的点(Python)
问题描述
我正在尝试将巴拿马地图拆分为等距的纬度、经度坐标,并使用 numpy 创建将它们分开的 linspace,基于底部左、右下、左上和右上的纬度。为此,我使用了嵌套的 for 循环。
问题是,尽管在最终字典中获得了正确数量的唯一纬度,但我只得到了一个唯一经度。你能帮我纠正循环中的错误,以便输入最终数据帧的最终字典给出 646 以响应
grid_centroid.long.nunique()
非常感谢!
import pandas as pd
import numpy as np
bottomLeft = (7.239013, -82.94546842973114)
bottomRight = (7.239013, -77.177479)
topLeft = (9.62079503922844, -82.94546842973114)
topRight = (9.62079503922844, -77.177479)
df = pd.read_csv('sites_unique.csv')
cols = np.linspace(bottomLeft[1], bottomRight[1], num=276)
rows = np.linspace(bottomLeft[0], topLeft[0], num=646)
df['col'] = np.searchsorted(cols, df['Average of lat'], 'right')
df['row'] = np.searchsorted(rows, df['Average of long'], 'right')
grid_dict = {'lat':[],'long':[]}
for l in range(275):
lat_index_init = l
for i in range(645):
lon_init_index = i
grid_dict['lat'].append(rows[lat_index_init])
grid_dict['long'].append(cols[lon_index_init])
i + 1
l + 1
i = 0
grid_centroid = pd.DataFrame(grid_dict)
解决方案
快速修复,想通了,它实际上非常简单
bottomLeft = (7.239013, -82.94546842973114)
bottomRight = (7.239013, -77.177479)
topLeft = (9.62079503922844, -82.94546842973114)
topRight = (9.62079503922844, -77.177479)
cols = np.linspace(bottomLeft[1], bottomRight[1], num=646)
rows = np.linspace(bottomLeft[0], topLeft[0], num=275)
grid_dict = {'lat':[],'long':[]}
for l in range(275):
lat_index_init = l
for i in range(645):
grid_dict['lat'].append(rows[l])
grid_dict['long'].append(cols[i])
i + 1
l + 1
i = 0
产生期望的结果。我希望这可以帮助其他努力创建地理空间网格的人
一切顺利
推荐阅读
- node.js - 为什么 app.engine 不默认 layout.hbs 作为默认值
- c# - 从两个列表返回不同项目列表的动态 LINQ 方法
- c++ - 无法在 box2d 碰撞回调中获取类数据
- database - PostgreSQL 查询将列更改为大写
- javascript - 头部的 Java 脚本函数导致正文中未定义 ReferenceError
- javascript - 如何避免浏览器中的闪烁问题?
- swift4 - WatchOS5 - WCSessionFileTransfer 的“无法加载文件传输结果”
- c# - 如何按列格式化数据表行数据
- jenkins - 如何从詹金斯管道触发工作中的任务
- c++ - 在 OpenGL 3.3 上使用 texture2D