91 |
saver = ProjFileSaver(pf) |
saver = ProjFileSaver(pf) |
92 |
saver.write(pf.GetFilename()) |
saver.write(pf.GetFilename()) |
93 |
|
|
94 |
|
# |
95 |
|
# Constants for the get_system_proj_file function |
96 |
|
# |
97 |
|
|
98 |
def get_system_proj_file(): |
# The default projection file with a few predefined projections |
99 |
"""Return the standard projections and a list with warnings |
DEFAULT_PROJ_FILE = "defaults.proj" |
100 |
|
|
101 |
The projections read from the default thuban projection file |
# The epsg projections. |
102 |
(usually in Resources/Projections/defaults.proj). The return value |
EPSG_PROJ_FILE = "epsg.proj" |
103 |
is a tuple with the projections in a ProjFile object and a list of |
|
104 |
strings with warning messages. The warnings list is usually empty |
# Deprecated EPSG projections. |
105 |
but may contain messages about ignored errors. |
EPSG_DEPRECATED_PROJ_FILE = "epsg-deprecated.proj" |
106 |
|
|
107 |
|
def get_system_proj_file(filename): |
108 |
|
"""Return the projections from the indicated file and a list with warnings |
109 |
|
|
110 |
|
The filename argument should be the name of a file in the directory |
111 |
|
with Thuban's default projection files (Resources/Projections/). If |
112 |
|
possible callers should not use hardwired string literal for the |
113 |
|
name to avoid unnecessary duplication. Instead they should use one |
114 |
|
of the predefined constants, currently DEFAULT_PROJ_FILE, |
115 |
|
EPSG_PROJ_FILE or EPSG_DEPRECATED_PROJ_FILE. |
116 |
|
|
117 |
|
The return value is a tuple with the projections in a ProjFile |
118 |
|
object and a list of strings with warning messages. The warnings |
119 |
|
list is usually empty but may contain messages about ignored errors. |
120 |
|
|
121 |
If the file could could not be opened return an empty projection |
If the file could could not be opened return an empty projection |
122 |
file object set to store data in the default file. |
file object set to store data in the indicated default file. |
123 |
""" |
""" |
124 |
filename = os.path.join(projdir, "defaults.proj") |
fullname = os.path.join(projdir, filename) |
125 |
try: |
try: |
126 |
return read_proj_file(filename) |
return read_proj_file(fullname) |
127 |
except (OSError, IOError, SAXParseException), val: |
except (OSError, IOError, SAXParseException), val: |
128 |
msg = _('Could not read "%s": %s') % (filename, str(val)) |
msg = _('Could not read "%s": %s') % (fullname, str(val)) |
129 |
return ProjFile(filename), [msg] |
return ProjFile(fullname), [msg] |
130 |
|
|
131 |
def get_user_proj_file(): |
def get_user_proj_file(): |
132 |
"""Return the user's projections and a list with warnings |
"""Return the user's projections and a list with warnings |