Commit e81554ef authored by Mario Chirinos Colunga's avatar Mario Chirinos Colunga 💬

update

parent c509c925
#!/usr/bin/python
# -*- coding: utf-8 -*-
#"POLYGON((-89.65513229370117 21.048938357786966,-89.62852478027342 21.047816903874505,-89.6261215209961 21.03339745836918,-89.6465492248535 21.022822311328852,-89.65873718261717 21.039325621609095,-89.65513229370117 21.048938357786966))"
import osgeo.ogr as ogr
import osgeo.osr as osr
import numpy as np
import gdal
import sys
#-------------------------------------------------------------------------------
def createLayer(wkt, layerName="wkt"):
# create the spatial reference, WGS84
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
layer = data_source.CreateLayer(layerName, srs, ogr.wkbPolygon)
# Create the point from the Well Known Text
geometry = ogr.CreateGeometryFromWkt(wkt)
# create the feature
feature = ogr.Feature(layer.GetLayerDefn())
# Set the feature geometry using the point
feature.SetGeometry(geometry)
# Create the feature in the layer (shapefile)
layer.CreateFeature(feature)
# Dereference the feature
feature = None
return layer
#-------------------------------------------------------------------------------
def rasterWkt(wkt, inputfile, outputfile):
'''
Draw WKT Polygon into a Image
'''
intput = gdal.Open(inputfile)
rows, cols, geotransform = intput.RasterYSize, intput.RasterXSize, intput.GetGeoTransform()
# Read the input bands as numpy arrays.
np_intput = intput.GetRasterBand(1).ReadAsArray(0,0,cols,rows)
driverTiff = gdal.GetDriverByName('GTiff')
output = driverTiff.Create(outputfile, cols, rows, 1, gdal.GDT_Byte)
output.GetRasterBand(1).SetNoDataValue(-99)
output.GetRasterBand(1).WriteArray(np_intput)
output.GetRasterBand(1).FlushCache()
output.SetGeoTransform(geotransform)
wkt = b1.GetProjection()
sr = osr.SpatialReference()
sr.ImportFromWkt(wkt)
output.SetProjection(sr.ExportToWkt())
gdal.RasterizeLayer(output, [1], createLayer(wkt), burn_values=[0])
output = None
def main(argv):
rasterWkt(argv[1], argv[2], argv[3])
if __name__ == "__main__":
main(sys.argv)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment