340 |
y=[] |
y=[] |
341 |
cursor = self.db.cursor() |
cursor = self.db.cursor() |
342 |
try: |
try: |
343 |
stmt = ("SELECT AsText(Envelope(%s)) FROM %s;" |
# Using the extent function is postgis specific. An OGC |
344 |
% (self.geometry_column, self.tablename)) |
# Simple Features compliant solution would be to use a query |
345 |
cursor.execute(stmt) |
# like "SELECT AsText(Envelope(the_geom)) FROM mytable;" and |
346 |
|
# calculate the bounding box by hand from that |
347 |
|
cursor.execute("SELECT extent(%s) FROM %s;" |
348 |
|
% (self.geometry_column, self.tablename)) |
349 |
result = cursor.fetchone() |
result = cursor.fetchone() |
350 |
while result: |
if result: |
351 |
result = result[0] |
(minx, miny), (maxx, maxy) \ |
352 |
# Here we must do some parsing through the result string |
= wellknowntext.parse_wkt_thuban(result[0])[0] |
353 |
# to get the points out of the polygon which representes |
return (minx, miny, maxx, maxy) |
|
# the bounding box The first and the last point of a |
|
|
# polygon are identical |
|
|
result = result.split("(")[2] |
|
|
result = result.split(")")[0] |
|
|
points = result.split(",") |
|
|
del points[4] # Remove the last point |
|
|
for point in points: |
|
|
px, py = point.split() |
|
|
x.append(float(px)) |
|
|
y.append(float(py)) |
|
|
result = cursor.fetchone() |
|
354 |
finally: |
finally: |
355 |
cursor.close() |
cursor.close() |
|
if not x: |
|
|
# Empty table |
|
|
return None |
|
|
return (min(x), min(y), max(x), max(y)) |
|
356 |
|
|
357 |
def Shape(self, shapeid): |
def Shape(self, shapeid): |
358 |
cursor = self.db.cursor() |
cursor = self.db.cursor() |