Python 根據(jù)數(shù)據(jù)模板創(chuàng)建shapefile的實(shí)現(xiàn)
廢話不多說(shuō),我就直接上代碼讓大家看看吧!
#!/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ū)動(dòng)
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()): # 獲取字段長(zhǎng)度
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)
# 添加點(diǎn)
out_lyr.CreateFeature(feature)
# 關(guān)閉 特征
feature = None
# 關(guān)閉數(shù)據(jù)
data_source = None
以上這篇Python 根據(jù)數(shù)據(jù)模板創(chuàng)建shapefile的實(shí)現(xiàn)就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
python判斷端口是否打開(kāi)的實(shí)現(xiàn)代碼
python判斷端口是否打開(kāi)的代碼,有需要的朋友可以參考下2013-02-02
python應(yīng)用程序在windows下不出現(xiàn)cmd窗口的辦法
這篇文章主要介紹了python應(yīng)用程序在windows下不出現(xiàn)cmd窗口的辦法,適用于python寫(xiě)的GTK程序并用py2exe編譯的情況下,需要的朋友可以參考下2014-05-05
PyTorch?Distributed?Data?Parallel使用詳解
這篇文章主要為大家介紹了PyTorch?Distributed?Data?Parallel使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-03-03
python中子類與父類的關(guān)系基礎(chǔ)知識(shí)點(diǎn)
在本篇文章里小編給大家整理的是一篇關(guān)于python中子類與父類的關(guān)系基礎(chǔ)知識(shí)點(diǎn)內(nèi)容,對(duì)此有興趣的朋友們可以學(xué)習(xí)下。2021-02-02
Python socket服務(wù)常用操作代碼實(shí)例
這篇文章主要介紹了Python socket服務(wù)常用操作代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06
Python實(shí)現(xiàn)根據(jù)日期獲取當(dāng)天凌晨時(shí)間戳的方法示例
這篇文章主要介紹了Python實(shí)現(xiàn)根據(jù)日期獲取當(dāng)天凌晨時(shí)間戳的方法,涉及Python針對(duì)日期與時(shí)間戳的相關(guān)轉(zhuǎn)換、運(yùn)算等操作技巧,需要的朋友可以參考下2019-04-04

