Commit 12e249ff authored by Mario Chirinos Colunga's avatar Mario Chirinos Colunga 💬

wkt box

parent 0dcc6d01
...@@ -4,32 +4,43 @@ import sys ...@@ -4,32 +4,43 @@ import sys
from osgeo import ogr from osgeo import ogr
def getWKTPolygonBoundingBox(polygon): def getWKTPolygonBoundingBox(polygon, wkt=False):
'''! '''!
Get the bounding box of a WKT polygon. Get the bounding box of a WKT polygon.
@param polygon: WKT polygon @param polygon: WKT polygon
@param wkt: if true return in WKT format
@return bounding box string in format ulx uly lrx lry @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) >>> print (g)
-89.96360136135893 21.295577631081912 -89.24078398227726 20.754157792347172 -89.96360136135893 21.295577631081912 -89.24078398227726 20.754157792347172
''' '''
box = ogr.CreateGeometryFromWkt(polygon).GetEnvelope() #(minX, maxX, minY, maxY) box = ogr.CreateGeometryFromWkt(polygon).GetEnvelope() #(minX, maxX, minY, maxY)
ulx = box[0] ulx = box[0]
uly = box[3] uly = box[3]
lrx = box[1] lrx = box[1]
lry = box[2] 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) return str(ulx) +" "+ str(uly) +" "+ str(lrx) +" "+ str(lry)
def main(argv): def main(argv):
# print (argv[1])
if len(sys.argv) == 2:
print (getWKTPolygonBoundingBox(argv[1])) print (getWKTPolygonBoundingBox(argv[1]))
if len(sys.argv) == 3:
print (getWKTPolygonBoundingBox(argv[1), argv[2]))
if __name__ == "__main__": if __name__ == "__main__":
main(sys.argv) 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))") #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) #print (g)
#!/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)
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