1 |
# Copyright (C) 2003 by Intevation GmbH |
# Copyright (C) 2003, 2004 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Martin Mueller <[email protected]> |
# Martin Mueller <[email protected]> |
4 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
41 |
"""Return a quoted version of the identifier ident. |
"""Return a quoted version of the identifier ident. |
42 |
|
|
43 |
The return value is a string that can be put directly into an SQL |
The return value is a string that can be put directly into an SQL |
44 |
statement. The quoted identifier is surrounded by double quotes and |
statement. The quoted identifier is surrounded by double quotes and |
45 |
any double quotes alread in the input value are converted to two |
any double quotes already in the input value are converted to two |
46 |
double quotes. Examples: |
double quotes. Examples: |
47 |
|
|
48 |
>>> quote_identifier("abc\"def") |
>>> quote_identifier("abc\"def") |
49 |
'"abc""def"' |
'"abc""def"' |
381 |
|
|
382 |
"""Shapestore interface to a table in a PostGIS database""" |
"""Shapestore interface to a table in a PostGIS database""" |
383 |
|
|
384 |
|
def _fetch_table_information(self): |
385 |
|
"""Extend inherited method to retrieve the SRID""" |
386 |
|
PostGISTable._fetch_table_information(self) |
387 |
|
cursor = self.db.cursor() |
388 |
|
cursor.execute("SELECT srid FROM geometry_columns" |
389 |
|
" WHERE f_table_name = %s", (self.tablename,)) |
390 |
|
self.srid = cursor.fetchone()[0] |
391 |
|
|
392 |
def Table(self): |
def Table(self): |
393 |
"""Return self since a PostGISShapeStore is its own table.""" |
"""Return self since a PostGISShapeStore is its own table.""" |
394 |
return self |
return self |
433 |
cursor.execute("SELECT extent(%s) FROM %s;" |
cursor.execute("SELECT extent(%s) FROM %s;" |
434 |
% (self.quoted_geo_col, self.quoted_tablename)) |
% (self.quoted_geo_col, self.quoted_tablename)) |
435 |
result = cursor.fetchone() |
result = cursor.fetchone() |
436 |
if result: |
if result[0]: |
437 |
(minx, miny), (maxx, maxy) \ |
(minx, miny), (maxx, maxy) \ |
438 |
= wellknowntext.parse_wkt_thuban(result[0])[0] |
= wellknowntext.parse_wkt_thuban(result[0])[0] |
439 |
return (minx, miny, maxx, maxy) |
return (minx, miny, maxx, maxy) |
468 |
left, bottom)) |
left, bottom)) |
469 |
cursor = self.db.cursor() |
cursor = self.db.cursor() |
470 |
cursor.execute("SELECT gid, AsText(%s) FROM %s" |
cursor.execute("SELECT gid, AsText(%s) FROM %s" |
471 |
" WHERE %s && GeometryFromText('%s', -1) ORDER BY gid" |
" WHERE %s && GeometryFromText('%s', %d) ORDER BY gid" |
472 |
% (self.quoted_geo_col, self.quoted_tablename, |
% (self.quoted_geo_col, self.quoted_tablename, |
473 |
self.quoted_geo_col, geom)) |
self.quoted_geo_col, geom, self.srid)) |
474 |
while 1: |
while 1: |
475 |
result = cursor.fetchone() |
result = cursor.fetchone() |
476 |
if result is None: |
if result is None: |