当前位置:网站首页>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
边栏推荐
- .104History
- 587. Install fence / Sword finger offer II 014 Anagrams in strings
- vite配置proxy代理解决跨域
- Generate verification code
- C language implements memcpy, memset, strcpy, strncpy, StrCmp, strncmp and strlen
- Read excel, int digital time to time
- 油猴网站地址
- SystemVerilog (VI) - variable
- Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
- Secure credit
猜你喜欢
Summary of floating point double precision, single precision and half precision knowledge
[UDS unified diagnostic service] IV. typical diagnostic service (4) - online programming function unit (0x34-0x38)
re正則錶達式
C network related operations
JS forms the items with the same name in the array object into the same array according to the name
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年茶艺师(初级)考试模拟100题及模拟考试
Go file operation
Fashion classification case based on keras
In JS, t, = > Analysis of
随机推荐
Element calculation distance and event object
MySQL 中的字符串函数
Excel opens large CSV format data
k8s之实现redis一主多从动态扩缩容
Summary of common server error codes
Scikit learn sklearn 0.18 official document Chinese version
2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试
ROS package NMEA_ navsat_ Driver reads GPS and Beidou Positioning Information Notes
C# 网络相关操作
Listen for click events other than an element
Crack sliding verification code
Eigen learning summary
C1 notes [task training part 2]
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展
C1小笔记【任务训练篇一】
Anchor location - how to set the distance between the anchor and the top of the page. The anchor is located and offset from the top
C network related operations
[appium] write scripts by designing Keyword Driven files
Classification of cifar100 data set based on convolutional neural network
MySQL_ 01_ Simple data retrieval