Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
GeoSentinel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Mario Chirinos Colunga
GeoSentinel
Commits
c13bbfdf
Commit
c13bbfdf
authored
Oct 09, 2018
by
Mario Chirinos Colunga
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wkt raster
parent
5b73a401
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
0 deletions
+41
-0
rasterWkt.py
geosentinel/rasterWkt.py
+41
-0
No files found.
geosentinel/rasterWkt.py
View file @
c13bbfdf
...
...
@@ -25,6 +25,47 @@ def createLayer(wkt, layerName="wkt"):
feature
=
None
return
layer
#-------------------------------------------------------------------------------
def
getPolygonArray
(
image
,
wkt
):
rows
,
cols
,
geotransform
=
image
.
RasterYSize
,
image
.
RasterXSize
,
image
.
GetGeoTransform
()
sr
=
osr
.
SpatialReference
()
sr
.
ImportFromWkt
(
image
.
GetProjection
())
driverTiff
=
gdal
.
GetDriverByName
(
'GTiff'
)
polygonRaster
=
driverTiff
.
Create
(
"polygonTmp.tiff"
,
cols
,
rows
,
1
,
gdal
.
GDT_Byte
)
#Set up polygon raster
polygonRaster
.
GetRasterBand
(
1
)
.
SetNoDataValue
(
-
99
)
polygonRaster
.
GetRasterBand
(
1
)
.
WriteArray
(
np
.
zeros
((
rows
,
cols
)))
polygonRaster
.
GetRasterBand
(
1
)
.
FlushCache
()
polygonRaster
.
SetGeoTransform
(
geotransform
)
polygonRaster
.
SetProjection
(
sr
.
ExportToWkt
())
# shapefile
driverShp
=
ogr
.
GetDriverByName
(
"ESRI Shapefile"
)
data_source
=
driverShp
.
CreateDataSource
(
"myShape.shp"
)
#Burn Polygon
srs
=
osr
.
SpatialReference
()
srs
.
ImportFromEPSG
(
4326
)
layer
=
data_source
.
CreateLayer
(
"wkt"
,
srs
,
ogr
.
wkbPolygon
)
geometry
=
ogr
.
CreateGeometryFromWkt
(
wkt
)
feature
=
ogr
.
Feature
(
layer
.
GetLayerDefn
())
feature
.
SetStyleString
(
"PEN(c:#FF0000,w:5px);"
)
feature
.
SetGeometry
(
geometry
)
layer
.
CreateFeature
(
feature
)
gdal
.
RasterizeLayer
(
polygonRaster
,
[
1
],
layer
,
burn_values
=
[
255
])
polygonRaster
.
GetRasterBand
(
1
)
.
FlushCache
()
np_polygon
=
polygonRaster
.
GetRasterBand
(
1
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
)
data_source
=
None
polygonRaster
=
None
return
np_polygon
#-------------------------------------------------------------------------------
def
rasterWkt
(
wkt
,
inputfile
,
outputfile
):
'''
Draw WKT Polygon into a Image
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment