当前位置:网站首页>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
边栏推荐
- 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!!!)
- 2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
- Romance in C language
- Process management command
- [UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (1)
- Where is the configuration file of tidb server?
- Basic usage of crawler requests
- C network related operations
- Secure credit
- JS parsing and execution process
猜你喜欢
SystemVerilog (VI) - variable
Fashion classification case based on keras
QTableWidget使用讲解
Flask项目的部署详解
Auto. JS custom dialog box
Implementation of k8s redis one master multi slave dynamic capacity expansion
On the problem of V-IF display and hiding
Cross domain settings of Chrome browser -- including new and old versions
positioner
2022 tea artist (primary) examination simulated 100 questions and simulated examination
随机推荐
C# 网络相关操作
Classes and objects
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
Selenium + phantom JS crack sliding verification 2
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
JS implementation private attribute
C language array processing batch data
Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise
Auto.js 自定义对话框
纳米技术+AI赋能蛋白质组学|珞米生命科技完成近千万美元融资
Svn simple operation command
Element calculation distance and event object
云原生虚拟化:基于 Kubevirt 构建边缘计算实例
Uniapp custom search box adaptation applet alignment capsule
positioner
极致体验,揭晓抖音背后的音视频技术
re正則錶達式
Click Cancel to return to the previous page and modify the parameter value of the previous page, let pages = getcurrentpages() let prevpage = pages [pages. Length - 2] / / the data of the previous pag
Implementation of object detection case based on SSD
2022 judgment questions and answers for operation of refrigeration and air conditioning equipment