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
fb04984c
Commit
fb04984c
authored
Aug 20, 2018
by
Mario Chirinos Colunga
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
drawing polygon
parent
ce324d20
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
12 deletions
+27
-12
rasterWkt.py
geosentinel/rasterWkt.py
+27
-12
No files found.
geosentinel/rasterWkt.py
View file @
fb04984c
...
@@ -34,32 +34,31 @@ def rasterWkt(wkt, inputfile, outputfile):
...
@@ -34,32 +34,31 @@ def rasterWkt(wkt, inputfile, outputfile):
print
(
outputfile
)
print
(
outputfile
)
intput
=
gdal
.
Open
(
inputfile
)
intput
=
gdal
.
Open
(
inputfile
)
rows
,
cols
,
geotransform
=
intput
.
RasterYSize
,
intput
.
RasterXSize
,
intput
.
GetGeoTransform
()
rows
,
cols
,
geotransform
=
intput
.
RasterYSize
,
intput
.
RasterXSize
,
intput
.
GetGeoTransform
()
sr
=
osr
.
SpatialReference
()
sr
.
ImportFromWkt
(
intput
.
GetProjection
())
# Read the input bands as numpy arrays.
# Read the input bands as numpy arrays.
driverTiff
=
gdal
.
GetDriverByName
(
'GTiff'
)
driverTiff
=
gdal
.
GetDriverByName
(
'GTiff'
)
output
=
driverTiff
.
Create
(
outputfile
,
cols
,
rows
,
3
,
gdal
.
GDT_Byte
)
output
=
driverTiff
.
Create
(
outputfile
,
cols
,
rows
,
3
,
gdal
.
GDT_Byte
)
print
(
"BANDS"
)
polygonRaster
=
driverTiff
.
Create
(
"polygonTmp.tiff"
,
cols
,
rows
,
1
,
gdal
.
GDT_Byte
)
print
(
output
.
RasterCount
)
for
b
in
range
(
1
,
output
.
RasterCount
+
1
):
np_input
=
intput
.
GetRasterBand
(
b
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
)
output
.
GetRasterBand
(
b
)
.
SetNoDataValue
(
-
99
)
output
.
GetRasterBand
(
b
)
.
WriteArray
(
np_input
)
output
.
GetRasterBand
(
b
)
.
FlushCache
()
#Set up polygon raster
polygonRaster
.
GetRasterBand
(
b
)
.
SetNoDataValue
(
-
99
)
polygonRaster
.
GetRasterBand
(
b
)
.
WriteArray
(
np
.
zeros
(
cols
*
rows
))
polygonRaster
.
GetRasterBand
(
b
)
.
FlushCache
()
polygonRaster
.
SetGeoTransform
(
geotransform
)
output
.
SetGeoTransform
(
geotransform
)
sr
=
osr
.
SpatialReference
()
sr
.
ImportFromWkt
(
intput
.
GetProjection
())
output
.
SetProjection
(
sr
.
ExportToWkt
())
# shapefile
# shapefile
driver
=
ogr
.
GetDriverByName
(
"ESRI Shapefile"
)
driver
=
ogr
.
GetDriverByName
(
"ESRI Shapefile"
)
data_source
=
driver
.
CreateDataSource
(
"myShape.shp"
)
data_source
=
driver
.
CreateDataSource
(
"myShape.shp"
)
#Burn Polygon
srs
=
osr
.
SpatialReference
()
srs
=
osr
.
SpatialReference
()
srs
.
ImportFromEPSG
(
4326
)
srs
.
ImportFromEPSG
(
4326
)
layer
=
data_source
.
CreateLayer
(
"wkt"
,
srs
,
ogr
.
wkbPolygon
)
layer
=
data_source
.
CreateLayer
(
"wkt"
,
srs
,
ogr
.
wkbPolygon
)
...
@@ -70,10 +69,26 @@ def rasterWkt(wkt, inputfile, outputfile):
...
@@ -70,10 +69,26 @@ def rasterWkt(wkt, inputfile, outputfile):
feature
.
SetGeometry
(
geometry
)
feature
.
SetGeometry
(
geometry
)
layer
.
CreateFeature
(
feature
)
layer
.
CreateFeature
(
feature
)
gdal
.
RasterizeLayer
(
output
,
[
1
,
2
,
3
],
layer
,
burn_values
=
[
255
,
1
,
1
])
gdal
.
RasterizeLayer
(
polygonRaster
,
[
1
],
layer
,
burn_values
=
[
255
])
#Draw output image
np_polygon
=
polygonRaster
.
GetRasterBand
(
1
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
)
for
b
in
range
(
1
,
output
.
RasterCount
+
1
):
np_input
=
intput
.
GetRasterBand
(
b
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
)
|
polygonRaster
output
.
GetRasterBand
(
b
)
.
SetNoDataValue
(
-
99
)
output
.
GetRasterBand
(
b
)
.
WriteArray
(
np_input
)
output
.
GetRasterBand
(
b
)
.
FlushCache
()
output
.
SetGeoTransform
(
geotransform
)
output
.
SetProjection
(
sr
.
ExportToWkt
())
#Close files
feature
=
None
feature
=
None
data_source
=
None
data_source
=
None
output
=
None
output
=
None
polygonRaster
=
None
def
main
(
argv
):
def
main
(
argv
):
rasterWkt
(
argv
[
1
],
argv
[
2
],
argv
[
3
])
rasterWkt
(
argv
[
1
],
argv
[
2
],
argv
[
3
])
...
...
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