Mercurial > dive4elements > river
annotate backend/contrib/shpimporter/jetties.py @ 7602:c50dbbe17950
issue1596: Store table (cell) data twice: Once as (formatted) string
as coming from server, once transformed into float (or string).
The benefit is that now we can sort table data numerically, while keeping
the formatted and i18ned display of values.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 27 Nov 2013 14:55:25 +0100 |
parents | 5aa05a7a34b7 |
children |
rev | line source |
---|---|
5353 | 1 # -*- coding: utf-8 -*- |
2 import os | |
3 | |
4 try: | |
5 from osgeo import ogr | |
6 except ImportError: | |
7 import ogr | |
8 | |
9 from importer import Importer | |
10 import utils | |
11 | |
12 import logging | |
13 logger = logging.getLogger("Jetties") | |
14 | |
15 PATH="Geodaesie/Bauwerke" | |
16 NAME="Jetties" | |
17 | |
18 # strings need to be lowercase | |
5357
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
19 # buhnenkopf 0 |
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
20 # buhnenfuß 1 |
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
21 # buhnenwurzel 2 |
5353 | 22 JETTY_KIND = { |
5357
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
23 "bkl" : 0, |
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
24 "bkr" : 0, |
5384
5a42ca06b93e
Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5357
diff
changeset
|
25 "bk" : 0, |
5357
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
26 "bfl" : 1, |
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
27 "bfr" : 1, |
5384
5a42ca06b93e
Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5357
diff
changeset
|
28 "bf" : 1, |
5357
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
29 "bwl" : 2, |
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
30 "bwr" : 2, |
5384
5a42ca06b93e
Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5357
diff
changeset
|
31 "bw" : 2, |
5353 | 32 } |
33 | |
34 class Jetties(Importer): | |
35 fieldmap = { | |
5384
5a42ca06b93e
Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5357
diff
changeset
|
36 "^station$" : "km", |
5a42ca06b93e
Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5357
diff
changeset
|
37 "^km$" : "km", |
5a42ca06b93e
Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5357
diff
changeset
|
38 "^wsv-km$" : "km", |
5a42ca06b93e
Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5357
diff
changeset
|
39 "^z$" : "z", |
5a42ca06b93e
Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5357
diff
changeset
|
40 "^H[oeö]{0,2}he$" : "z", |
5a42ca06b93e
Importer act according to specs when importing jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5357
diff
changeset
|
41 "^m+NHN$" : "z", |
5353 | 42 } |
43 | |
44 def getPath(self, base): | |
45 return "%s/%s" % (base, PATH) | |
46 | |
47 def getTablename(self): | |
48 return "jetties" | |
49 | |
50 def getName(self): | |
51 return "JETTIES" | |
52 | |
53 def isGeometryValid(self, geomType): | |
54 return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D | |
55 | |
56 def isShapeRelevant(self, name, path): | |
57 if not path.endswith("Buhnen.shp"): | |
58 return False | |
59 shp = ogr.Open(path) | |
60 return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) | |
61 | |
62 def createNewFeature(self, featureDef, feat, **args): | |
63 newFeat = ogr.Feature(featureDef) | |
64 geometry = feat.GetGeometryRef() | |
65 geometry.SetCoordinateDimension(2) | |
66 | |
67 self.copyFields(feat, newFeat, self.fieldmap) | |
68 | |
69 newFeat.SetGeometry(geometry) | |
70 | |
5438
91b14ade2149
Set river_id for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5384
diff
changeset
|
71 newFeat.SetField("river_id", self.river_id) |
91b14ade2149
Set river_id for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5384
diff
changeset
|
72 |
5353 | 73 artname = self.searchField("^type$") |
74 if self.IsFieldSet(feat, artname): | |
75 self.handled(artname) | |
76 kind_id = JETTY_KIND.get(feat.GetField(artname).lower()) | |
5357
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
77 if kind_id == None: |
5353 | 78 logger.warn("Unknown Type: %s" % \ |
79 feat.GetField(artname)) | |
80 else: | |
81 newFeat.SetField("kind_id", kind_id) | |
82 | |
83 return newFeat | |
84 |