annotate flys-backend/contrib/shpimporter/hws.py @ 5003:563ff8893d47 dami

Importer: Fix fieldname of "official" in the new feature and set it based on the filename as a fallback
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 15 Feb 2013 15:03:48 +0100
parents baa32f1df47d
children 769593a84606
rev   line source
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
1 # -*- coding: utf-8 -*-
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
2 import os
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
3
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
4 try:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
5 from osgeo import ogr
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
6 except ImportErrror:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
7 import ogr
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9 from importer import Importer
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
10 import utils
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12 PATH="Hydrologie/HW-Schutzanlagen"
3654
59ca5dab2782 Shape importer: use python's OptionParse to read user specific configuration from command line.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2862
diff changeset
13 NAME="HWS"
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
15 # Keep in sync with hws_kinds table:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
16 HWS_KIND = {
5002
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
17 "durchlass" : 1,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
18 "damm" : 2,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
19 "deich" : 2,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
20 "hochufer" : 2,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
21 "graben" : 3,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
22 "rohr1" : 1,
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
23 }
2862
998f1a7dcfde New shape importers and schema modifications.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
25 # Keep in sync with fed_states table:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
26 FED_STATES = {
5002
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
27 "bayern" : 1,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
28 "hessen" : 2,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
29 "niedersachsen" : 3,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
30 "nordrhein-westfalen" : 4,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
31 "nordrhein westfalen" : 4,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
32 "rheinland-pfalz" : 5,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
33 "rheinland pfalz" : 5,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
34 "saarland" : 6,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
35 "schleswig-holstein" : 7,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
36 "schleswig holstein" : 7,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
37 "brandenburg" : 8,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
38 "mecklenburg-vorpommern" : 9,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
39 "mecklenburg vorpommern" : 9,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
40 "thüringen" : 10,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
41 "baden-württemberg" : 11,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
42 "baden württemberg" : 11,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
43 "sachsen-anhalt" : 12,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
44 "sachsen anhalt" : 12,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
45 "sachsen" : 13,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
46 "berlin" : 14,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
47 "bremen" : 15,
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
48 "hamburg" : 16,
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
49 }
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
50
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
51 class HWSPoints(Importer):
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
52 fieldmap = {
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
53 "name$" : "name",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
54 "quelle$" : "source",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
55 "anmerkung$" : "description",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
56 "stand$" : "status_date",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
57 "verband$" : "agency",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
58 "Deich_{0,1}KM$" : "dike_km",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
59 "Bereich$" : "range",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
60 "H[oeö]{0,2}he_{0,1}SOLL$" : "z_target",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
61 "(WSP_){0,1}BfG_{0,1}100$" : "rated_level",
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
62 "H[oeö]{0,2}he_{0,1}IST$" : "z",
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
63 }
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
64
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
65 def getPath(self, base):
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
66 return "%s/%s" % (base, PATH)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
67
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
68 def getTablename(self):
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
69 return "hws_points"
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
70
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
71 def getName(self):
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
72 return "HWS_POINTS"
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
73
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
74 def isGeometryValid(self, geomType):
4934
11b459a3eb5c Importer: Import hws_points based on geom type
Andre Heinecke <aheinecke@intevation.de>
parents: 4933
diff changeset
75 return geomType == ogr.wkbPoint or geomType == ogr.wkbPoint25D
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
76
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
77 def isShapeRelevant(self, name, path):
4934
11b459a3eb5c Importer: Import hws_points based on geom type
Andre Heinecke <aheinecke@intevation.de>
parents: 4933
diff changeset
78 shp = ogr.Open(path)
4955
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
79 return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType())
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
80
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
81 def createNewFeature(self, featureDef, feat, **args):
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
82 newFeat = ogr.Feature(featureDef)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
83 geometry = feat.GetGeometryRef()
4881
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
84 geometry.SetCoordinateDimension(2)
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
85
4884
b457532dae63 Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents: 4881
diff changeset
86 self.copyFields(feat, newFeat, self.fieldmap)
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
87
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
88 newFeat.SetGeometry(geometry)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
89
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
90 newFeat.SetField("ogr_fid", feat.GetFID())
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
91 artname = self.searchField("art$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
92 if self.IsFieldSet(feat, artname):
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
93 self.handled(artname)
5002
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
94 kind_id = HWS_KIND.get(feat.GetField(artname).lower())
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
95 if not kind_id:
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
96 print ("Unknown Art: %s" % \
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
97 feat.GetField(artname))
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
98 else:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
99 newFeat.SetField("kind_id", kind_id)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
100
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
101 fname = self.searchField("Bundesland$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
102 if self.IsFieldSet(feat, fname):
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
103 self.handled(fname)
5002
baa32f1df47d Importer HWS: case insensitive matching for HWS_KIND and FED_STATES
Andre Heinecke <aheinecke@intevation.de>
parents: 4955
diff changeset
104 fed_id = FED_STATES.get(feat.GetField(fname).lower())
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
105
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
106 if not fed_id:
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
107 print ("Unknown Bundesland: %s" % \
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
108 feat.GetField("Bundesland"))
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
109 else:
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
110 newFeat.SetField("fed_state_id", fed_id)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
111
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
112 fname = self.searchField("(ufer$)|(flussseite$)")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
113 if self.IsFieldSet(feat, fname):
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
114 self.handled(fname)
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
115 shoreString = feat.GetField(fname)
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
116 if "links" in shoreString.lower():
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
117 newFeat.SetField("shore_side", True)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
118 elif "rechts" in shoreString.lower():
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
119 newFeat.SetField("shore_side", False)
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
120
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
121
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
122 fname = self.searchField("river_{0,1}id$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
123 if self.IsFieldSet(feat, fname):
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
124 self.handled(fname)
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
125 if feat.GetField(fname) != self.river_id:
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
126 print ("River_id mismatch between shapefile and"
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
127 " importer parameter.")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
128 newFeat.SetField("river_id", feat.GetField(fname))
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
129 else:
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
130 newFeat.SetField("river_id", self.river_id)
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
131
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
132 fname = self.searchField("name$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
133 if not self.IsFieldSet(feat, fname):
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
134 newFeat.SetField("name", args['name'])
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
135
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
136 fname = self.searchField("offiziell$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
137 if self.IsFieldSet(feat, fname):
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
138 self.handled(fname)
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
139 offiziell = feat.GetField(fname)
4881
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
140 if offiziell == "1" or offiziell == 1:
5003
563ff8893d47 Importer: Fix fieldname of "official" in the new feature and set it
Andre Heinecke <aheinecke@intevation.de>
parents: 5002
diff changeset
141 newFeat.SetField("official", True)
4881
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
142 else:
5003
563ff8893d47 Importer: Fix fieldname of "official" in the new feature and set it
Andre Heinecke <aheinecke@intevation.de>
parents: 5002
diff changeset
143 newFeat.SetField("official", False)
563ff8893d47 Importer: Fix fieldname of "official" in the new feature and set it
Andre Heinecke <aheinecke@intevation.de>
parents: 5002
diff changeset
144 # Set the official value based on the file name as a fallback
563ff8893d47 Importer: Fix fieldname of "official" in the new feature and set it
Andre Heinecke <aheinecke@intevation.de>
parents: 5002
diff changeset
145 elif args.get("name", "").lower() == "rohre_und_sperren" or \
563ff8893d47 Importer: Fix fieldname of "official" in the new feature and set it
Andre Heinecke <aheinecke@intevation.de>
parents: 5002
diff changeset
146 args.get("name", "").lower() == "rohre-und-sperren":
563ff8893d47 Importer: Fix fieldname of "official" in the new feature and set it
Andre Heinecke <aheinecke@intevation.de>
parents: 5002
diff changeset
147 newFeat.SetField("official", True)
4881
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
148
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
149 if self.IsFieldSet(newFeat, "z") and \
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
150 self.IsFieldSet(newFeat, "rated_level"):
4935
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
151 fname = self.searchField("freibord(_m){0,1}$")
c0a58558b817 Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents: 4934
diff changeset
152 self.handled(fname)
4881
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
153 z = newFeat.GetFieldAsDouble("z")
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
154 rl = newFeat.GetFieldAsDouble("rated_level")
9b03cf6b85c9 (importer) calculate freeboard and expect sql
Andre Heinecke <aheinecke@intevation.de>
parents: 4875
diff changeset
155 newFeat.SetField("freeboard", z - rl)
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
156
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
157 return newFeat
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
158
4955
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
159 class HWSLines(HWSPoints):
4875
37fa93f65971 (importer) Add classes for hws_points and hws_lines
Andre Heinecke <aheinecke@intevation.de>
parents: 3654
diff changeset
160
4955
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
161 # TODO: GEOM_target, GEOM_rated_level, dike_km_from, dike_km_to
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
162 fieldmap = {
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
163 "name$" : "name",
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
164 "quelle$" : "source",
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
165 "anmerkung$" : "description",
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
166 "stand$" : "status_date",
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
167 "verband$" : "agency",
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
168 "Bereich$" : "range",
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
169 }
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
170
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
171 def getPath(self, base):
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
172 return "%s/%s" % (base, PATH)
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
173
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
174 def getTablename(self):
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
175 return "hws_lines"
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
176
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
177 def getName(self):
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
178 return "HWS_LINES"
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
179
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
180 def isGeometryValid(self, geomType):
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
181 return geomType == ogr.wkbLineString or geomType == ogr.wkbLineString25D
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
182
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
183 def isShapeRelevant(self, name, path):
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
184 shp = ogr.Open(path)
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
185 return self.isGeometryValid(shp.GetLayerByName(name).GetGeomType())
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
186
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
187 def createNewFeature(self, featureDef, feat, **args):
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
188 newFeat = HWSPoints.createNewFeature(self, featureDef, feat, **args)
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
189 geometry = feat.GetGeometryRef()
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
190 geometry.SetCoordinateDimension(3)
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
191 newFeat.SetGeometry(geometry)
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
192
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
193 return newFeat
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
194
7323847fa7df Importer: Add HWS lines stub. Needs some example data to finish
Andre Heinecke <aheinecke@intevation.de>
parents: 4935
diff changeset
195

http://dive4elements.wald.intevation.org