Skip to content

Commit

Permalink
move additions from top __init__ to core.__init__
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed May 16, 2018
1 parent 5790bbc commit 95ecea8
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 32 deletions.
22 changes: 0 additions & 22 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 14 additions & 10 deletions python/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions python/core/additions/qgsfeature.py
Original file line number Diff line number Diff line change
@@ -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__}
7 changes: 7 additions & 0 deletions python/core/additions/qgsgeometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.