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
12e249ff
Commit
12e249ff
authored
Jun 06, 2018
by
Mario Chirinos Colunga
💬
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wkt box
parent
0dcc6d01
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
7 deletions
+31
-7
polygonToBox.py
geosentinel/polygonToBox.py
+18
-7
polygonToBox.pyc
geosentinel/polygonToBox.pyc
+0
-0
simplifyWktPolygon.py
geosentinel/simplifyWktPolygon.py
+13
-0
No files found.
geosentinel/polygonToBox.py
View file @
12e249ff
...
...
@@ -4,32 +4,43 @@ import sys
from
osgeo
import
ogr
def
getWKTPolygonBoundingBox
(
polygon
):
def
getWKTPolygonBoundingBox
(
polygon
,
wkt
=
False
):
'''!
Get the bounding box of a WKT polygon.
@param polygon: WKT polygon
@param wkt: if true return in WKT format
@return bounding box string in format ulx uly lrx lry
>>> g = getWKTPolygonBoundingBox("POLYGON((-89.96360136135893 20.754157792347172,-89.24078398227726 20.754157792347172,-89.24078398227726 21.295577631081912,-89.96360136135893 21.295577631081912,-89.96360136135893 20.754157792347172))")
>>> p = "POLYGON((-89.96360136135893 20.754157792347172,-89.24078398227726 20.754157792347172,-89.24078398227726 21.295577631081912,-89.96360136135893 21.295577631081912,-89.96360136135893 20.754157792347172))"
>>> g = getWKTPolygonBoundingBox(p, True)
>>> print (g)
>>> g = getWKTPolygonBoundingBox(p)
>>> print (g)
-89.96360136135893 21.295577631081912 -89.24078398227726 20.754157792347172
'''
box
=
ogr
.
CreateGeometryFromWkt
(
polygon
)
.
GetEnvelope
()
#(minX, maxX, minY, maxY)
ulx
=
box
[
0
]
uly
=
box
[
3
]
lrx
=
box
[
1
]
lry
=
box
[
2
]
# ulx uly lrx lry
if
(
wkt
):
return
"POLYGON(("
+
str
(
ulx
)
+
" "
+
str
(
uly
)
+
","
+
str
(
lrx
)
+
" "
+
str
(
uly
)
+
","
+
str
(
lrx
)
+
" "
+
str
(
lry
)
+
","
+
str
(
ulx
)
+
" "
+
str
(
lry
)
+
","
+
str
(
ulx
)
+
" "
+
str
(
uly
)
+
"))"
else
:
#ulx uly lrx lry
return
str
(
ulx
)
+
" "
+
str
(
uly
)
+
" "
+
str
(
lrx
)
+
" "
+
str
(
lry
)
def
main
(
argv
):
# print (argv[1])
if
len
(
sys
.
argv
)
==
2
:
print
(
getWKTPolygonBoundingBox
(
argv
[
1
]))
if
len
(
sys
.
argv
)
==
3
:
print
(
getWKTPolygonBoundingBox
(
argv
[
1
),
argv
[
2
]))
if
__name__
==
"__main__"
:
main
(
sys
.
argv
)
#g = getWKTPolygonBoundingBox("POLYGON((-89.96360136135893 20.754157792347172,-89.24078398227726 20.754157792347172,-89.24078398227726 21.295577631081912,-89.96360136135893 21.295577631081912,-89.96360136135893 20.754157792347172))")
#print (g)
geosentinel/polygonToBox.pyc
0 → 100644
View file @
12e249ff
File added
geosentinel/simplifyWktPolygon.py
0 → 100644
View file @
12e249ff
#!/usr/bin/python
# -*- coding: utf-8 -*-
def
simplifyWktPolygon
(
wkt
,
MaxPoints
):
"""
"""
def
main
(
argv
):
# print (argv[1])
simplifyWktPolygon
(
argv
[
1
],
argv
[
2
])
if
__name__
==
"__main__"
:
main
(
sys
.
argv
)
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