当前位置:网站首页>GDAL + ogr learning
GDAL + ogr learning
2022-04-23 18:00:00 【Be happy to study today】
GDAL+OGR Study
Every time you write code, use Arcpy You have to switch back python2, so much trouble , So let's learn gdal+ogr.
gdal Libraries installed
direct cmd Write pip intsall gdal Will report a mistake
Open the link gdal Library Download , according to python Version download the package of the corresponding version , My version is python3.9+64 position , Download on demand .
take wheel Copy the file to the corresponding folder and run again pip install Installation successful .
Use OGR Filter data
They are Gaud POI surface type The structure and POIshp type Structure
Will use the... Contained in the form POI The type is right shp Inside POI Type
#-*- coding:utf-8 -*-
#2022.2.10
'''
Put the statistics in the table poi Screening , Then select... In the designated area poi Category
'''
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(" common ",n," strip poi data ")
# Add fields
defn = lyr.GetLayerDefn()
fieldIndex = defn.GetFieldIndex('selectid')
if fieldIndex < 0:
# Add fields
lyr.CreateField( # Add a layer selectid Field
ogr.FieldDefn('selectid', ogr.OFTInteger,SetPrecision(3))
)
fieldIndex2 = defn.GetFieldIndex('selectid')
if fieldIndex2 > 0:
print(" Field created successfully :", fieldIndex)
m = 0
starttime = time.time()
for feat in lyr:
name = feat.GetField('name')
type = feat.GetField('type')
# Calculation r Value to determine whether to select ,>0 Then choose , yes 0 You don't choose
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) # Set the value of the field
else:
feat.SetField('selectid', 0) # Set the value of the field
lyr.SetFeature(feat)
m=m+1
print(" Running page ",m," Data ",feat.GetField('selectid'),name,type)
if m==n:
break;
endtime = time.time()
print(" Total running time ",endtime-starttime)
if __name__=="__main__":
# Read POI Type table
datapath = r'E:\WHDATA\region_data\jianghan_district\database'
poifilename = "./ Sub category POI.xlsx"
poitype = pd.read_excel(poifilename)
type = poitype[' Subclass '].to_list()
# Read Jianghan District POIshp data
in_poishp = os.path.join(datapath,"poi.shp")
outpath = os.path.join(datapath,"poi_select.shp")
ds = ogr.Open(in_poishp,1)#1 Said to write ,0 Indicates read-only
lyr = ds.GetLayer()
selectpoi(type,lyr)
版权声明
本文为[Be happy to study today]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230545528278.html
边栏推荐
- Operation of 2022 mobile crane driver national question bank simulation examination platform
- Fashion classification case based on keras
- Write a regular
- Examination question bank and online simulation examination of the third batch (main person in charge) of special operation certificate of safety officer a certificate in Guangdong Province in 2022
- This point in JS
- Leak detection and vacancy filling (6)
- C network related operations
- Go language JSON package usage
- Svn simple operation command
- How to read literature
猜你喜欢
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
MySQL_01_简单数据检索
.104History
Summary of floating point double precision, single precision and half precision knowledge
Detailed deployment of flask project
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
Implementation of object detection case based on SSD
An example of linear regression based on tensorflow
Halo open source project learning (II): entity classes and data tables
C#的随机数生成
随机推荐
Leak detection and vacancy filling (6)
Crack sliding verification code
I / O multiplexing and its related details
Arithmetic expression
Element calculation distance and event object
2022 judgment questions and answers for operation of refrigeration and air conditioning equipment
Build openstack platform
Yolov4 pruning [with code]
C [file operation] read TXT text by line
Tell the truth of TS
2022江西光伏展,中國分布式光伏展會,南昌太陽能利用展
Implementation of object detection case based on SSD
油猴网站地址
2022年上海市安全员C证操作证考试题库及模拟考试
Uniapp custom search box adaptation applet alignment capsule
Halo 开源项目学习(二):实体类与数据表
Basic usage of crawler requests
Compilation principle first set follow set select set prediction analysis table to judge whether the symbol string conforms to the grammar definition (with source code!!!)
Thirteen documents in software engineering
re正则表达式