当前位置:网站首页>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
边栏推荐
- Comparative study paper - [Moco, cvpr2020] momentum contract for unsupervised visual representation learning
- C language file operation
- MySQL occasional Caton
- container
- Collections multiple parameter sorting
- Installation and usage skills of idea
- Pytorch notes - get familiar with the network construction method by building RESNET (complete code)
- Example of reentrant lock thread waiting to wake up
- Create binary tree
- Type conversion in C #
猜你喜欢

Create binary tree

20 excellent plug-ins recommended by idea

檢測技術與原理

The bottom implementation principle of thread - static agent mode

Kibana search syntax

Illustrate the significance of hashcode

Export of data

Algèbre linéaire chapitre 1 - déterminants
![How to use comparative learning to do unsupervised - [cvpr22] training & [eccv20] image translation](/img/33/780b80693f70112eebc10941f7c134.png)
How to use comparative learning to do unsupervised - [cvpr22] training & [eccv20] image translation

Fundamentals of in-depth learning -- a simple understanding of meta learning (from Li Hongyi's course notes)
随机推荐
Collections multiple parameter sorting
Three ways to create threads
[untitled] database - limit the number of returned rows
Rainbow (DP)
The bottom implementation principle of thread - static agent mode
20 excellent plug-ins recommended by idea
Troubleshooting of data deleted and reappeared problems
Pytorch introduction notes - use a simple example to observe the output size of each layer of forward propagation
Event listener
线性代数第二章-矩阵及其运算
Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
Understanding and installing MySQL
Example of reentrant lock thread waiting to wake up
[leetcode 59] spiral matrix II
Automatic control (Han min version)
Animation - Introduction to keyframes
On traversal of binary tree
线性代数第一章-行列式
[leetcode 202] happy number
Calculation (enter the calculation formula to get the result)