Skip to content

Commit

Permalink
placeholder, filter, attribute, first implementation of statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
wilhelmberg committed Feb 12, 2014
1 parent f7342aa commit 530643b
Show file tree
Hide file tree
Showing 14 changed files with 159 additions and 20 deletions.
4 changes: 3 additions & 1 deletion VoGISRaumplanungPlot/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ PY_FILES = vogisraumplanungplot.py \

BO_FILES = vrpbo/__init__.py \
vrpbo/vrpbothema.py \
vrpbo/vrpbolayout.py
vrpbo/vrpbolayout.py \
vrpbo/vrpbostatistik.py \
vrpbo/vrpbostatistiksubthema.py

COMPOSER_FILES = vrpcomposer/__init__.py \
vrpcomposer/vrpprintcomposer.py
Expand Down
Empty file added VoGISRaumplanungPlot/i18n/TODO
Empty file.
2 changes: 1 addition & 1 deletion VoGISRaumplanungPlot/metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[general]
name=VoGIS Raumplanung
description=Create Plots from VoGIS Data.
version=0.0.4
version=0.0.5
qgisMinimumVersion=2.0
qgisMaximumVersion=2.99
author=BergWerk GIS
Expand Down
2 changes: 1 addition & 1 deletion VoGISRaumplanungPlot/resources_rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Resource object code
#
# Created: So. Feb 9 17:32:11 2014
# Created: Mi. Feb 12 12:55:31 2014
# by: The Resource Compiler for PyQt (Qt v4.8.4)
#
# WARNING! All changes made in this file will be lost!
Expand Down
2 changes: 1 addition & 1 deletion VoGISRaumplanungPlot/ui_vogisraumplanungplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui_vogisraumplanungplot.ui'
#
# Created: Sun Feb 9 17:32:11 2014
# Created: Wed Feb 12 12:55:31 2014
# by: PyQt4 UI code generator 4.10.3
#
# WARNING! All changes made in this file will be lost!
Expand Down
2 changes: 1 addition & 1 deletion VoGISRaumplanungPlot/ui_vogisraumplanungplotsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui_vogisraumplanungplotsettings.ui'
#
# Created: Sun Feb 9 17:32:11 2014
# Created: Wed Feb 12 12:55:31 2014
# by: PyQt4 UI code generator 4.10.3
#
# WARNING! All changes made in this file will be lost!
Expand Down
2 changes: 1 addition & 1 deletion VoGISRaumplanungPlot/vogisraumplanungplotdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def accept(self):
self.iface,
self.curr_gem_name,
self.dkm_coverage_layer,
self.json_settings.dkm_stand(),
self.json_settings,
gnrs,
gstk_filter,
ortho,
Expand Down
29 changes: 29 additions & 0 deletions VoGISRaumplanungPlot/vrpbo/vrpbostatistik.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
"""Business object for Grunstück Statistik"""

from qgis.core import QgsMessageLog
from ..vrpcore.constvals import *

class VRPStatistik:
"""Statistics for one parcel"""
def __init__(self, gstk_nr, gstk_flaeche, gemeindename):
self.gnr = gstk_nr
self.flaeche = gstk_flaeche
self.gem_name = gemeindename
self.subthemen = []

def add_subthema(self, subthema):
"""add subthema"""
self.subthemen.append(subthema)

def __str__(self):
asstr = '{1}{0}{2}{0}{3:.2f}'.format('\t', self.gem_name, self.gnr, self.flaeche)
for subthema in self.subthemen:
asstr += '\n' + subthema.__str__()
return asstr

def __unicode__(self):
asunicode = u'{1}{0}{2}{0}{3:.2f}'.format(u'\t', self.gem_name, self.gnr, self.flaeche)
for subthema in self.subthemen:
asunicode += u'\n' + subthema.__unicode__()
return asunicode
24 changes: 24 additions & 0 deletions VoGISRaumplanungPlot/vrpbo/vrpbostatistiksubthema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
"""Business object for Grundstück Statistik"""

from qgis.core import QgsMessageLog
from ..vrpcore.constvals import *

class VRPStatistikSubThema:
"""Statistics for one parcel"""
def __init__(self, subthema_name, text_flaeche):
self.name = subthema_name
self.txt_area = text_flaeche

def __str__(self):
#{3:.2f}
txt = ''
for key, val in self.txt_area.iteritems():
txt += '{0}:{1:.2f}; '.format(key, val)
return '{1}{0}{2}'.format('\t', self.name, txt)

def __unicode__(self):
txt = u''
for key, val in self.txt_area.iteritems():
txt += u'{0}:{1:.2f}; '.format(key, val)
return u'{1}{0}{2}'.format(u'\t', self.name, txt)
3 changes: 3 additions & 0 deletions VoGISRaumplanungPlot/vrpbo/vrpbothema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self, js_quelle, parent_name):
self.name = parent_name
self.pfad = js_quelle['pfad']
self.qml = None
self.statistik = False
self.attribut = None
self.filter = None
self.text = None
Expand All @@ -21,6 +22,8 @@ def __init__(self, js_quelle, parent_name):
if 'qml' in js_quelle:
if not js_quelle['qml'].isspace() and not js_quelle['qml'] == '':
self.qml = js_quelle['qml']
if 'statistik' in js_quelle:
self.statistik = js_quelle['statistik']
if 'attribut' in js_quelle:
if not js_quelle['attribut'].isspace() and not js_quelle['attribut'] == '':
self.attribut = js_quelle['attribut']
Expand Down
103 changes: 92 additions & 11 deletions VoGISRaumplanungPlot/vrpcomposer/vrpprintcomposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,25 @@
from PyQt4.QtGui import QPrinter
from PyQt4.QtGui import QPainter
from PyQt4.QtGui import QTreeWidget
from qgis.core import QgsMapLayerRegistry
from qgis.core import QgsVectorLayer
from qgis.core import QgsRasterLayer
from qgis.core import QgsExpression
from qgis.core import QgsComposition
import processing
from qgis.core import QgsComposerLabel
from qgis.core import QgsComposerLegend
from qgis.core import QgsComposition
from qgis.core import QgsExpression
from qgis.core import QgsFeatureRequest
from qgis.core import QgsMapLayerRegistry
from qgis.core import QgsMessageLog
from qgis.core import QgsRasterLayer
from qgis.core import QgsVectorLayer
from qgis.gui import QgsMessageBar
from ..vrpcore.constvals import *
from ..vrpbo.vrpbostatistik import VRPStatistik
from ..vrpbo.vrpbostatistiksubthema import VRPStatistikSubThema


class VRPPrintComposer:
"""Atlas Generation"""
def __init__(self, iface, gemname, coveragelayer, dkm_date, gnr_nbrs, featurefilter, orthoimage, themen, templateqpt, pdfmap):
def __init__(self, iface, gemname, coveragelayer, json_settings, gnr_nbrs, featurefilter, orthoimage, themen, templateqpt, pdfmap):
self.iface = iface
self.legiface = self.iface.legendInterface()
self.toc = self.iface.mainWindow().findChild(QTreeWidget, 'theMapLegend')
Expand All @@ -37,7 +42,7 @@ def __init__(self, iface, gemname, coveragelayer, dkm_date, gnr_nbrs, featurefil
self.gem_name = gemname
self.coverage_layer = coveragelayer
self.gnrs = gnr_nbrs
self.date_dkm = dkm_date
self.settings = json_settings
self.feature_filter = featurefilter
self.ortho = orthoimage
self.ortho_lyr = None
Expand All @@ -49,7 +54,7 @@ def __init__(self, iface, gemname, coveragelayer, dkm_date, gnr_nbrs, featurefil
self.lyrname_dkm_gnr = 'DKM GNR'
self.comp_leg = []
self.comp_lbl = []
self.statistics = None
self.statistics = {}

def export_all_features_TEST(self):
lyr = QgsVectorLayer('/home/bergw/VoGIS-Raumplanung-Daten/Geodaten/Raumplanung/Flaechenwidmung/Dornbirn/Flaechenwidmungsplan/fwp_flaeche.shp', 'flaeiw', 'ogr')
Expand Down Expand Up @@ -169,6 +174,7 @@ def export_all_features(self):
if not sub_themen is None:
for sub_thema in sub_themen:
layers = self.__add_layers(sub_thema)
self.__calculate_statistics(sub_thema, layers)
if cntr > 0:
printer.newPage()
self.__reorder_layers()
Expand All @@ -181,11 +187,86 @@ def export_all_features(self):
msg = 'export pdf (catch all):\n\n{0}'.format(traceback.format_exc())
QgsMessageLog.logMessage(msg, DLG_CAPTION)
return msg
#if VRP_DEBUG is True:
QgsMessageLog.logMessage(u'====== STATISTICS =========', DLG_CAPTION)
for gnr, stats in self.statistics.iteritems():
QgsMessageLog.logMessage(u'{0}:\n{1}'.format(gnr, stats.__unicode__()), DLG_CAPTION)
QgsMessageLog.logMessage(u'- - - - - - - - - - - - - - - - - - - - - - - -', DLG_CAPTION)
QgsMessageLog.logMessage(u'====== END - STATISTICS =========', DLG_CAPTION)

return None

def __calculate_statistics(self, thema, layers):
pass

features = processing.features(self.coverage_layer)
for gstk in features:
try:
gnr = gstk[self.settings.fld_gnr()]
flaeche = gstk.geometry().area()
gstk_stats = VRPStatistik(gnr, flaeche, self.gem_name)
for lyr in layers:
lyrname = lyr.name()
lyr_thema = self.__get_thema_by_layername(lyrname)
if VRP_DEBUG is True: QgsMessageLog.logMessage(u'lyrname:{0}, lyr_thema:{1}'.format(lyrname, lyr_thema), DLG_CAPTION)
if lyr_thema is None: continue
skip = False
lyr_quelle = None
for quelle in lyr_thema.quellen:
if VRP_DEBUG is True: QgsMessageLog.logMessage(u'quelle:{0}, statistik:{1}'.format(quelle.name, quelle.statistik), DLG_CAPTION)
if quelle.name == lyrname and quelle.statistik is False:
skip = True
break
elif quelle.name == lyrname and quelle.statistik is True:
lyr_quelle = quelle
break
if skip is True: continue
text_flaeche = self.__get_text_flaeche(gstk, lyr, lyr_quelle.attribut)
sub_stat = VRPStatistikSubThema(lyrname, text_flaeche)
gstk_stats.add_subthema(sub_stat)
if gnr in self.statistics:
self.statistics[gnr].subthemen.extend(gstk_stats.subthemen)
else:
self.statistics[gnr] = gstk_stats
except:
msg = '__calculate_statistics:\n\n{0}'.format(traceback.format_exc())
QgsMessageLog.logMessage(msg, DLG_CAPTION, QgsMessageLog.CRITICAL)
self.iface.messageBar().pushMessage(msg, QgsMessageBar.CRITICAL)
return

def __get_text_flaeche(self, gstk, layer, fld_name):
text = {}
#performance! filter by bb of gstk first
feat_req = QgsFeatureRequest()
feat_req.setFilterRect(gstk.geometry().boundingBox())
for feat in layer.getFeatures(feat_req):
if feat.geometry().intersects(gstk.geometry()):
#no fld_name defined: means yes/no only
if fld_name is None:
attr_val = u'Ja'
else:
attr_val = feat[fld_name]
flaeche = feat.geometry().intersection(gstk.geometry()).area()
if fld_name in text:
text[attr_val] += flaeche
else:
text[attr_val] = flaeche
if len(text) < 1 and fld_name is None:
text[u'Nein'] = 0
elif len(text) < 1 and not fld_name is None:
text[u'Nein'] = 0
return text


def __get_thema_by_layername(self, lyrname):
for thema in self.themen:
if thema.name == lyrname:
return thema
for subthema in thema.subthemen:
if subthema.name == lyrname:
return subthema
for quelle in subthema.quellen:
if quelle.name == lyrname:
return subthema
return None

def __update_composer_items(self, oberthema):
for leg in self.comp_leg:
Expand All @@ -195,7 +276,7 @@ def __update_composer_items(self, oberthema):
txt = txt.replace('[Oberthema]', oberthema)
txt = txt.replace('[GNR]', ', '.join(self.gnrs))
txt = txt.replace('[TODAY]', strftime("%d.%m.%Y"))
txt = txt.replace('[DATE]', self.date_dkm)
txt = txt.replace('[DATE]', self.settings.dkm_stand())
lbl[0].setText(txt)


Expand Down
2 changes: 1 addition & 1 deletion VoGISRaumplanungPlot/vrpcore/constvals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# -*- coding: utf-8 -*-

DLG_CAPTION = 'VoGIS Raumplanung Plot'
VRP_DEBUG = True
VRP_DEBUG = False
4 changes: 2 additions & 2 deletions plugins.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version = '1.0' encoding = 'UTF-8'?>
<plugins>
<pyqgis_plugin name="VoGIS Raumplanung" version="0.0.4">
<pyqgis_plugin name="VoGIS Raumplanung" version="0.0.5">
<description><![CDATA[Create Plots from VoGIS Data.]]></description>
<version>0.0.4</version>
<version>0.0.5</version>
<qgis_minimum_version>2.0.0</qgis_minimum_version>
<qgis_maximum_version>2.99.0</qgis_maximum_version>
<homepage>https://github.com/BergWerkGIS/VoGIS-Raumplanung/</homepage>
Expand Down
Binary file modified vogisraumplanungplot.zip
Binary file not shown.

0 comments on commit 530643b

Please sign in to comment.