SHARE
TWEET

Untitled

a guest Apr 12th, 2018 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2.  
  3. import requests
  4. from collections import namedtuple
  5. from lxml import etree
  6. import csv
  7. import sys
  8.  
  9. Bbox = namedtuple('Bbox', ['x_min', 'y_min', 'x_max', 'y_max'])
  10.  
  11. bbox = Bbox(
  12.     x_min = '566732.5126428431',
  13.     x_max = '566866.1271540247',
  14.     y_min = '5934895.9206352',
  15.     y_max = '5935029.535146381'
  16. )
  17.  
  18. url = 'https://geoportal-hamburg.de/geodienste_hamburg_de/HH_WMS_Radverkehrszaehlsaeulen'
  19.  
  20. params = {
  21.     'SERVICE': 'WMS',
  22.     'VERSION': '1.3.0',
  23.     'REQUEST': 'GetFeatureInfo',
  24.     'LAYERS': ','.join(['zaehlstellen']),
  25.     'QUERY_LAYERS': ','.join(['zaehlstellen']),
  26.     'STYLES': ','.join([]),
  27.     'CRS': 'EPSG:25832',
  28.     'BBOX': ','.join(bbox),
  29.     'WIDTH': 101,
  30.     'HEIGHT': 101,
  31.     'FORMAT': 'image/png',
  32.     'INFO_FORMAT': 'text/xml',
  33.     'FEATURE_COUNT': '1',
  34.     'I': '50',
  35.     'J': '50',
  36. }
  37.  
  38. nsmap = {
  39.     'app': 'http://www.deegree.org/app',
  40. }
  41. resp = etree.fromstring(requests.get(url, params=params).content)
  42.  
  43. writer = csv.DictWriter(sys.stdout, ['Messstelle', 'Tag', 'Zeit', 'Anzahl'])
  44. writer.writeheader()
  45.  
  46. for zs in resp.xpath('//app:zaehlsaeulen', namespaces=nsmap):
  47.     name = zs.xpath('app:name/text()', namespaces=nsmap)[0]
  48.     tageslinie = zs.xpath('app:tageslinie/text()', namespaces=nsmap)[0]
  49.     for messung in tageslinie.split('|'):
  50.         tag, zeit, anzahl = messung.split(',')
  51.         writer.writerow({
  52.             'Messstelle': name,
  53.             'Tag': tag,
  54.             'Zeit': zeit,
  55.             'Anzahl': anzahl,
  56.         })
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top