当前位置:网站首页>GDAL+OGR学习
GDAL+OGR学习
2022-04-23 05:46:00 【今天学习要很快乐鸭】
GDAL+OGR学习
每次写代码用Arcpy就得切回python2,很麻烦,故来学习一下gdal+ogr。
gdal库安装
直接cmd写pip intsall gdal会报错
打开该链接gdal库下载,根据python版本下载对应版本的包,我的版本是python3.9+64位,按需下载。
将wheel文件复制到相应文件夹再次运行pip install 安装成功。
使用OGR筛选数据
分别是高德POI表type结构和POIshp type的结构
将利用表格内含有的POI类型里对shp里的的POI类型进行筛选
#-*- coding:utf-8 -*-
#2022.2.10
'''
将表格里统计的poi进行筛选,然后选出指定区域内的poi类别
'''
import time
import pandas as pd
from osgeo import ogr
import os
def identify(poistr,selectpoilist):
if poistr.split(';')[2] in selectpoilist:
return 1
else:
return 0
def selectpoi(poitype,lyr):
n = lyr.GetFeatureCount()
print("共",n,"条poi数据")
#添加字段
defn = lyr.GetLayerDefn()
fieldIndex = defn.GetFieldIndex('selectid')
if fieldIndex < 0:
# 添加字段
lyr.CreateField( # 为图层添加一个selectid字段
ogr.FieldDefn('selectid', ogr.OFTInteger,SetPrecision(3))
)
fieldIndex2 = defn.GetFieldIndex('selectid')
if fieldIndex2 > 0:
print("字段创建成功:", fieldIndex)
m = 0
starttime = time.time()
for feat in lyr:
name = feat.GetField('name')
type = feat.GetField('type')
#计算r值判断是否选取,>0则选取,是0则不选
if (type.count("|")>0):
r=0
for i in range(0,type.count("|")):
r =r+identify(type.split('|')[i],poitype)
else:
r=identify(type,poitype)
if r>0:
feat.SetField('selectid', 1) # 设置字段的值
else:
feat.SetField('selectid', 0) # 设置字段的值
lyr.SetFeature(feat)
m=m+1
print("正在运行第",m,"条数据",feat.GetField('selectid'),name,type)
if m==n:
break;
endtime = time.time()
print("运行时间共计",endtime-starttime)
if __name__=="__main__":
#读取POI类型表格
datapath = r'E:\WHDATA\region_data\jianghan_district\database'
poifilename = "./细类别POI.xlsx"
poitype = pd.read_excel(poifilename)
type = poitype['小类'].to_list()
#读取江汉区POIshp数据
in_poishp = os.path.join(datapath,"poi.shp")
outpath = os.path.join(datapath,"poi_select.shp")
ds = ogr.Open(in_poishp,1)#1表示可写,0表示只读
lyr = ds.GetLayer()
selectpoi(type,lyr)
版权声明
本文为[今天学习要很快乐鸭]所创,转载请带上原文链接,感谢
https://blog.csdn.net/ShirleyLGY/article/details/123394211
边栏推荐
- Miscellaneous 1
- Pytorch notes - get familiar with the network construction method by building RESNET (complete code)
- Consistent hash algorithm used for redis cache load balancing
- C array
- Guaba and Computational Geometry
- Create binary tree
- Addition, deletion, modification and query of MySQL table
- Exception handling: grab and throw model
- C3p0 database connection pool usage
- 8. Integer Decomposition
猜你喜欢
Implementation of displaying database pictures to browser tables based on thymeleaf
Preparedstatement prevents SQL injection
Automatic control (Han min version)
Techniques et principes de détection
RPC must know and know
A sharp tool to improve work efficiency
Export of data
Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
IO multiplexing of 09 redis
線性代數第二章-矩陣及其運算
随机推荐
Understanding and installing MySQL
程序设计训练
Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
[untitled] database - limit the number of returned rows
A general U-shaped transformer for image restoration
ValueError: loaded state dict contains a parameter group that doesn‘t match the size of optimizer‘s
Addition, deletion, modification and query of MySQL table
Why does the subscript of the array start from 0 instead of 1?
Delete and truncate
Paper on LDCT image reconstruction: edge enhancement based transformer for medical image denoising
Common sense of thread pool
Chapter 3 of linear algebra - Elementary Transformation of matrix and system of linear equations
Integers have friends interval GCD + double pointer
POI and easyexcel exercises
C # Foundation
Example of reentrant lock thread waiting to wake up
H. Are You Safe? Convex hull naked problem
線性代數第二章-矩陣及其運算
Pytorch notes - complete code for linear regression & manual or automatic calculation of gradient code comparison
6.Reversal