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 _ |
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 |
|
|
98 |
saver = ProjFileSaver(pf) |
saver = ProjFileSaver(pf) |
99 |
saver.write(pf.GetFilename()) |
saver.write(pf.GetFilename()) |
100 |
|
|
101 |
|
# |
102 |
# Constants for the get_system_proj_file function |
# Constants for the get_system_proj_file function |
103 |
|
# |
104 |
|
|
105 |
|
# The default projection file with a few predefined projections |
106 |
DEFAULT_PROJ_FILE = "defaults.proj" |
DEFAULT_PROJ_FILE = "defaults.proj" |
107 |
|
|
108 |
|
# The epsg projections. |
109 |
EPSG_PROJ_FILE = "epsg.proj" |
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): |
def get_system_proj_file(filename): |
115 |
"""Return the projections from the indicated file and a list with warnings |
"""Return the projections from the indicated file and a list with warnings |
116 |
|
|
118 |
with Thuban's default projection files (Resources/Projections/). If |
with Thuban's default projection files (Resources/Projections/). If |
119 |
possible callers should not use hardwired string literal for the |
possible callers should not use hardwired string literal for the |
120 |
name to avoid unnecessary duplication. Instead they should use one |
name to avoid unnecessary duplication. Instead they should use one |
121 |
of the predefined constants, currently DEFAULT_PROJ_FILE or |
of the predefined constants, currently DEFAULT_PROJ_FILE, |
122 |
EPSG_PROJ_FILE. |
EPSG_PROJ_FILE or EPSG_DEPRECATED_PROJ_FILE. |
123 |
|
|
124 |
The return value is a tuple with the projections in a ProjFile |
The return value is a tuple with the projections in a ProjFile |
125 |
object and a list of strings with warning messages. The warnings |
object and a list of strings with warning messages. The warnings |