自己設定
def
intersection
(shp1, shp2, outshp)
:"""
:param shp1: 緩衝區向量路徑
:param shp2: 目標向量路徑
:param outshp: 輸出向量路徑
:return:
"""driver = ogr.getdriverbyname(
"esri shapefile"
) datasource1 = driver.open(shp1,1)
layer1 = datasource1.getlayer(
) datasource2 = driver.open(shp2,1)
layer2 = datasource2.getlayer(
)# 獲取到shp的投影座標系資訊
prosrs = layer1.getspatialref(
) geosrs = osr.spatialreference(
)# 設定輸出座標係為wgs84
geosrs.setprojection(
"gcs_wgs_1984"
)# 新建datasource,layer
out_ds = driver.createdatasource(outshp)
out_lyr = out_ds.createlayer(outshp, prosrs, ogr.wkbpolygon)
def_feature = out_lyr.getlayerdefn(
)for feature in layer1:
geom = feature.getgeometryref(
)for feature_ in layer2:
geom_ = feature_.getgeometryref(
)if geom.intersect(geom_)==1
: out_feature = ogr.feature(def_feature)
out_feature.setgeometry(geom_)
out_lyr.createfeature(out_feature)
out_ds.flushcache(
)del datasource1, datasource2
# 寫入投影檔案
geosrs.morphfromesri(
) prjfile =
open
(outshp.replace(
'.shp'
,'.prj'),
'w')
prjfile.write(geosrs.exporttowkt())
prjfile.close(
)
投影資訊**於.prj檔案中。
def
intersection
(shp1, shp2, outshp)
:"""
:param shp1: 緩衝區向量路徑
:param shp2: 目標向量路徑
:param outshp: 輸出向量路徑
:return:
"""driver = ogr.getdriverbyname(
"esri shapefile"
) datasource1 = driver.open(shp1,1)
layer1 = datasource1.getlayer(
) spatialref = layer1.getspatialref(
)
datasource2 = driver.open(shp2,1)
layer2 = datasource2.getlayer(
)# 新建datasource,layer
out_ds = driver.createdatasource(outshp)
out_lyr = out_ds.createlayer(outshp, spatialref, ogr.wkbpolygon)
def_feature = out_lyr.getlayerdefn(
)for feature in layer1:
geom = feature.getgeometryref(
)for feature_ in layer2:
geom_ = feature_.getgeometryref(
)if geom.intersect(geom_)==1
: out_feature = ogr.feature(def_feature)
out_feature.setgeometry(geom_)
out_lyr.createfeature(out_feature)
out_ds.flushcache(
)del datasource1, datasource2
地理座標系 投影座標系
1.基本概念 平時開展gis開發 研究 應用工作,總會接觸到座標系,也會遇到座標轉換的問題,如地理座標系 投影座標系等。地理座標系是球面座標,參考平面是橢球面,座標單位是經緯度 投影座標系是平面座標系,參考平面是水平面,座標單位是公尺 千公尺等。地理座標系轉換到投影座標系的過程理解為投影,即將不規則...
大地座標系 地理座標系 投影座標系
大地座標系 是大地測量中以參考橢球面為基準面建立起來的座標系。地面點的位置用 大地經度 大地緯度和大地高度 表示。大地座標系的確立包括選擇乙個橢球 對橢球進行定位和確定大地起算資料。乙個形狀 大小和定位 定向都已確定的地球橢球叫參考橢球。參考橢球一旦確定,則標誌著大地座標系已經建立。大地座標系是一種...
地理座標系和投影座標系
用經緯度表示地面點位的球面座標系。在大地測量學中,對於地理座標系統中的經緯度有三種描述 天文經緯度 大地經緯度 地心經緯度。天文經緯度 表示地面點在大地水準面上的位置,用天文經度和天文緯度表示。大地經緯度 表示地面點在參考橢球面上的位置,用大地精度 大地緯度 大地高h表示 大地座標均以橢球面法線來定...