矢量转栅格
矢量 栅格
2023-09-11 14:19:52 时间
#!/usr/bin/env python # -*- coding: utf-8 -*- from osgeo import ogr from osgeo import gdal # set pixel size pixel_size = 0.00002 no_data_value = -9999 # Shapefile input name # input projection must be in cartesian system in meters # input wgs 84 or EPSG: 4326 will NOT work!!! input_shp = r'../geodata/data/ply_golfcourse-strasslach3857.shp' # TIF Raster file to be created output_raster = r'../geodata/data/ply_golfcourse-strasslach.img' # Open the data source get the layer object # assign extent coordinates #shp_driver = ogr.GetDriverByName('ESRI Shapefile') open_shp = ogr.Open(input_shp) shp_layer = open_shp.GetLayer() x_min, x_max, y_min, y_max = shp_layer.GetExtent() print(x_min) print(x_max) # calculate raster resolution x_res = int((x_max - x_min) / pixel_size) y_res = int((y_max - y_min) / pixel_size) print(x_res) print(y_res) # set the image type for export image_type = 'GTiff' image_type = 'HFA' driver = gdal.GetDriverByName(image_type) driver.Register() # create a new raster takes Parameters # Filename the name of the dataset to create. UTF-8 encoded. # nXSize width of created raster in pixels. # nYSize height of created raster in pixels. # nBands number of bands. # eType type of raster. new_raster = driver.Create(output_raster, x_res, y_res, 1, gdal.GDT_Byte) new_raster.SetGeoTransform((x_min, pixel_size, 0, y_max, 0, -pixel_size)) # get the raster band we want to export too raster_band = new_raster.GetRasterBand(1) # assign the no data value to empty cells raster_band.SetNoDataValue(no_data_value) # run vector to raster on new raster with input Shapefile gdal.RasterizeLayer(new_raster, [1], shp_layer, burn_values=[255])
相关文章
- 强大的矢量图形库:Raphael JS 中文帮助文档及教程
- Google Earth Engine(GEE)——feature collection矢量集合的融合
- Google Earth Engine(GEE)——创建矢量feature添加属性及其获取!
- Google Earth Engine(GEE)——JavaScript基本功能介绍( 矢量集合FeatureCollections)
- Google Earth Engine(GEE)——影像矢量转栅格(日本夜间灯光数据案例分析)
- Google Earth Engine(GEE)——使用在线的世界矢量边界作为研究区(国家和洲际),如何调用?
- 制作 矢量图标
- NI推出第二款矢量信号收发仪,扩展创新性软件设计仪器平台
- 矢量图形转换工具UniConvertor
- 【GIS】Mapbox、GeoServer矢量瓦片
- C代码中矢量运算的几个例子
- 矢量切片
- 栅格转矢量
- PSINS中旋转矢量与四元数转换及四元数相乘公式与代码