美文网首页
矢量转栅格 栅格转矢量

矢量转栅格 栅格转矢量

作者: 不玩了啊 | 来源:发表于2019-11-21 17:17 被阅读0次

#!/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])

#!/usr/bin/env python

# -*- coding: utf-8 -*-

from osgeo import ogr

from osgeo import gdal

#  get raster datasource

open_image = gdal.Open( "../geodata/cadaster_borders-2tone-black-white.png" )

input_band = open_image.GetRasterBand(3)

#  create output datasource

output_shp = "../geodata/data/cadaster_raster"

shp_driver = ogr.GetDriverByName("ESRI Shapefile")

# create output file name

output_shapefile = shp_driver.CreateDataSource( output_shp + ".shp" )

new_shapefile = output_shapefile.CreateLayer(output_shp, srs = None )

gdal.Polygonize(input_band, None, new_shapefile, -1, [], callback=None)

new_shapefile.SyncToDisk()

相关文章

  • 矢量转栅格 栅格转矢量

    #!/usr/bin/env python # -*- coding: utf-8 -*- from osgeo ...

  • C# + ArcEngine 栅格转矢量

    以栅格转点为例:

  • Geotrellis 简介

    1 scala类库和框架2 可以读取 写入 操作栅格数据3 实现了很多的地图数据的操作,以及矢量到栅格数据,栅格到...

  • 教学第13周复盘20171201@张新锋

    地理信息系统原理 课堂内容梳理 知识:掌握矢量数据结构向栅格数据结构的转换掌握栅格数据结构向矢量数据结构的转换(四...

  • python实现使用GDAL实现矢量转栅格

    需求 现在有一个shp文件和栅格数据,需要将shp转换成和栅格数据空间位置一致且像元大小一致的栅格数据。ArcGI...

  • SVG 入门

    一、栅格图形和矢量图形栅格图形:也称位图,图像由一组二维像素网格表示。Canvas 2d API 就是一款栅格图形...

  • Python中用GDAL实现矢量对栅格的切割

    概述: 本文讲述如何在Python中用GDAL实现根据输入矢量边界对栅格数据的裁剪。 效果: 裁剪前 矢量边界 裁...

  • 5.5笔记

    栅格化:将矢量转位图图层路径文字工具 点小圆点按住ctrl拖选择-色彩范围:基础抠图 高光、阴影模式都调为滤色,不...

  • SVG在iOS中使用总结

    SVG简介 SVG是一种用XML定义的语言,用来描述二维矢量及矢量/栅格图形。SVG提供了3种类型的图形对象:矢量...

  • 地图瓦片整体介绍

    地图瓦片整体介绍 如今互联网地图的地图内容分为两种,一种是栅格地图瓦片,一种是矢量地图瓦片。 栅格地图瓦片 栅格地...

网友评论

      本文标题:矢量转栅格 栅格转矢量

      本文链接:https://www.haomeiwen.com/subject/feitwctx.html