comparison flys-backend/contrib/shpimporter/floodmarks.py @ 5545:ed149d5d7fb7

Add floodmarks importer
author Andre Heinecke <aheinecke@intevation.de>
date Wed, 03 Apr 2013 16:33:28 +0200
parents
children
comparison
equal deleted inserted replaced
5544:12f4d088f088 5545:ed149d5d7fb7
1 # -*- coding: utf-8 -*-
2 try:
3 from osgeo import ogr
4 except ImportError:
5 import ogr
6
7 from importer import Importer
8 import logging
9 import os
10 import re
11
12 TABLE_NAME="flood_marks"
13 PATH="Hydrologie/HW-Marken"
14 NAME="Floodmarks"
15
16 logger = logging.getLogger(NAME)
17
18 BUILDING_KINDS= {
19 "sonstige" : 0,
20 "brücken" : 1,
21 "wehre" : 2,
22 "pegel" : 3,
23 }
24
25 class Floodmark(Importer):
26 fieldmap = {
27 "^station$" : "km",
28 "^km$" : "km",
29 "^wsv-km$" : "km",
30 "^FlussKm$" : "km",
31 "^z$" : "z",
32 "^z\d*" : "z", # z02, z1890, usw.
33 "^m+NHN$" : "z",
34 "^Ort$" : "location",
35 "^Pegel$" : "location",
36 }
37
38 def getPath(self, base):
39 return "%s/%s" % (base, PATH)
40
41 def getTablename(self):
42 return TABLE_NAME
43
44 def getName(self):
45 return NAME
46
47 def isGeometryValid(self, geomType):
48 return geomType == ogr.wkbPoint
49
50 def isShapeRelevant(self, name, path):
51 return "hw-marken" in name.lower()
52
53 def createNewFeature(self, featureDef, feat, **args):
54 newFeat = ogr.Feature(featureDef)
55 geometry = feat.GetGeometryRef()
56 geometry.SetCoordinateDimension(2)
57 newFeat.SetGeometry(geometry)
58
59 self.copyFields(feat, newFeat, self.fieldmap)
60
61 newFeat.SetField("river_id", self.river_id)
62
63 filename = os.path.basename(args['path'])
64
65 # Try to extract the year from the filename
66 match = re.search(r"([_\-])(\d\d\d\d)([_\-])", filename)
67 if match:
68 year = match.groups()[1]
69 year = int(year)
70 newFeat.SetField("year", year)
71 else:
72 logger.warn(u"Could not extract year from filename: %s " % filename)
73
74 return newFeat
75

http://dive4elements.wald.intevation.org