def fromWKT(self, s): """ Initialise from a WKT string of the form 'BOX(x y,x y)' This syntax is returned by the extent() command in postgis. """ try: # skip 'BOX(' and ')' s = s[4:] s = s[:-1] # match import re f = "[-+]?(\d+(\.\d*)?|\d*\.\d+)([eE][-+]?\d+)?" e = r"(?P<x1>%s) (?P<y1>%s)\,(?P<x2>%s) (?P<y2>%s)" % (f, f, f, f) points = re.match(e, s).groupdict() # print points # set matching results ll = pointFromValues(float(points['x1']), float(points['y1'])) ur = pointFromValues(float(points['x2']), float(points['y2'])) except: raise Exception("Could not parse '%s'" % s) # recast self._setUpperRight(ur) self._setLowerLeft(ll) self._normaliseCornerCoords()
def fromWKT(self, s): """ Initialise from a WKT string of the form 'BOX(x y,x y)' This syntax is returned by the extent() command in postgis. """ try: # skip 'BOX(' and ')' s = s[4:] s = s[:-1] # match import re f = "[-+]?(\d+(\.\d*)?|\d*\.\d+)([eE][-+]?\d+)?" e = r"(?P<x1>%s) (?P<y1>%s)\,(?P<x2>%s) (?P<y2>%s)" %(f,f,f,f) points = re.match(e,s).groupdict() # print points # set matching results ll = pointFromValues( float(points['x1']),float(points['y1']) ) ur = pointFromValues( float(points['x2']),float(points['y2']) ) except: raise Exception("Could not parse '%s'" %s) # recast self._setUpperRight(ur) self._setLowerLeft(ll) self._normaliseCornerCoords()
def _normaliseCornerCoords(self): #print self._upper_right xr = self._upper_right.getX() xl = self._lower_left.getX() yu = self._upper_right.getY() yl = self._lower_left.getY() if xl > xr and yl > yu: self._upper_right = pointFromValues(xl, yl) self._lower_left = pointFromValues(xr, yu) elif xl > xr: self._upper_right = pointFromValues(xl, yu) self._lower_left = pointFromValues(xr, yl) elif yl > yu: self._upper_right = pointFromValues(xr, yl) self._lower_left = pointFromValues(xl, yu)
def _normaliseCornerCoords(self): #print self._upper_right xr = self._upper_right.getX() xl = self._lower_left.getX() yu = self._upper_right.getY() yl = self._lower_left.getY() if xl>xr and yl>yu: self._upper_right = pointFromValues(xl,yl) self._lower_left = pointFromValues(xr,yu) elif xl>xr: self._upper_right = pointFromValues(xl,yu) self._lower_left = pointFromValues(xr,yl) elif yl>yu: self._upper_right = pointFromValues(xr,yl) self._lower_left = pointFromValues(xl,yu)