Python 根據(jù)數(shù)據(jù)模板創(chuàng)建shapefile的實現(xiàn)
更新時間:2019年11月26日 11:16:15 作者:staHuri
今天小編就為大家分享一篇Python 根據(jù)數(shù)據(jù)模板創(chuàng)建shapefile的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
廢話不多說,我就直接上代碼讓大家看看吧!
#!/usr/bin/env python # -*- coding: utf-8 -*- # @File : copyShapefile.py # @Author: huifer # @Date : 2018-4-28 from os.path import exists import gdal from osgeo import ogr from os import remove gdal.SetConfigOption("GDAL_FILENAME_IS_UTF8", "YES") # 路徑中文 gdal.SetConfigOption("SHAPE_ENCODING", "GBK") # 屬性中文 in_shapefile = "dataSample/wang_point.shp"# 數(shù)據(jù)模板 out_shapefile = "shapefileAa.shp" # 輸出數(shù)據(jù)集 in_ds = ogr.Open(in_shapefile) # 讀取模板數(shù)據(jù) in_lyr = in_ds.GetLayerByIndex(0) if exists(out_shapefile): remove(out_shapefile) drv = ogr.GetDriverByName("ESRI Shapefile") # 指定數(shù)據(jù)驅(qū)動 out_ds = drv.CreateDataSource(out_shapefile) # 創(chuàng)建數(shù)據(jù)源 proj = in_lyr.GetSpatialRef() # 獲取模板坐標(biāo)系 out_lyr = out_ds.CreateLayer(out_shapefile.split(".")[0], proj, ogr.wkbPoint) # copy the schema of the original shapefile to the destination shapefile lyr_def = in_lyr.GetLayerDefn() for i in range(lyr_def.GetFieldCount()): # 獲取字段長度 out_lyr.CreateField(lyr_def.GetFieldDefn(i)) # 創(chuàng)建字段 feature = ogr.Feature(lyr_def) wkt = "POINT(88615.730000 75345.486000)" point = ogr.CreateGeometryFromWkt(wkt) feature.SetGeometry(point) # 添加點 out_lyr.CreateFeature(feature) # 關(guān)閉 特征 feature = None # 關(guān)閉數(shù)據(jù) data_source = None
以上這篇Python 根據(jù)數(shù)據(jù)模板創(chuàng)建shapefile的實現(xiàn)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
python應(yīng)用程序在windows下不出現(xiàn)cmd窗口的辦法
這篇文章主要介紹了python應(yīng)用程序在windows下不出現(xiàn)cmd窗口的辦法,適用于python寫的GTK程序并用py2exe編譯的情況下,需要的朋友可以參考下2014-05-05PyTorch?Distributed?Data?Parallel使用詳解
這篇文章主要為大家介紹了PyTorch?Distributed?Data?Parallel使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03python中子類與父類的關(guān)系基礎(chǔ)知識點
在本篇文章里小編給大家整理的是一篇關(guān)于python中子類與父類的關(guān)系基礎(chǔ)知識點內(nèi)容,對此有興趣的朋友們可以學(xué)習(xí)下。2021-02-02Python實現(xiàn)根據(jù)日期獲取當(dāng)天凌晨時間戳的方法示例
這篇文章主要介紹了Python實現(xiàn)根據(jù)日期獲取當(dāng)天凌晨時間戳的方法,涉及Python針對日期與時間戳的相關(guān)轉(zhuǎn)換、運算等操作技巧,需要的朋友可以參考下2019-04-04