/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/resource.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/resource.py

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

trunk/thuban/Thuban/Model/resource.py revision 1830 by bh, Thu Oct 16 16:36:00 2003 UTC branches/WIP-pyshapelib-bramz/Thuban/Model/resource.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 UTC
# Line 15  __version__ = "$Revision$" Line 15  __version__ = "$Revision$"
15  import os  import os
16  import os.path  import os.path
17  import weakref  import weakref
18    import traceback
19    
20  import Thuban  import Thuban
21  from Thuban import _  from Thuban import _
# Line 32  projdir = \ Line 33  projdir = \
33    
34  PROJ_EXT = ".proj"  PROJ_EXT = ".proj"
35    
36  has_gdal_support = lambda: False  # Determine the status of GDAL support. If GDAL is supported
37  try:  # gdal_support_status will be set to the empty string, otherwise to a
38      # first try to see if our extension module is there. if it  # string with information why it isn't supported
39      # wasn't even compiled, we obviously don't have gdal support.  #
40      import gdalwarp  # GDAL is supported if we can import both the thuban specific gdalwarp
41    # module and the GDAL python bindings.
42      # now try to import the python extension. if this doesn't  for _module in ("gdalwarp", "gdal"):
43      # exist then we can't do anything.      try:
44      import gdal          __import__(_module)
45        except ImportError, val:
46      """Return True if the gdal library is available."""          gdal_support_status = (_("No GDAL support because module '%s'"
47      has_gdal_support = lambda: True                                   " cannot be imported. Python exception: '%s'")
48  except ImportError:                                 % (_module, str(val)))
49      pass          break
50    else:
51        gdal_support_status = ""
52    
53    def has_gdal_support():
54        return gdal_support_status == ""
55    
56    
57  projfile_cache = weakref.WeakValueDictionary()  projfile_cache = weakref.WeakValueDictionary()
58    
# Line 91  def write_proj_file(pf): Line 98  def write_proj_file(pf):
98      saver = ProjFileSaver(pf)      saver = ProjFileSaver(pf)
99      saver.write(pf.GetFilename())      saver.write(pf.GetFilename())
100    
101    #
102  def get_system_proj_file():  # Constants for the get_system_proj_file function
103      """Return the standard projections and a list with warnings  #
104    
105      The projections read from the default thuban projection file  # The default projection file with a few predefined projections
106      (usually in Resources/Projections/defaults.proj). The return value  DEFAULT_PROJ_FILE = "defaults.proj"
107      is a tuple with the projections in a ProjFile object and a list of  
108      strings with warning messages. The warnings list is usually empty  # The epsg projections.
109      but may contain messages about ignored errors.  EPSG_PROJ_FILE = "epsg.proj"
110    
111    # Deprecated EPSG projections.
112    EPSG_DEPRECATED_PROJ_FILE = "epsg-deprecated.proj"
113    
114    def get_system_proj_file(filename):
115        """Return the projections from the indicated file and a list with warnings
116    
117        The filename argument should be the name of a file in the directory
118        with Thuban's default projection files (Resources/Projections/). If
119        possible callers should not use hardwired string literal for the
120        name to avoid unnecessary duplication. Instead they should use one
121        of the predefined constants, currently DEFAULT_PROJ_FILE,
122        EPSG_PROJ_FILE or EPSG_DEPRECATED_PROJ_FILE.
123    
124        The return value is a tuple with the projections in a ProjFile
125        object and a list of strings with warning messages. The warnings
126        list is usually empty but may contain messages about ignored errors.
127    
128      If the file could could not be opened return an empty projection      If the file could could not be opened return an empty projection
129      file object set to store data in the default file.      file object set to store data in the indicated default file.
130      """      """
131      filename = os.path.join(projdir, "defaults.proj")      fullname = os.path.join(projdir, filename)
132      try:      try:
133          return read_proj_file(filename)          return read_proj_file(fullname)
134      except (OSError, IOError, SAXParseException), val:      except (OSError, IOError, SAXParseException), val:
135          msg = _('Could not read "%s": %s') % (filename, str(val))          msg = _('Could not read "%s": %s') % (fullname, str(val))
136          return ProjFile(filename), [msg]          return ProjFile(fullname), [msg]
137    
138  def get_user_proj_file():  def get_user_proj_file():
139      """Return the user's projections and a list with warnings      """Return the user's projections and a list with warnings

Legend:
Removed from v.1830  
changed lines
  Added in v.2734

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26