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
5cb902ca
Commit
5cb902ca
authored
Oct 09, 2018
by
Mario Chirinos Colunga
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wkt raster
parent
3569cdd5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
18 deletions
+31
-18
rasterWkt.py
geosentinel/rasterWkt.py
+31
-18
No files found.
geosentinel/rasterWkt.py
View file @
5cb902ca
...
...
@@ -25,27 +25,40 @@ def createLayer(wkt, layerName="wkt"):
feature
=
None
return
layer
#-------------------------------------------------------------------------------
def
getPolygonArray
(
image
,
wkt
):
def
getPolygonArray
(
image
,
wkt
_geom
):
rows
,
cols
,
geotransform
=
image
.
RasterYSize
,
image
.
RasterXSize
,
image
.
GetGeoTransform
()
print
(
rows
,
cols
,
geotransform
)
sr
=
osr
.
SpatialReference
()
sr
.
ImportFromWkt
(
image
.
GetProjection
())
# shapefile
driverShp
=
ogr
.
GetDriverByName
(
"ESRI Shapefile"
)
data_source
=
driverShp
.
CreateDataSource
(
"myShape.shp"
)
#
# shapefile
#
driverShp = ogr.GetDriverByName("ESRI Shapefile")
#
data_source = driverShp.CreateDataSource("myShape.shp")
srs
=
osr
.
SpatialReference
()
srs
.
ImportFromEPSG
(
4326
)
layer
=
data_source
.
CreateLayer
(
"wkt"
,
srs
,
ogr
.
wkbPolygon
)
geometry
=
ogr
.
CreateGeometryFromWkt
(
wkt
)
feature
=
ogr
.
Feature
(
layer
.
GetLayerDefn
())
#
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
)
## feature.SetStyleString("PEN(c:#FF0000,w:5px);")
# feature.SetGeometry(geometry)
# layer.CreateFeature(feature)
#
# data_source = None
rast_ogr_ds
=
ogr
.
GetDriverByName
(
'Memory'
)
.
CreateDataSource
(
'wrk'
)
rast_mem_lyr
=
rast_ogr_ds
.
CreateLayer
(
'poly'
,
srs
=
sr
)
feat
=
ogr
.
Feature
(
rast_mem_lyr
.
GetLayerDefn
()
)
feat
.
SetGeometryDirectly
(
ogr
.
Geometry
(
wkt
=
wkt_geom
)
)
rast_mem_lyr
.
CreateFeature
(
feat
)
# Run the algorithm.
# err = gdal.RasterizeLayer( target_ds, [3,2,1], rast_mem_lyr, burn_values = [200,220,240] )
#Set up polygon raster
driverTiff
=
gdal
.
GetDriverByName
(
'GTiff'
)
...
...
@@ -53,18 +66,18 @@ def getPolygonArray(image, wkt):
polygonRaster
.
GetRasterBand
(
1
)
.
SetNoDataValue
(
-
99
)
polygonRaster
.
GetRasterBand
(
1
)
.
WriteArray
(
np
.
zeros
((
rows
,
cols
)))
polygonRaster
.
GetRasterBand
(
1
)
.
FlushCache
()
# polygonRaster.SetGeoTransform(geotransform)
# polygonRaster.SetProjection(sr.ExportToWkt())
polygonRaster
.
SetProjection
(
image
.
GetProjectionRef
())
polygonRaster
.
SetGeoTransform
(
image
.
GetGeoTransform
())
#Burn Polygon
gdal
.
RasterizeLayer
(
polygonRaster
,
[
1
],
laye
r
,
burn_values
=
[
255
])
gdal
.
RasterizeLayer
(
polygonRaster
,
[
1
],
rast_mem_ly
r
,
burn_values
=
[
255
])
polygonRaster
.
GetRasterBand
(
1
)
.
FlushCache
()
np_polygon
=
polygonRaster
.
GetRasterBand
(
1
)
.
ReadAsArray
(
0
,
0
,
cols
,
rows
)
feature
=
None
data_source
=
None
rast_ogr_ds
=
None
#
data_source = None
polygonRaster
=
None
return
np_polygon
...
...
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