Mercurial > dive4elements > river
annotate flys-backend/contrib/shpimporter/jetties.py @ 5368:d3f170484455
MainValuesArtifact: Doc, cosmetics.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 22 Mar 2013 09:06:32 +0100 |
parents | 776427b5aa76 |
children | 5a42ca06b93e |
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, |
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
25 "bfl" : 1, |
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
26 "bfr" : 1, |
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
27 "bwl" : 2, |
776427b5aa76
Add updated type mapping for jetties
Andre Heinecke <aheinecke@intevation.de>
parents:
5353
diff
changeset
|
28 "bwr" : 2, |
5353 | 29 } |
30 | |
31 class Jetties(Importer): | |
32 fieldmap = { | |
33 "^station$" : "km", | |
34 "^z$" : "z", | |
35 } | |
36 | |
37 def getPath(self, base): | |
38 return "%s/%s" % (base, PATH) | |
39 | |
40 def getTablename(self): | |
41 return "jetties" | |
42 | |
43 def getName(self): | |
44 return "JETTIES" | |
45 | |
46 def isGeometryValid(self, geomType): | |
47 return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D | |
48 | |
49 def isShapeRelevant(self, name, path): | |
50 if not path.endswith("Buhnen.shp"): | |
51 return False | |
52 shp = ogr.Open(path) | |
53 return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType()) | |
54 | |
55 def createNewFeature(self, featureDef, feat, **args): | |
56 newFeat = ogr.Feature(featureDef) | |
57 geometry = feat.GetGeometryRef() | |
58 geometry.SetCoordinateDimension(2) | |
59 | |
60 self.copyFields(feat, newFeat, self.fieldmap) | |
61 | |
62 newFeat.SetGeometry(geometry) | |
63 | |
64 artname = self.searchField("^type$") | |
65 if self.IsFieldSet(feat, artname): | |
66 self.handled(artname) | |
67 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
|
68 if kind_id == None: |
5353 | 69 logger.warn("Unknown Type: %s" % \ |
70 feat.GetField(artname)) | |
71 else: | |
72 newFeat.SetField("kind_id", kind_id) | |
73 | |
74 return newFeat | |
75 |