Skip to content
Permalink
Browse files

move additions from top __init__ to core.__init__

  • Loading branch information
3nids committed May 16, 2018
1 parent 5790bbc commit 95ecea897a85f7aebe7db8f9e1563536ac0866df
Showing with 28 additions and 32 deletions.
  1. +0 −22 python/__init__.py
  2. +14 −10 python/core/__init__.py
  3. +7 −0 python/core/additions/qgsfeature.py
  4. +7 −0 python/core/additions/qgsgeometry.py
@@ -69,25 +69,3 @@ def setupenv():


from qgis.PyQt import QtCore
from qgis.core import QgsFeature, QgsGeometry


def mapping_feature(feature):
geom = feature.geometry()
properties = {}
fields = [field.name() for field in feature.fields()]
properties = dict(list(zip(fields, feature.attributes())))
return {'type': 'Feature',
'properties': properties,
'geometry': geom.__geo_interface__}


def mapping_geometry(geometry):
geo = geometry.asJson()
# We have to use eval because exportToGeoJSON() gives us
# back a string that looks like a dictionary.
return eval(geo)


QgsFeature.__geo_interface__ = property(mapping_feature)
QgsGeometry.__geo_interface__ = property(mapping_geometry)
@@ -26,22 +26,26 @@
from qgis.PyQt.QtCore import NULL
from qgis._core import *

from .additions.readwritecontextentercategory import ReadWriteContextEnterCategory
from .additions.projectdirtyblocker import ProjectDirtyBlocker
from .additions.qgstaskwrapper import QgsTaskWrapper
from .additions.qgsfunction import register_function, qgsfunction
from .additions.edit import edit, QgsEditError
from .additions.fromfunction import fromFunction
from .additions.processing import processing_output_layer_repr, processing_source_repr
from .additions.qgsgeometry import _geometryNonZero
from .additions.projectdirtyblocker import ProjectDirtyBlocker
from .additions.qgsdefaultvalue import _isValid
from .additions.qgsfeature import mapping_feature
from .additions.qgsfunction import register_function, qgsfunction
from .additions.qgsgeometry import _geometryNonZero, mapping_geometry
from .additions.qgstaskwrapper import QgsTaskWrapper
from .additions.readwritecontextentercategory import ReadWriteContextEnterCategory

# Injections into classes
QgsGeometry.__nonzero__ = _geometryNonZero
QgsGeometry.__bool__ = _geometryNonZero
QgsDefaultValue.__bool__ = _isValid
QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory
QgsProject.blockDirtying = ProjectDirtyBlocker
QgsTask.fromFunction = fromFunction
QgsFeature.__geo_interface__ = property(mapping_feature)
QgsGeometry.__bool__ = _geometryNonZero
QgsGeometry.__geo_interface__ = property(mapping_geometry)
QgsGeometry.__nonzero__ = _geometryNonZero
QgsProcessingFeatureSourceDefinition.__repr__ = processing_source_repr
QgsProcessingOutputLayerDefinition.__repr__ = processing_output_layer_repr
QgsProject.blockDirtying = ProjectDirtyBlocker
QgsReadWriteContext.enterCategory = ReadWriteContextEnterCategory
QgsTask.fromFunction = fromFunction
QgsTolerance.UnitType.parentClass = QgsTolerance
@@ -0,0 +1,7 @@
def mapping_feature(feature):
geom = feature.geometry()
fields = [field.name() for field in feature.fields()]
properties = dict(list(zip(fields, feature.attributes())))
return {'type': 'Feature',
'properties': properties,
'geometry': geom.__geo_interface__}
@@ -20,3 +20,10 @@

def _geometryNonZero(self):
return not self.isEmpty()


def mapping_geometry(geometry):
geo = geometry.asJson()
# We have to use eval because exportToGeoJSON() gives us
# back a string that looks like a dictionary.
return eval(geo)

0 comments on commit 95ecea8

Please sign in to comment.
You can’t perform that action at this time.