当前位置:网站首页>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
边栏推荐
- Leak detection and vacancy filling (VII)
- undefined reference to `Nabo::NearestNeighbourSearch
- cv_ Solution of mismatch between bridge and opencv
- 20222 return to the workplace
- Detailed deployment of flask project
- Welcome to the markdown editor
- Re expression régulière
- C1小笔记【任务训练篇一】
- 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
- Add animation to the picture under V-for timing
猜你喜欢

Flask项目的部署详解

2022年广东省安全员A证第三批(主要负责人)特种作业证考试题库及在线模拟考试

Process management command

YOLOv4剪枝【附代码】

Implementation of k8s redis one master multi slave dynamic capacity expansion
![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](/img/ed/4d61ce34f830209f5adbddf9165676.png)
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

JS parsing and execution process

C# 的数据流加密与解密

2022江西储能技术展会,中国电池展,动力电池展,燃料电池展

开源按键组件Multi_Button的使用,含测试工程
随机推荐
Leak detection and vacancy filling (VII)
proxy server
Realsense selection comparison d455 d435i d415 t265 3D hardware comparison
Identification verification code
[UDS unified diagnostic service] (Supplement) v. detailed explanation of ECU bootloader development points (2)
Generate verification code
[appium] write scripts by designing Keyword Driven files
Chrome浏览器的跨域设置----包含新老版本两种设置
Welcome to the markdown editor
The ultimate experience, the audio and video technology behind the tiktok
Laser slam theory and practice of dark blue College Chapter 3 laser radar distortion removal exercise
Thirteen documents in software engineering
列表的使用-增删改查
C language loop structure program
Remember using Ali Font Icon Library for the first time
Crack sliding verification code
Secure credit
Theory and practice of laser slam in dark blue College - Chapter 2 (odometer calibration)
Comparison between xtask and kotlin coroutine
2022江西光伏展,中国分布式光伏展会,南昌太阳能利用展