251 |
[("gid_offset", 1000)]), |
[("gid_offset", 1000)]), |
252 |
("political", os.path.join("..", "Data", "iceland", |
("political", os.path.join("..", "Data", "iceland", |
253 |
"political.shp")), |
"political.shp")), |
254 |
("roads", os.path.join("..", "Data", "iceland", |
("roads_multi", os.path.join("..", "Data", "iceland", |
255 |
"roads-line.shp")), |
"roads-line.shp")), |
256 |
|
|
257 |
|
# same as roads-multi but using LINESTRING instead of |
258 |
|
# MULTILINESTRING |
259 |
|
("roads", os.path.join("..", "Data", "iceland", |
260 |
|
"roads-line.shp"), |
261 |
|
[("force_wkt_type", "LINESTRING")]), |
262 |
|
|
263 |
# The polygon data as a MULTIPOLYGON geometry type |
# The polygon data as a MULTIPOLYGON geometry type |
264 |
("political_multi", os.path.join("..", "Data", "iceland", |
("political_multi", os.path.join("..", "Data", "iceland", |
265 |
"political.shp"), |
"political.shp"), |
501 |
"""Return the name of the postgis_sql file |
"""Return the name of the postgis_sql file |
502 |
|
|
503 |
A postgis installation usually has the postgis_sql file in |
A postgis installation usually has the postgis_sql file in |
504 |
PostgreSQL's datadir (i.e. the directory where PostgreSQL keeps |
PostgreSQL's $datadir (i.e. the directory where PostgreSQL keeps |
505 |
static files, not the directory containing the databases). |
static files, not the directory containing the databases). |
506 |
Unfortunately there's no way to determine the name of this directory |
Unfortunately there's no way to determine the name of this directory |
507 |
with pg_config so we assume here that it's |
with pg_config so we assume here that it's |
508 |
$bindir/../share/postgresql/. |
$bindir/../share/postgresql/. |
509 |
|
|
510 |
|
Furthermore, different versions of postgis place the file in |
511 |
|
slightly different locations. For instance: |
512 |
|
|
513 |
|
postgis 0.7.5 $datadir/contrib/postgis.sql |
514 |
|
postgis 0.8.1 $datadir/postgis.sql |
515 |
|
|
516 |
|
To support both versions, we look in both places and return the |
517 |
|
first one found (looking under contrib first). If the file is not |
518 |
|
found the return value is None. |
519 |
""" |
""" |
520 |
bindir = run_config_script("pg_config --bindir").strip() |
bindir = run_config_script("pg_config --bindir").strip() |
521 |
return os.path.join(bindir, "..", "share", "postgresql", |
datadir = os.path.join(bindir, "..", "share", "postgresql") |
522 |
"contrib", "postgis.sql") |
for filename in [os.path.join(datadir, "contrib", "postgis.sql"), |
523 |
|
os.path.join(datadir, "postgis.sql")]: |
524 |
|
if os.path.exists(filename): |
525 |
|
return filename |
526 |
|
|
527 |
|
|
528 |
_postgres_server = None |
_postgres_server = None |
529 |
def get_test_server(): |
def get_test_server(): |
635 |
poly.append(", ".join(["%r %r" % p for p in ring])) |
poly.append(", ".join(["%r %r" % p for p in ring])) |
636 |
return "POLYGON((%s))" % "), (".join(poly) |
return "POLYGON((%s))" % "), (".join(poly) |
637 |
|
|
638 |
|
def coords_to_linestring(coords): |
639 |
|
"""Return string with a LINESTRING WKT representation of coords""" |
640 |
|
if len(coords) > 1: |
641 |
|
raise ValueError("A LINESTRING can only have one arc") |
642 |
|
return "LINESTRING(%s)" % ", ".join(["%r %r" % p for p in coords[0]]) |
643 |
|
|
644 |
def coords_to_multilinestring(coords): |
def coords_to_multilinestring(coords): |
645 |
"""Return string with a WKT representation of the arc in coords""" |
"""Return string with a MULTILINESTRING WKT representation of coords""" |
646 |
poly = [] |
poly = [] |
647 |
for ring in coords: |
for ring in coords: |
648 |
poly.append(", ".join(["%r %r" % p for p in ring])) |
poly.append(", ".join(["%r %r" % p for p in ring])) |
657 |
|
|
658 |
wkt_converter = { |
wkt_converter = { |
659 |
"POINT": coords_to_point, |
"POINT": coords_to_point, |
660 |
|
"LINESTRING": coords_to_linestring, |
661 |
"MULTILINESTRING": coords_to_multilinestring, |
"MULTILINESTRING": coords_to_multilinestring, |
662 |
"POLYGON": coords_to_polygon, |
"POLYGON": coords_to_polygon, |
663 |
"MULTIPOLYGON": coords_to_multipolygon, |
"MULTIPOLYGON": coords_to_multipolygon, |
676 |
tablename -- The name of the table to create and into which the data |
tablename -- The name of the table to create and into which the data |
677 |
is to be inserted |
is to be inserted |
678 |
|
|
679 |
force_wkt_type -- If given the real WKT geometry type to use instead |
force_wkt_type -- If given and not None, this is used as the WKT |
680 |
of the default that would be chosen based on the type of |
geometry type to use instead of the default that would |
681 |
the shapefile |
be chosen based on the type of the shapefile |
682 |
|
|
683 |
gid_offset -- A number to add to the shapeid to get the value for |
gid_offset -- A number to add to the shapeid to get the value for |
684 |
the gid column (default 0) |
the gid column (default 0) |