comparison backend/contrib/shpimporter/boundaries.py @ 5838:5aa05a7a34b7

Rename modules to more fitting names.
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 15:23:37 +0200
parents flys-backend/contrib/shpimporter/boundaries.py@148365ff484d
children d5e95f926d13
comparison
equal deleted inserted replaced
5837:d9901a08d0a6 5838:5aa05a7a34b7
1 try:
2 from osgeo import ogr
3 except ImportError:
4 import ogr
5
6 from importer import Importer
7 import utils
8
9 TABLE_NAME="hydr_boundaries"
10 TABLE_NAME_POLY="hydr_boundaries_poly"
11 PATH="Hydrologie/Hydr.Grenzen"
12 NAME="Hydr. Boundaries"
13
14
15 class HydrBoundary(Importer):
16
17 def getPath(self, base):
18 return "%s/%s" % (base, PATH)
19
20 def getTablename(self):
21 return TABLE_NAME
22
23 def getName(self):
24 return NAME
25
26 def isGeometryValid(self, geomType):
27 return geomType in [ogr.wkbLineString,
28 ogr.wkbLineString25D,
29 ogr.wkbMultiLineString25D,
30 ogr.wkbMultiLineString]
31
32 def isShapeRelevant(self, name, path):
33 shp = ogr.Open(path)
34 if self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) and \
35 self.getKind(path) > 0 and not "talaue" in path.lower():
36 return True
37 else:
38 return False
39
40 def getKind(self, path):
41 if "linien/bfg" in path.lower():
42 return 1
43 elif "linien/land" in path.lower():
44 return 2
45 elif "/sonstige/" in path.lower():
46 return 3
47 else:
48 return 0
49
50 def createNewFeature(self, featureDef, feat, **args):
51 kind = self.getKind(args['path'])
52
53 newFeat = ogr.Feature(featureDef)
54 geometry = feat.GetGeometryRef()
55 geometry.SetCoordinateDimension(3)
56
57 newFeat.SetGeometry(geometry)
58 newFeat.SetField("name", args['name'])
59 newFeat.SetField("kind", kind)
60 if self.IsFieldSet(feat, "SECTIE"):
61 newFeat.SetField("sectie", feat.GetField("SECTIE"))
62
63 if self.IsFieldSet(feat, "STROVOER"):
64 newFeat.SetField("sobek", feat.GetField("STROVOER"))
65
66 if self.IsFieldSet(feat, "river_id"):
67 newFeat.SetField("river_id", feat.GetField("river_id"))
68 else:
69 newFeat.SetField("river_id", self.river_id)
70
71 return utils.convertToMultiLine(newFeat)
72
73 class HydrBoundaryPoly(HydrBoundary):
74
75 def getTablename(self):
76 return TABLE_NAME_POLY
77
78 def getName(self):
79 return "%s (Polygons)" % NAME
80
81 def isGeometryValid(self, geomType):
82 return geomType == ogr.wkbPolygon or geomType == ogr.wkbMultiPolygon
83
84 def isShapeRelevant(self, name, path):
85 shp = ogr.Open(path)
86 if self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) and \
87 self.getKind(path) > 0:
88 return True
89 else:
90 return False
91
92 def createNewFeature(self, featureDef, feat, **args):
93 kind = self.getKind(args['path'])
94
95 newFeat = ogr.Feature(featureDef)
96 geometry = feat.GetGeometryRef()
97 geometry.SetCoordinateDimension(2)
98
99 newFeat.SetGeometry(geometry)
100 newFeat.SetField("name", args['name'])
101 newFeat.SetField("kind", kind)
102
103 if self.IsFieldSet(feat, "SECTIE"):
104 newFeat.SetField("sectie", feat.GetField("SECTIE"))
105
106 if self.IsFieldSet(feat, "SOBEK"):
107 newFeat.SetField("sobek", feat.GetField("SOBEK"))
108
109 if self.IsFieldSet(feat, "river_id"):
110 newFeat.SetField("river_id", feat.GetField("river_id"))
111 else:
112 newFeat.SetField("river_id", self.river_id)
113
114 return utils.convertToMultiPolygon(newFeat)
115

http://dive4elements.wald.intevation.org