Permalink
Browse files

[LAYER] Add a criteria layer class

  • Loading branch information...
1 parent 6f1b7fa commit a6b52678dcca3a9e44545d2c5038d289cd343dce @oso committed Sep 21, 2011
Showing with 38 additions and 0 deletions.
  1. +19 −0 layer.py
  2. +19 −0 tests/test_layer.py
View
19 layer.py
@@ -0,0 +1,19 @@
+from qgis.core import QgsVectorLayer
+from mcda import criterion
+
+class criteria_layer(QgsVectorLayer):
+
+ def __init__(self, layer):
+ self.layer = layer
+
+ @property
+ def criteria(self):
+ provider = self.layer.dataProvider()
+ fields = provider.fields()
+ criteria = []
+ for id, field in fields.iteritems():
+ name = str(field.name().trimmed())
+ crit = criterion(id, name)
+ criteria.append(crit)
+
+ return criteria
View
19 tests/test_layer.py
@@ -0,0 +1,19 @@
+import sys
+sys.path.append("..")
+import os
+from qgis.core import QgsVectorLayer, QgsApplication
+from layer import criteria_layer
+
+if __name__ == "__main__":
+ QgsApplication.setPrefixPath("/usr", True)
+ QgsApplication.initQgis()
+
+ layer = QgsVectorLayer("./data/ticino/criteria.shp", "criteria", "ogr")
+ if not layer.isValid():
+ raise NameError, "Layer failed to load!"
+
+ layer = criteria_layer(layer)
+
+ print layer.criteria
+
+ QgsApplication.exitQgis()

0 comments on commit a6b5267

Please sign in to comment.