您好,登錄后才能下訂單哦!
廢話不多說(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è)參考,也希望大家多多支持億速云。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。