python使用gdal将shp文件转为TIF
python使用gdal将shp文件转为TIF
方法一
# 缺少获取shp文件坐标系的步骤
def vector2raster(inputfilePath, outputfile, resp):sf = shapefile.Reader(inputfilePath)# 读取shp四至min_x, min_y, max_x, max_y = sf.bboxresp = 100 # 设置每个cell的大小tifrow = int((max_x - min_x) / resp)tifcol = int((max_y - min_y) / resp)vector = ogr.Open(inputfilePath)layer = vector.GetLayer()targetDataset = gdal.GetDriverByName('GTiff').Create(outputfile, tifrow, tifcol, 1, gdal.GDT_Byte)transform = (min_x, resp, 0, min_y, 0, resp)targetDataset.SetGeoTransform(transform)# targetDataset.SetProjection(data.GetProjection())band = targetDataset.GetRasterBand(1)NoData_value = -999band.SetNoDataValue(NoData_value)band.FlushCache()gdal.RasterizeLayer(targetDataset, [1], layer, )inputfilePath = "input_shp.shp" # 输入的待转换为tif的shp文件
outputfile = 'ouput_tif.tif' # 转为TIF后的存储地址
resp = 100 # 栅格中每个cell的大小vector2raster(inputfilePath, outputfile, 100)
方法二
# 003 通过模板设置坐标系
import gdal
from osgeo.gdal import gdalconst
from osgeo import gdal, ogr
import numpy as np
import os
import glob
import shapefiledef vector2raster(inputfilePath, outputfile, tempaltefile):inputfilePath = inputfilePathoutputfile = outputfiletempaltefile = tempaltefiledata = gdal.Open(tempaltefile, gdalconst.GA_ReadOnly)x_res = data.RasterXSizey_res = data.RasterYSizevector = ogr.Open(inputfilePath)layer = vector.GetLayer()targetDataset = gdal.GetDriverByName('GTiff').Create(outputfile, x_res, y_res, 1, gdal.GDT_Byte)targetDataset.SetGeoTransform(data.GetGeoTransform())# targetDataset.SetProjection(data.GetProjection())band = targetDataset.GetRasterBand(1)NoData_value = -999band.SetNoDataValue(NoData_value)band.FlushCache()gdal.RasterizeLayer(targetDataset, [1], layer, )inputfilePath = "input_shp.shp"
outputfile = 'output_tif.tif'
tempaltefile = 'tempaltefile .tif'
vector2raster(inputfilePath, outputfile, tempaltefile)
python使用gdal将shp文件转为TIF相关推荐
- java使用GDAL将shp文件转为geojson文件
java使用GDAL将shp文件转为geojson文件 代码如下(示例): //将shp文件转为geojson文件//shp文件所在的位置String strVectorFile = "E: ...
- python使用gdal读取shp文件
from __future__ import division import pandas as pd from osgeo import ogr, osr, gdal import osdef re ...
- 使用NetTopologySuite将shp文件转为GeoJson格式
使用NetTopologySuite将shp文件转为GeoJson格式 需要引入的库(NetTopologySuite可从Nuget中下载): using NetTopologySuite.Featu ...
- python shp文件_对python 读取线的shp文件实例详解
如下所示: import shapefile sf = shapefile.reader("e:\\1.2\\cs\\dx_csl.shp") shapes = sf.shapes ...
- 批量将NC文件转为tif格式
批量将多年的NC文件转为tif格式进行处理(来源:https://www.geek-share.com/detail/2763962738.html) 所参考和借鉴的文章的链接如下: https:// ...
- Python 画降雨图,mash 数据掩膜 裁剪出想要的区域,根据shp文件裁剪tif数据
1. 背景介绍 2. 导库 import numpy as np import xarray as xr import matplotlib.pyplot as plt from matplotlib ...
- MATLAB:读取nc文件并将nc文件转为tif文件输出
NC(NetCDF network Common Data Form,译为"网络通用数据格式") 文件是将多个时段的数据存储在一个文件当中. 内容格式如下: •从数学上来说,net ...
- python转csv_python脚本如何将Excel文件转为csv文件(代码)
本篇文章给大家带来的内容是关于python脚本如何将Excel文件转为csv文件(代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助.#!/usr/bin/env python __ ...
- 【数据转换】ascii文件转换为tif文件的函数
目的:脱离arcpy环境(ArcGIS平台),在python环境下实现ascii文件转换为tif文件格式 原因:在利用numpy库进行数值运算的过程中,多次涉及tif文件与ascii文件的转换.为了提 ...
最新文章
- Django学习笔记 开发环境搭建
- Ubentu编译Android源码(AOSP)
- Verdi-ug --- nwave Tutorial
- 微信小程序scroll-wiew 横向滚动问题
- 2019春第六周编程总结
- 搭载敏捷飞天底座,阿里云专有云敏捷版全面升级
- C++基础06-类与对象之new和malloc
- WEB前后端交互原型通用元件库、常用组件、信息输出、信息输入、信息反馈、综合系列、页面交互、首页、分类页、内容详情、用户中心、注册登录、找回密码、元件库、web元件库、rplib、axure
- 名不正则言不顺,言不顺则事不成
- hdu 5919--Sequence II(主席树--求区间不同数个数+区间第k大)
- python做前端mongodb_python-mongodb基本操作都在这了
- python中win32api模块_解决在Python中使用Win32api报错的问题,No module named win32api
- 喜大普奔,润乾全功能中文开源BI来了
- 锂电池技术关键突破:水淹火烧重击短路都不炸!三星看了会沉默,特斯拉蔚来听了要流泪...
- access2016与mysql_Access 2016数据库应用与开发
- PHP 判断操作系统位数
- HDU 5956 The Elder (树形DP + 斜率优化)
- 【Cactus仙人掌图】仙人掌基础知识学习笔记
- 基于eigen实现matlab hamming hann blakman 窗函数的实现
- 可以免费下载视频素材和模板网站汇总
热门文章
- tensorflow-federated+win10
- 大化设计模式第六、七周
- java el表达式原理_EL表达式详解
- 【题解】交通工具(c/c++中浮点数四舍五入为整数)
- iframe属性简单示例
- 2019-11-29-VisualStudio-2019-尝试使用-C#-8.0-新的方式
- 学计算机考平面设计证书有用吗,需要考一个平面设计师证书吗
- 注意力Transformer
- Multiobjective Optimization for Joint Task Offloading, Power Assignment, and Resource Allocation
- HighCharts使用