Mercurial > dive4elements > river
annotate flys-backend/contrib/shpimporter/importer.py @ 5403:e1cd77ddcbc4
Generalize parsing of ids data string
author | Andre Heinecke <aheinecke@intevation.de> |
---|---|
date | Mon, 25 Mar 2013 15:01:16 +0100 |
parents | ff11b178f152 |
children | db5def5456ce |
rev | line source |
---|---|
4872
a563e9f58f93
Improve error handling and unify dbconn for all importers
Andre Heinecke <aheinecke@intevation.de>
parents:
4871
diff
changeset
|
1 try: |
5004
f1c01fecf194
Fix imports of ogr, this removes a warning in gdal 1.9 but keeps
Andre Heinecke <aheinecke@intevation.de>
parents:
5001
diff
changeset
|
2 from osgeo import ogr, osr |
5077
c5187ab9f571
Fix Syntax Errror
Andre Heinecke <aheinecke@intevation.de>
parents:
5006
diff
changeset
|
3 except ImportError: |
5004
f1c01fecf194
Fix imports of ogr, this removes a warning in gdal 1.9 but keeps
Andre Heinecke <aheinecke@intevation.de>
parents:
5001
diff
changeset
|
4 import ogr, osr |
4877
852d4c508f33
(importer) Try to convert paths to UTF-8 for DB insertion
Andre Heinecke <aheinecke@intevation.de>
parents:
4876
diff
changeset
|
5 import utils |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
6 import re |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
7 import logging |
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
8 |
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
9 logger = logging.getLogger("importer") |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 class Importer: |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
4970
174fbaa3d344
Add handling of River Names and remove target_src parameter
Andre Heinecke <aheinecke@intevation.de>
parents:
4951
diff
changeset
|
13 def __init__(self, river_id, dbconn, dry_run): |
174fbaa3d344
Add handling of River Names and remove target_src parameter
Andre Heinecke <aheinecke@intevation.de>
parents:
4951
diff
changeset
|
14 self.river_id = river_id |
4872
a563e9f58f93
Improve error handling and unify dbconn for all importers
Andre Heinecke <aheinecke@intevation.de>
parents:
4871
diff
changeset
|
15 self.dbconn = dbconn |
4970
174fbaa3d344
Add handling of River Names and remove target_src parameter
Andre Heinecke <aheinecke@intevation.de>
parents:
4951
diff
changeset
|
16 self.dry_run = dry_run |
2861
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
17 self.dest_srs = osr.SpatialReference() |
4970
174fbaa3d344
Add handling of River Names and remove target_src parameter
Andre Heinecke <aheinecke@intevation.de>
parents:
4951
diff
changeset
|
18 self.dest_srs.ImportFromEPSG(31467) |
4884
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
19 self.handled_fields = [] |
4885
89a8764cabcc
Importer: Only show imported fields if copy_fields is used
Andre Heinecke <aheinecke@intevation.de>
parents:
4884
diff
changeset
|
20 self.tracking_import = False |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
21 self.srcLayer = None |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
22 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 def getKind(self, path): |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 raise NotImplementedError("Importer.getKind is abstract!") |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 def getPath(self, base): |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 raise NotImplementedError("Importer.getPath is abstract!") |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 def getTablename(self): |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 raise NotImplementedError("Importer.getTablename is abstract!") |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
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
|
32 def getName(self): |
5160
0dae9e77c5da
Importer fix issues reported by pylint
Andre Heinecke <aheinecke@intevation.de>
parents:
5077
diff
changeset
|
33 raise NotImplementedError("Importer.getName is abstract!") |
0dae9e77c5da
Importer fix issues reported by pylint
Andre Heinecke <aheinecke@intevation.de>
parents:
5077
diff
changeset
|
34 |
0dae9e77c5da
Importer fix issues reported by pylint
Andre Heinecke <aheinecke@intevation.de>
parents:
5077
diff
changeset
|
35 def isGeometryValid(self, geomType): |
0dae9e77c5da
Importer fix issues reported by pylint
Andre Heinecke <aheinecke@intevation.de>
parents:
5077
diff
changeset
|
36 raise NotImplementedError("Importer.isGeometryValid is abstract!") |
0dae9e77c5da
Importer fix issues reported by pylint
Andre Heinecke <aheinecke@intevation.de>
parents:
5077
diff
changeset
|
37 |
0dae9e77c5da
Importer fix issues reported by pylint
Andre Heinecke <aheinecke@intevation.de>
parents:
5077
diff
changeset
|
38 def createNewFeature(self, featureDef, feat, **args): |
0dae9e77c5da
Importer fix issues reported by pylint
Andre Heinecke <aheinecke@intevation.de>
parents:
5077
diff
changeset
|
39 raise NotImplementedError("Importer.createNewFeature is abstract!") |
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
|
40 |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 def IsFieldSet(self, feat, name): |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
42 if not name: |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
43 return False |
4878
82d00b0c7302
(importer) Avoid uneccessary error and improve debug output
Andre Heinecke <aheinecke@intevation.de>
parents:
4877
diff
changeset
|
44 if feat.GetFieldIndex(name) == -1: |
82d00b0c7302
(importer) Avoid uneccessary error and improve debug output
Andre Heinecke <aheinecke@intevation.de>
parents:
4877
diff
changeset
|
45 return False # Avoids an Error in IsFieldSet |
82d00b0c7302
(importer) Avoid uneccessary error and improve debug output
Andre Heinecke <aheinecke@intevation.de>
parents:
4877
diff
changeset
|
46 return feat.IsFieldSet(feat.GetFieldIndex(name)) |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 |
5386
6c2751c17869
Importer: Add function to search a value in all fields.
Andre Heinecke <aheinecke@intevation.de>
parents:
5365
diff
changeset
|
48 def searchValue(self, feat, regex): |
6c2751c17869
Importer: Add function to search a value in all fields.
Andre Heinecke <aheinecke@intevation.de>
parents:
5365
diff
changeset
|
49 """ |
5401
ff11b178f152
Fix searchValue and mark a field where a string is found as handled
Andre Heinecke <aheinecke@intevation.de>
parents:
5386
diff
changeset
|
50 Searches for a value that matches regex in all attribute |
5386
6c2751c17869
Importer: Add function to search a value in all fields.
Andre Heinecke <aheinecke@intevation.de>
parents:
5365
diff
changeset
|
51 fields of a feature. |
5401
ff11b178f152
Fix searchValue and mark a field where a string is found as handled
Andre Heinecke <aheinecke@intevation.de>
parents:
5386
diff
changeset
|
52 |
ff11b178f152
Fix searchValue and mark a field where a string is found as handled
Andre Heinecke <aheinecke@intevation.de>
parents:
5386
diff
changeset
|
53 @returns the name of the field where a match was found or None |
5386
6c2751c17869
Importer: Add function to search a value in all fields.
Andre Heinecke <aheinecke@intevation.de>
parents:
5365
diff
changeset
|
54 """ |
6c2751c17869
Importer: Add function to search a value in all fields.
Andre Heinecke <aheinecke@intevation.de>
parents:
5365
diff
changeset
|
55 for val in feat.items(): |
5401
ff11b178f152
Fix searchValue and mark a field where a string is found as handled
Andre Heinecke <aheinecke@intevation.de>
parents:
5386
diff
changeset
|
56 match = re.match(regex, feat.items()[val], re.IGNORECASE) |
ff11b178f152
Fix searchValue and mark a field where a string is found as handled
Andre Heinecke <aheinecke@intevation.de>
parents:
5386
diff
changeset
|
57 if match: |
ff11b178f152
Fix searchValue and mark a field where a string is found as handled
Andre Heinecke <aheinecke@intevation.de>
parents:
5386
diff
changeset
|
58 return val |
5386
6c2751c17869
Importer: Add function to search a value in all fields.
Andre Heinecke <aheinecke@intevation.de>
parents:
5365
diff
changeset
|
59 |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
60 def searchField(self, regex): |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
61 """ |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
62 Searches for a field in the current src layer that matches |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
63 the expression regex. |
5174
b3a15fa3d88e
let import_river.sh parse gauge official numbers, typo
Tom Gottfried <tom@intevation.de>
parents:
5160
diff
changeset
|
64 Throws an exception if more than one field matches |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
65 @param feat: The feature to search for attributes |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
66 @param regex: The regex to look for |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
67 |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
68 @returns: The field name as a string |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
69 """ |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
70 |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
71 if not hasattr(self.srcLayer, "fieldnames"): |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
72 self.srcLayer.fieldnames = [] |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
73 for i in range(0, self.srcLayer.GetLayerDefn().GetFieldCount()): |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
74 self.srcLayer.fieldnames.append( |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
75 self.srcLayer.GetLayerDefn().GetFieldDefn(i).GetNameRef()) |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
76 |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
77 result = None |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
78 for name in self.srcLayer.fieldnames: |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
79 match = re.match(regex, name, re.IGNORECASE) |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
80 if match: |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
81 if result: |
5174
b3a15fa3d88e
let import_river.sh parse gauge official numbers, typo
Tom Gottfried <tom@intevation.de>
parents:
5160
diff
changeset
|
82 raise Exception("More than one field matches: %s" % regex) |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
83 else: |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
84 result = match.group(0) |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
85 return result |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
86 |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
87 def IsDoubleFieldSet(self, feat, name): |
5365
90f1c5f67698
Importer: Do not return true for IsDoubleField set if the field
Andre Heinecke <aheinecke@intevation.de>
parents:
5174
diff
changeset
|
88 if not self.IsFieldSet(feat, name): |
90f1c5f67698
Importer: Do not return true for IsDoubleField set if the field
Andre Heinecke <aheinecke@intevation.de>
parents:
5174
diff
changeset
|
89 return False |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 try: |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
91 isset = feat.GetFieldAsDouble(name) |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 return isset is not None |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 except: |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 return False |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 def isShapeRelevant(self, name, path): |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 return True |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 def walkOverShapes(self, shape): |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 (name, path) = shape |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
101 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 shp = ogr.Open(shape[1]) |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 if shp is None: |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
104 logger.error("Shapefile '%s' could not be opened!" % path) |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 return |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 |
4995
998b29c8d2fd
Improve debug output for unsupported features and skipped shapefiles
Andre Heinecke <aheinecke@intevation.de>
parents:
4974
diff
changeset
|
107 if not self.isShapeRelevant(name, path): |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
108 logger.info("Skip shapefile: '%s' of Type: %s" % (path, |
4995
998b29c8d2fd
Improve debug output for unsupported features and skipped shapefiles
Andre Heinecke <aheinecke@intevation.de>
parents:
4974
diff
changeset
|
109 utils.getWkbString(shp.GetLayerByName(name).GetGeomType()))) |
998b29c8d2fd
Improve debug output for unsupported features and skipped shapefiles
Andre Heinecke <aheinecke@intevation.de>
parents:
4974
diff
changeset
|
110 return |
998b29c8d2fd
Improve debug output for unsupported features and skipped shapefiles
Andre Heinecke <aheinecke@intevation.de>
parents:
4974
diff
changeset
|
111 |
998b29c8d2fd
Improve debug output for unsupported features and skipped shapefiles
Andre Heinecke <aheinecke@intevation.de>
parents:
4974
diff
changeset
|
112 |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
113 logger.info("Processing shapefile '%s'" % path) |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
114 srcLayer = shp.GetLayerByName(name) |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
115 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
116 if srcLayer is None: |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
117 logger.error("Layer '%s' was not found!" % name) |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
118 return |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
119 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
120 return self.shape2Database(srcLayer, name, path) |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
121 |
2861
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
122 def transform(self, feat): |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
123 geometry = feat.GetGeometryRef() |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
124 src_srs = geometry.GetSpatialReference() |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
125 |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
126 if src_srs is None: |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
127 logger.error("No source SRS given! No transformation possible!") |
2861
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
128 return feat |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
129 |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
130 transformer = osr.CoordinateTransformation(src_srs, self.dest_srs) |
4974
a92241d40228
Handle transformation errors
Andre Heinecke <aheinecke@intevation.de>
parents:
4970
diff
changeset
|
131 if geometry.Transform(transformer): |
a92241d40228
Handle transformation errors
Andre Heinecke <aheinecke@intevation.de>
parents:
4970
diff
changeset
|
132 return None |
2861
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
133 |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
134 return feat |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
135 |
4884
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
136 def handled(self, field): |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
137 """ |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
138 Register a field or a map of as handled during the import. |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
139 |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
140 There is a warning printed after the import for each unhandled field! |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
141 """ |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
142 if not field in self.handled_fields: |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
143 self.handled_fields.append(field) |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
144 |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
145 def copyFields(self, src, target, mapping): |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
146 """ |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
147 Checks the mapping dictonary for key value pairs to |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
148 copy from the source to the destination feature. |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
149 The keys can be reguar expressions that are matched |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
150 agains the source fieldnames |
4884
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
151 |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
152 The Key is the attribute of the source feature to be copied |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
153 into the target attribute named by the dict's value. |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
154 """ |
4885
89a8764cabcc
Importer: Only show imported fields if copy_fields is used
Andre Heinecke <aheinecke@intevation.de>
parents:
4884
diff
changeset
|
155 self.tracking_import = True |
4884
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
156 for key, value in mapping.items(): |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
157 realname = self.searchField(key) |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
158 if realname == None: |
4884
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
159 continue |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
160 if not realname in self.handled_fields: |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
161 self.handled_fields.append(realname) |
4884
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
162 # 0 OFTInteger, Simple 32bit integer |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
163 # 1 OFTIntegerList, List of 32bit integers |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
164 # 2 OFTReal, Double Precision floating point |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
165 # 3 OFTRealList, List of doubles |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
166 # 4 OFTString, String of ASCII chars |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
167 # 5 OFTStringList, Array of strings |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
168 # 6 OFTWideString, deprecated |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
169 # 7 OFTWideStringList, deprecated |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
170 # 8 OFTBinary, Raw Binary data |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
171 # 9 OFTDate, Date |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
172 # 10 OFTTime, Time |
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
173 # 11 OFTDateTime, Date and Time |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
174 if src.IsFieldSet(src.GetFieldIndex(realname)): |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
175 if src.GetFieldType(realname) == 2: |
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
176 target.SetField(value, src.GetFieldAsDouble(realname)) |
4884
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
177 else: |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
178 target.SetField(value, utils.getUTF8(src.GetField(realname))) |
4884
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
179 |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
180 def shape2Database(self, srcLayer, name, path): |
4872
a563e9f58f93
Improve error handling and unify dbconn for all importers
Andre Heinecke <aheinecke@intevation.de>
parents:
4871
diff
changeset
|
181 destLayer = self.dbconn.GetLayerByName(self.getTablename()) |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
182 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
183 if srcLayer is None: |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
184 logger.error("Shapefile is None!") |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
185 return -1 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
186 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
187 if destLayer is None: |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
188 logger.error("No destination layer given!") |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
189 return -1 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
190 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
191 count = srcLayer.GetFeatureCount() |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
192 logger.debug("Try to add %i features to database." % count) |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
193 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
194 srcLayer.ResetReading() |
4935
c0a58558b817
Importer: - Handle regular expressions for attribute names
Andre Heinecke <aheinecke@intevation.de>
parents:
4886
diff
changeset
|
195 self.srcLayer = srcLayer |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
196 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
197 geomType = -1 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
198 success = 0 |
4995
998b29c8d2fd
Improve debug output for unsupported features and skipped shapefiles
Andre Heinecke <aheinecke@intevation.de>
parents:
4974
diff
changeset
|
199 unsupported = {} |
2861
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
200 creationFailed = 0 |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
201 featureDef = destLayer.GetLayerDefn() |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
202 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
203 for feat in srcLayer: |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
204 geom = feat.GetGeometryRef() |
2861
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
205 |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
206 if geom is None: |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
207 logger.debug("Unkown Geometry reference for feature") |
2861
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
208 continue |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
209 |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
210 geomType = geom.GetGeometryType() |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
211 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
212 if self.isGeometryValid(geomType): |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
213 newFeat = self.createNewFeature(featureDef, |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
214 feat, |
4951
23a090b41543
Importer: Check lowercase pathname and handle utf-8 conversion
Andre Heinecke <aheinecke@intevation.de>
parents:
4935
diff
changeset
|
215 name=utils.getUTF8(name), |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
216 path=path) |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
217 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
218 if newFeat is not None: |
4877
852d4c508f33
(importer) Try to convert paths to UTF-8 for DB insertion
Andre Heinecke <aheinecke@intevation.de>
parents:
4876
diff
changeset
|
219 newFeat.SetField("path", utils.getUTF8Path(path)) |
2861
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
220 newFeat = self.transform(newFeat) |
4974
a92241d40228
Handle transformation errors
Andre Heinecke <aheinecke@intevation.de>
parents:
4970
diff
changeset
|
221 if newFeat: |
a92241d40228
Handle transformation errors
Andre Heinecke <aheinecke@intevation.de>
parents:
4970
diff
changeset
|
222 res = destLayer.CreateFeature(newFeat) |
a92241d40228
Handle transformation errors
Andre Heinecke <aheinecke@intevation.de>
parents:
4970
diff
changeset
|
223 if res is None or res > 0: |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
224 logger.error("Unable to insert feature. Error: %r" % res) |
4974
a92241d40228
Handle transformation errors
Andre Heinecke <aheinecke@intevation.de>
parents:
4970
diff
changeset
|
225 else: |
a92241d40228
Handle transformation errors
Andre Heinecke <aheinecke@intevation.de>
parents:
4970
diff
changeset
|
226 success = success + 1 |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
227 else: |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
228 logger.error("Could not transform feature: %s " % feat.GetFID()) |
4974
a92241d40228
Handle transformation errors
Andre Heinecke <aheinecke@intevation.de>
parents:
4970
diff
changeset
|
229 creationFailed += 1 |
2861
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
230 else: |
b0132e1b9719
Added further shape importers and added the option to reproject shapes during the import process.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2853
diff
changeset
|
231 creationFailed = creationFailed + 1 |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
232 else: |
4995
998b29c8d2fd
Improve debug output for unsupported features and skipped shapefiles
Andre Heinecke <aheinecke@intevation.de>
parents:
4974
diff
changeset
|
233 unsupported[utils.getWkbString(geomType)] = \ |
998b29c8d2fd
Improve debug output for unsupported features and skipped shapefiles
Andre Heinecke <aheinecke@intevation.de>
parents:
4974
diff
changeset
|
234 unsupported.get(utils.getWkbString(geomType), 0) + 1 |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
235 |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
236 logger.info("Inserted %i features" % success) |
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
237 logger.info("Failed to create %i features" % creationFailed) |
5001 | 238 for key, value in unsupported.items(): |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
239 logger.info("Found %i unsupported features of type: %s" % (value, key)) |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
240 |
4886
8e99d2d9364d
Importer: When not tracking dont print info about unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4885
diff
changeset
|
241 if self.tracking_import: |
8e99d2d9364d
Importer: When not tracking dont print info about unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4885
diff
changeset
|
242 unhandled = [] |
8e99d2d9364d
Importer: When not tracking dont print info about unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4885
diff
changeset
|
243 for i in range(0, srcLayer.GetLayerDefn().GetFieldCount()): |
8e99d2d9364d
Importer: When not tracking dont print info about unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4885
diff
changeset
|
244 act_field = srcLayer.GetLayerDefn().GetFieldDefn(i).GetNameRef() |
8e99d2d9364d
Importer: When not tracking dont print info about unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4885
diff
changeset
|
245 if not act_field in self.handled_fields: |
8e99d2d9364d
Importer: When not tracking dont print info about unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4885
diff
changeset
|
246 unhandled.append(act_field) |
4884
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
247 |
4886
8e99d2d9364d
Importer: When not tracking dont print info about unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4885
diff
changeset
|
248 if len(unhandled): |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
249 logger.info("Did not import values from fields: %s " % \ |
4886
8e99d2d9364d
Importer: When not tracking dont print info about unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4885
diff
changeset
|
250 " ".join(unhandled)) |
4884
b457532dae63
Importer: Move copy fields into importer class and track imported/unimported fields
Andre Heinecke <aheinecke@intevation.de>
parents:
4878
diff
changeset
|
251 |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
252 try: |
4970
174fbaa3d344
Add handling of River Names and remove target_src parameter
Andre Heinecke <aheinecke@intevation.de>
parents:
4951
diff
changeset
|
253 if self.dry_run: |
3655
8654e4480fc6
Shape importer: added command line option dry_run to supress database transactions.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3654
diff
changeset
|
254 return geomType |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
255 destLayer.CommitTransaction() |
5160
0dae9e77c5da
Importer fix issues reported by pylint
Andre Heinecke <aheinecke@intevation.de>
parents:
5077
diff
changeset
|
256 except: |
5006
769593a84606
Importer: Behold, Logging!
Andre Heinecke <aheinecke@intevation.de>
parents:
5004
diff
changeset
|
257 logger.error("Exception while committing transaction.") |
2853
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
258 |
bd9e76e0b55d
Improved the python shapefile importer.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
259 return geomType |