如何在给定边界上使用 geopandas 制作规则网格每个网格预计至少包含一个点

问题描述

enter image description here

上图显示了示例数据点和规则网格。如您所见,大多数网格都是空的。我只想要一个常规网格,其中每个网格至少包含一个数据点。有人可以支持我吗?非常感谢!

#下面是代码

import shapely
import geopandas
from geopandas import GeoDataFrame
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

df = pd.read_csv(r'D:\Academic\grid2.csv')
gdf = geopandas.GeoDataFrame(df,geometry=geopandas.points_from_xy(df.Latitude,df.Longitude),crs="+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs")
# total area for the grid
xmin,ymin,xmax,ymax= gdf.total_bounds
# how many cells across and down
n_cells=30
cell_size = (xmax-xmin)/n_cells
# projection of the grid
crs = "+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs"
# create the cells in a loop

grid_cells = []
for x0 in np.arange(xmin,xmax+cell_size,cell_size ):
    for y0 in np.arange(ymin,ymax+cell_size,cell_size):

        # bounds

        x1 = x0-cell_size
        y1 = y0+cell_size
        grid_cells.append( shapely.geometry.Box(x0,y0,x1,y1)  )                                    cell = geopandas.GeoDataFrame(grid_cells,columns=['geometry'],crs=crs)
ax = gdf.plot(markersize=.1,figsize=(12,8),column='LTE_UE_PCI',cmap='jet')
plt.autoscale(False)
cell.plot(ax=ax,facecolor="none",edgecolor='grey')

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)