5 |
# This program is free software under the GPL (>=v2) |
# This program is free software under the GPL (>=v2) |
6 |
# Read the file COPYING coming with Thuban for details. |
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
8 |
|
"""Handle resources loaded from files such as projections""" |
9 |
|
|
10 |
|
__version__ = "$Revision$" |
11 |
|
# $Source$ |
12 |
|
# $Id$ |
13 |
|
|
14 |
|
|
15 |
import os |
import os |
16 |
import os.path |
import os.path |
17 |
|
|
28 |
projdir = \ |
projdir = \ |
29 |
os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Projections") |
os.path.join(Thuban.__path__[0], os.pardir, "Resources", "Projections") |
30 |
|
|
|
usrdir = get_application_dir() |
|
31 |
|
|
32 |
PROJ_EXT = ".proj" |
PROJ_EXT = ".proj" |
33 |
|
|
34 |
has_gdal_support = lambda: False |
has_gdal_support = lambda: False |
35 |
try: |
try: |
36 |
|
# first try to see if our extension module is there. if it |
37 |
|
# wasn't even compiled, we obviously don't have gdal support. |
38 |
|
import gdalwarp |
39 |
|
|
40 |
|
# now try to import the python extension. if this doesn't |
41 |
|
# exist then we can't do anything. |
42 |
import gdal |
import gdal |
43 |
|
|
44 |
"""Return True if the gdal library is available.""" |
"""Return True if the gdal library is available.""" |
45 |
has_gdal_support = lambda: True |
has_gdal_support = lambda: True |
46 |
except ImportError: |
except ImportError: |
81 |
for file in filter(lambda s: s.endswith(PROJ_EXT), dirlist): |
for file in filter(lambda s: s.endswith(PROJ_EXT), dirlist): |
82 |
try: |
try: |
83 |
filename = os.path.join(dir, file) |
filename = os.path.join(dir, file) |
84 |
list.append(ReadProjFile(filename)) |
list.append(read_proj_file(filename)) |
85 |
except (OSError, IOError, SAXParseException): |
except (OSError, IOError, SAXParseException): |
86 |
pass # just move onto the next file |
pass # just move onto the next file |
87 |
|
|
96 |
""" |
""" |
97 |
filename = os.path.join(projdir, "defaults.proj") |
filename = os.path.join(projdir, "defaults.proj") |
98 |
try: |
try: |
99 |
return [ReadProjFile(filename)] |
return [read_proj_file(filename)] |
100 |
except (OSError, IOError, SAXParseException): |
except (OSError, IOError, SAXParseException): |
101 |
return [ProjFile(filename)] |
return [ProjFile(filename)] |
102 |
|
|
107 |
empty projection file set to store data in the default file. |
empty projection file set to store data in the default file. |
108 |
""" |
""" |
109 |
|
|
110 |
|
usrdir = get_application_dir() |
111 |
filename = os.path.join(usrdir, "user.proj") |
filename = os.path.join(usrdir, "user.proj") |
112 |
try: |
try: |
113 |
return [ReadProjFile(filename)] |
return [read_proj_file(filename)] |
114 |
except (OSError, IOError, SAXParseException): |
except (OSError, IOError, SAXParseException): |
115 |
return [ProjFile(filename)] |
return [ProjFile(filename)] |
116 |
|
|