1 |
jan |
1800 |
# Copyright (c) 2003 by Intevation GmbH |
2 |
|
|
# Authors: |
3 |
|
|
# Jan-Oliver Wagner <[email protected]> |
4 |
|
|
# |
5 |
|
|
# This program is free software under the GPL (>=v2) |
6 |
|
|
# Read the file COPYING coming with Thuban for details. |
7 |
|
|
|
8 |
|
|
""" |
9 |
|
|
Convert the epsg file of proj into a python .proj file. |
10 |
|
|
|
11 |
|
|
Call it like: |
12 |
|
|
$ python create_epsg.py > epsg.proj |
13 |
|
|
|
14 |
|
|
This tool assumes the original file of proj ('epsg') to |
15 |
|
|
be present in the standard location of a system wide |
16 |
|
|
installation, i.e. in /usr/share/proj/epsg. |
17 |
|
|
If it is somewhere else, just adapt the path in the code |
18 |
|
|
below. |
19 |
|
|
|
20 |
|
|
The entries in the source file look like this: |
21 |
|
|
|
22 |
|
|
# Anguilla 1957 / British West Indies Grid |
23 |
|
|
<200> +proj=tmerc +lat_0=0.000000000 +lon_0=-62.000000000 +k=0.999500 +x_0=40000 0.000 +y_0=0.000 +ellps=clrk80 +units=m no_defs <> |
24 |
|
|
""" |
25 |
|
|
|
26 |
|
|
__version__ = "$Revision$" |
27 |
|
|
|
28 |
|
|
# this function is copied from Thuban/Model/xmlwriter.py |
29 |
|
|
def escape(data): |
30 |
|
|
"""Escape &, \", ', <, and > in a string of data. |
31 |
|
|
""" |
32 |
|
|
data = data.replace("&", "&") |
33 |
|
|
data = data.replace("<", "<") |
34 |
|
|
data = data.replace(">", ">") |
35 |
|
|
data = data.replace('"', """) |
36 |
|
|
data = data.replace("'", "'") |
37 |
|
|
return data |
38 |
|
|
|
39 |
|
|
print '<?xml version="1.0" encoding="UTF-8"?>' |
40 |
|
|
print '<!DOCTYPE projfile SYSTEM "projectionlist.dtd">' |
41 |
|
|
print '<projectionlist>' |
42 |
|
|
|
43 |
|
|
epsg = open('/usr/share/proj/epsg', 'r').readlines() |
44 |
|
|
|
45 |
|
|
for line in epsg: |
46 |
|
|
if line[0] == '#': |
47 |
|
|
title = line[2:-1] |
48 |
|
|
if line[0] == '<': |
49 |
|
|
elements = line.split(' ') |
50 |
|
|
epsg_nr = elements[0][1:-1] |
51 |
|
|
print ' <projection epsg="%s" name="%s">' % (epsg_nr, escape(title)) |
52 |
|
|
for p in elements[1:-3]: |
53 |
|
|
print ' <parameter value="%s"/>' % escape(p[1:]) |
54 |
|
|
print ' </projection>' |
55 |
|
|
|
56 |
|
|
print '</projectionlist>' |