Last change
on this file since 8682 was 8622, checked in by rick, 14 years ago |
- Haasje over tussen verschillende functies in files om ze op de juiste locatie te zetten.
- staticDNS.yaml is makkelijker te parsen en better te lezen
|
File size:
1.3 KB
|
Rev | Line | |
---|
[8622] | 1 | CACHE_FILE = '/tmp/rd2etrs.yaml'
|
---|
| 2 | coordinates = None
|
---|
| 3 |
|
---|
| 4 | def etrs2rd(lam, phi):
|
---|
| 5 | """ Convert etrs to rd """
|
---|
| 6 |
|
---|
| 7 | item['lam'] = lam
|
---|
| 8 | item['phi'] = phi
|
---|
| 9 | item['func'] = 'etrs2rd'
|
---|
| 10 | url = 'http://vanderzwet.net/rdnap/%(func)s/%(xrd)s/%(yrd)s/0/' % item
|
---|
| 11 |
|
---|
| 12 | f = urllib.urlopen(url)
|
---|
| 13 | raw = f.read()
|
---|
| 14 |
|
---|
| 15 | rdnap_x,rdnap_y,rdnap_h = raw.split('/')
|
---|
| 16 | return (rdnap_x, rdnap_y)
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | def rd2etrs(xrd, yrd, hnap=0.0):
|
---|
| 21 | """
|
---|
| 22 | Convert rd to etrs
|
---|
| 23 | JavaScript Version: https://rdinfo.kadaster.nl/rd/transformator.html
|
---|
| 24 | """
|
---|
| 25 | # Get cache is exists
|
---|
| 26 | global coordinates
|
---|
| 27 | if coordinates == None:
|
---|
| 28 | try:
|
---|
| 29 | coordinates = get_yaml(CACHE_FILE)
|
---|
| 30 | except (IOError,AttributeError):
|
---|
| 31 | coordinates = dict()
|
---|
| 32 | pass
|
---|
| 33 |
|
---|
| 34 | # Check if item in cache
|
---|
| 35 | xrd = float(str(xrd))
|
---|
| 36 | yrd = float(str(yrd))
|
---|
| 37 | if coordinates.has_key((xrd, yrd)):
|
---|
| 38 | return coordinates[(xrd, yrd)]
|
---|
| 39 |
|
---|
| 40 | # Get new coordinate
|
---|
| 41 | item = dict()
|
---|
| 42 | item['xrd'] = xrd
|
---|
| 43 | item['yrd'] = yrd
|
---|
| 44 | item['hnap'] = hnap
|
---|
| 45 | item['func'] = 'rd2etrs'
|
---|
| 46 | url = 'http://vanderzwet.net/rdnap/%(func)s/%(xrd)s/%(yrd)s/%(hnap)s/' % item
|
---|
| 47 | print "### Not in Cache, Fetching coordinate %s, %s from %s" % (xrd, yrd, url)
|
---|
| 48 | f = urllib.urlopen(url)
|
---|
| 49 | raw = f.read()
|
---|
| 50 |
|
---|
| 51 | lam,phi,h = raw.split('/')
|
---|
| 52 | coordinates[(xrd, yrd)] = (lam, phi)
|
---|
| 53 | write_yaml(CACHE_FILE, coordinates)
|
---|
| 54 | return (lam, phi)
|
---|
Note:
See
TracBrowser
for help on using the repository browser.