annotate flys-backend/contrib/shpimporter/jetties.py @ 5369:a0c807165bcd

FacetTypes: Add two new Facet types for mainvalues in hist. w/q diagrams.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Fri, 22 Mar 2013 09:07:22 +0100
parents 776427b5aa76
children 5a42ca06b93e
rev   line source
5353
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2 import os
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4 try:
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 from osgeo import ogr
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6 except ImportError:
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7 import ogr
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9 from importer import Importer
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10 import utils
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 import logging
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 logger = logging.getLogger("Jetties")
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 PATH="Geodaesie/Bauwerke"
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 NAME="Jetties"
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
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
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
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
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
29 }
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 class Jetties(Importer):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 fieldmap = {
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
33 "^station$" : "km",
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34 "^z$" : "z",
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 }
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
37 def getPath(self, base):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
38 return "%s/%s" % (base, PATH)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
39
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40 def getTablename(self):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 return "jetties"
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
42
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
43 def getName(self):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
44 return "JETTIES"
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 def isGeometryValid(self, geomType):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
47 return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
48
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49 def isShapeRelevant(self, name, path):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 if not path.endswith("Buhnen.shp"):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51 return False
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 shp = ogr.Open(path)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53 return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType())
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
55 def createNewFeature(self, featureDef, feat, **args):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 newFeat = ogr.Feature(featureDef)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57 geometry = feat.GetGeometryRef()
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58 geometry.SetCoordinateDimension(2)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 self.copyFields(feat, newFeat, self.fieldmap)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 newFeat.SetGeometry(geometry)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64 artname = self.searchField("^type$")
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 if self.IsFieldSet(feat, artname):
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66 self.handled(artname)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
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
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 logger.warn("Unknown Type: %s" % \
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 feat.GetField(artname))
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71 else:
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
72 newFeat.SetField("kind_id", kind_id)
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 return newFeat
d086ce6c13d3 Add jetties importer
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75

http://dive4elements.wald.intevation.org