/[thuban]/branches/WIP-pyshapelib-bramz/test/postgissupport.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/test/postgissupport.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2460 by bh, Wed Dec 15 14:01:04 2004 UTC revision 2543 by bh, Fri Jan 21 16:58:31 2005 UTC
# Line 1  Line 1 
1  # Copyright (C) 2003, 2004 by Intevation GmbH  # Copyright (C) 2003, 2004, 2005 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 251  class PostgreSQLServer: Line 251  class PostgreSQLServer:
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"),
# Line 390  class PostGISDatabase: Line 396  class PostGISDatabase:
396              server -- The PostgreSQLServer instance containing the              server -- The PostgreSQLServer instance containing the
397                  database                  database
398    
399              postgis_sql -- Filename of the postgis.sql file with the              postgis_sql -- Filename of the sql file with the postgis
400                  postgis initialization code                  initialization code
401    
402              dbname -- The name of the database              dbname -- The name of the database
403    
# Line 495  def find_postgis_sql(): Line 501  def find_postgis_sql():
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 or may even use different names.  For
512        instance:
513    
514          postgis 0.7.5        $datadir/contrib/postgis.sql
515          postgis 0.8.1        $datadir/postgis.sql
516          postgis 1.0.0-rc1    $datadir/lwpostgis.sql
517    
518        To support both versions, we look in both places and return the
519        first one found (looking under contrib first).  If the file is not
520        found the return value is None.
521      """      """
522      bindir = run_config_script("pg_config --bindir").strip()      bindir = run_config_script("pg_config --bindir").strip()
523      return os.path.join(bindir, "..", "share", "postgresql",      datadir = os.path.join(bindir, "..", "share", "postgresql")
524                          "contrib", "postgis.sql")      for filename in [os.path.join(datadir, "contrib", "postgis.sql"),
525                         os.path.join(datadir, "postgis.sql"),
526                         os.path.join(datadir, "lwpostgis.sql")]:
527            if os.path.exists(filename):
528                return filename
529    
530    
531  _postgres_server = None  _postgres_server = None
532  def get_test_server():  def get_test_server():
# Line 615  def coords_to_polygon(coords): Line 638  def coords_to_polygon(coords):
638          poly.append(", ".join(["%r %r" % p for p in ring]))          poly.append(", ".join(["%r %r" % p for p in ring]))
639      return "POLYGON((%s))" % "), (".join(poly)      return "POLYGON((%s))" % "), (".join(poly)
640    
641    def coords_to_linestring(coords):
642        """Return string with a LINESTRING WKT representation of coords"""
643        if len(coords) > 1:
644            raise ValueError("A LINESTRING can only have one arc")
645        return "LINESTRING(%s)" % ", ".join(["%r %r" % p for p in coords[0]])
646    
647  def coords_to_multilinestring(coords):  def coords_to_multilinestring(coords):
648      """Return string with a WKT representation of the arc in coords"""      """Return string with a MULTILINESTRING WKT representation of coords"""
649      poly = []      poly = []
650      for ring in coords:      for ring in coords:
651          poly.append(", ".join(["%r %r" % p for p in ring]))          poly.append(", ".join(["%r %r" % p for p in ring]))
# Line 631  def coords_to_multipolygon(coords): Line 660  def coords_to_multipolygon(coords):
660    
661  wkt_converter = {  wkt_converter = {
662      "POINT": coords_to_point,      "POINT": coords_to_point,
663        "LINESTRING": coords_to_linestring,
664      "MULTILINESTRING": coords_to_multilinestring,      "MULTILINESTRING": coords_to_multilinestring,
665      "POLYGON": coords_to_polygon,      "POLYGON": coords_to_polygon,
666      "MULTIPOLYGON": coords_to_multipolygon,      "MULTIPOLYGON": coords_to_multipolygon,
# Line 649  def upload_shapefile(filename, db, table Line 679  def upload_shapefile(filename, db, table
679      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
680                  is to be inserted                  is to be inserted
681    
682      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
683                  of the default that would be chosen based on the type of                  geometry type to use instead of the default that would
684                  the shapefile                  be chosen based on the type of the shapefile
685    
686      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
687                  the gid column (default 0)                  the gid column (default 0)

Legend:
Removed from v.2460  
changed lines
  Added in v.2543

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26