admin 管理员组

文章数量: 1087749

python 提取照片GPS位置并转换成shp文件

python 提取照片GPS位置并转换成shp文件

-- coding: UTF-8 --

import exifread
import re
from osgeo import gdal, osr
from osgeo import ogr
import os, sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMessageBox
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QAction
from PyQt5 import QtCore, QtGui, QtWidgets
#创建shp文件
def insert_jzx(path_shp, name_shp):
gdal.SetConfigOption(“SHAPE_ENCODING”, “GBK”)
driver = ogr.GetDriverByName(‘ESRI Shapefile’)
os.chdir(path_shp)
if os.path.exists(‘%s.shp’%name_shp):
driver.DeleteDataSource(‘%s.shp’%name_shp)
outds_jzx = driver.CreateDataSource(‘%s.shp’%name_shp)
# gdal.SetConfigOption(“GDAL_FILENAME_IS_UTF8”, “YES”)
if outds_jzx == None:
print(‘创建文件失败!’)
dst_osr = osr.SpatialReference()
dst_osr.ImportFromEPSG(4490) # 国家2000坐标39度
outlayer_jzx = outds_jzx.CreateLayer(name_shp, dst_osr, geom_type=ogr.wkbPoint)
featuredefn_jzx = outlayer_jzx.GetLayerDefn()
fieldDefn = ogr.FieldDefn(‘照片路径’, ogr.OFTString)
fieldDefn.SetWidth(254)
outlayer_jzx.CreateField(fieldDefn)
return featuredefn_jzx, outds_jzx, outlayer_jzx

#写入shp文件
def update_shp(list_1, zd, outlayer_jzx, featuredefn_jzx):
ring = ogr.Geometry(ogr.wkbPoint)
ring.AddPoint(list_1[‘N’], list_1[‘E’])
#ring.AddPoint(list_1[0][0], list_1[0][1])
# polygon = ogr.Geometry(ogr.wkbPoint)
# polygon.AddGeometry(ring)
feature = ogr.Feature(featuredefn_jzx)
feature.SetGeometry(ring)
feature.SetField(‘照片路径’, zd)
outlayer_jzx.CreateFeature(feature)
feature.Destroy()
#del feature
#ring.Destroy()
#polygon.Destroy()

def select_jwd(path):
gps = {}
f = open(path,‘rb’)
contents = exifread.process_file(f)
for key in contents:
if key == “GPS GPSLongitude”:
a = contents[key]
a = str(a).replace(‘[’,‘’).replace(‘]’,‘’).split(‘,’)
d, f, m = a
m = m.split(‘/’)
ds = float(d) + float(f)/60 + float(m[0])/float(m[1])/600
gps[str(contents[‘GPS GPSLatitudeRef’])] = ds
elif key ==“GPS GPSLatitude”:
print(“纬度 =”,contents[key],contents[‘GPS GPSLongitudeRef’])
a = contents[key]
a = str(a).replace(‘[’, ‘’).replace(‘]’, ‘’).split(‘,’)
d, f, m = a
m = m.split(‘/’)
ds = float(d) + float(f) / 60 + float(m[0]) / float(m[1]) / 600
gps[str(contents[‘GPS GPSLongitudeRef’])] = ds
return gps


本文标签: python 提取照片GPS位置并转换成shp文件