|
35 | 35 |
|
36 | 36 | from qgis.core import QgsFeature, QgsGeometry
|
37 | 37 |
|
38 |
| -try: |
39 |
| - # Add a __nonzero__ method onto QPyNullVariant so we can check for null values easier. |
40 |
| - # >>> value = QPyNullVariant("int") |
41 |
| - # >>> if value: |
42 |
| - # >>> print "Not a null value" |
43 |
| - from types import MethodType |
44 |
| - from PyQt4.QtCore import QPyNullVariant |
45 |
| - |
46 |
| - def __nonzero__(self): |
47 |
| - return False |
48 |
| - |
49 |
| - def __repr__(self): |
50 |
| - return 'NULL' |
51 |
| - |
52 |
| - def __eq__(self, other): |
53 |
| - return isinstance(other, QPyNullVariant) or other is None |
54 |
| - |
55 |
| - def __ne__(self, other): |
56 |
| - return not isinstance(other, QPyNullVariant) and other is not None |
57 |
| - |
58 |
| - def __hash__(self): |
59 |
| - return 2178309 |
60 |
| - |
61 |
| - QPyNullVariant.__nonzero__ = MethodType(__nonzero__, None, QPyNullVariant) |
62 |
| - QPyNullVariant.__repr__ = MethodType(__repr__, None, QPyNullVariant) |
63 |
| - QPyNullVariant.__eq__ = MethodType(__eq__, None, QPyNullVariant) |
64 |
| - QPyNullVariant.__ne__ = MethodType(__ne__, None, QPyNullVariant) |
65 |
| - QPyNullVariant.__hash__ = MethodType(__hash__, None, QPyNullVariant) |
66 |
| - |
67 |
| - # define a dummy QPyNullVariant instance NULL in qgis.core |
68 |
| - # this is mainly used to compare against |
69 |
| - # so one can write if feat['attr'] == NULL: |
70 |
| - from qgis import core |
71 |
| - core.NULL = QPyNullVariant( int ) |
72 |
| -except ImportError: |
73 |
| - pass |
74 |
| - |
75 |
| -# Define a `with edit(layer)` statement |
76 |
| - |
77 |
| -class edit: |
78 |
| - def __init__(self,layer): |
79 |
| - self.layer = layer |
80 |
| - |
81 |
| - def __enter__(self): |
82 |
| - assert self.layer.startEditing() |
83 |
| - return self.layer |
84 |
| - |
85 |
| - def __exit__(self, ex_type, ex_value, traceback): |
86 |
| - if ex_type is None: |
87 |
| - assert self.layer.commitChanges() |
88 |
| - return True |
89 |
| - else: |
90 |
| - self.layer.rollBack() |
91 |
| - return False |
92 |
| - |
93 |
| -from qgis import core |
94 |
| -core.edit = edit |
95 |
| - |
96 | 38 |
|
97 | 39 | def mapping_feature(feature):
|
98 | 40 | geom = feature.geometry()
|
|
0 commit comments