使用python实现渔网创建

使用python实现渔网创建

from shapely.geometry import Polygon
import geopandas as gpd

def Fishnet(boundary,cell_height,cell_width) -> None:
    # 渔网多边形
    # boundary = gpd.read_file("boundary.shp")
    xmin, ymin, xmax, ymax = boundary.total_bounds
    rows = int((ymax - ymin) / cell_height)
    cols = int((xmax - xmin) / cell_width)
    polygons = []
    for x in range(cols):
        for y in range(rows):
            polygons.append(Polygon([(xmin + x * cell_width, ymin + y * cell_height),
                                    (xmin + (x + 1) * cell_width, ymin + y * cell_height),
                                    (xmin + (x + 1) * cell_width, ymin + (y + 1) * cell_height),
                                    (xmin + x * cell_width, ymin + (y + 1) * cell_height)]))
    fishnet = gpd.GeoDataFrame(geometry=polygons, crs=boundary.crs)

    # 计算渔网中心点
    fishnet["center"] = fishnet.centroid
    fishnet = fishnet.set_geometry("center")
    # 设置新的crs为4326
    fishnet = fishnet.to_crs(epsg=4326)
    fishnet = fishnet.drop('geometry',axis =1)

    return fishnet

注意: boundary需要投影。

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值