Skip to content

Commit

Permalink
Adds helper functions and EndChecks to lessons
Browse files Browse the repository at this point in the history
  • Loading branch information
SrNetoChan committed Sep 26, 2017
1 parent 9b8cc30 commit fee9220
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ All selected buildings will be rendered in bright yellow.

![buildings_are_selected](buildings_are_selected.png)

If necessary, click **Solve Step** to automatically select the block's
buildings.

Click **Next step** once you are done.
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
from lessons.utils import layerFromName
from qgis.core import QgsMapLayer, QgsRectangle

# Functions

def selectByRectangle(layername, xmin, ymin, xmax, ymax):
"""
Select features in rectangle
:param layername: Layer's name as in the layers panel
:return: None
"""

layer = layerFromName(layername)
if layer is not None and layer.type() == QgsMapLayer.VectorLayer:
layer.selectByRect(QgsRectangle(xmin, ymin, xmax, ymax))

# EndCheck Function

def isLayerEditable(*args):
Expand All @@ -10,3 +22,40 @@ def isLayerEditable(*args):
"""
layer = layerFromName(args[0])
return layer is not None and layer.isEditable()

def isLayerSaved(layername):
"""
Returns True if no changes were made in the layer after the last save
:param layername: Layer name as in the layers panel
:return: Boolean
"""

layer = layerFromName(layername)
return layer is not None and layer.type() == QgsMapLayer.VectorLayer and \
not layer.isModified()

def checkFieldValue(layername, field, value):
"""
Return True if all features have a certain value for a
particular field. If the layer has selected features, only those will be
taken in account
:param layername: Layer's name as in the layers panel
:param field: Field name
:param value: value to confirm
:return: Boolean
"""

layer = layerFromName(layername)
if layer is None:
return False

if layer.selectedFeatureCount():
features = layer.selectedFeatures()
else:
features = layer.getFeatures()

for feature in features:
if feature.attribute(field) != value:
return False

return True
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,30 @@ lesson:
steps:
- description: 01_introduction.md
name: Introduction

- description: 02_select_features_to_update.md
name: Select features to update

function:
name: selectByRectangle
params:
- Buildings
- 2108266.086
- 736866.556
- 2108698.209
- 737332.511

- description: 03_open_attribute_table.md
name: Open attribute table

- description: 04_turn_layer_into_editing_mode.md
name: Turn layer into editing mode

endcheck:
name: isLayerEditable
params:
- Buildings

- description: 05_update_a_field_of_the_selected_features.md
name: Update a field of the selected features

Expand All @@ -26,18 +39,58 @@ lesson:
- QgsFieldCalculatorBase
- 300
- 1000

endcheck:
name: checkFieldValue
params:
- Buildings
- DESCRIPTIO
- UNDER CONSTRUCTION

- description: 06_confirm_the_changes.md
name: Confirm the changes

- description: 07_change_multiple_features_attributes_using_the_quick_bar.md
name: Change multiple features attributes using the quick bar

endcheck:
name: checkFieldValue
params:
- Buildings
- UPDATE_DAT
- 2017-08-15

- description: 08_edit_multiple_fields_using_multi_edit_mode.md
name: Edit multiple fields using multi edit mode

endcheck:
name: checkFieldValue
params:
- Buildings
- UPDATE_DAT
- 2017-09-24

endcheck:
name: checkFieldValue
params:
- Buildings
- DESCRIPTIO
- COMMERCIAL

- description: 09_confirm_multiple_field_changes.md
name: Confirm multiple field changes

- description: 10_save_changes_to_the_attributes.md
name: Save changes to the attributes

endcheck:
name: isLayerSaved
params:
- Buildings

- description: 11_turn_editing_mode_off.md
name: Turn editing mode off

nextLessons:
- group: Vector layer attributes
name: 09. Join attribute tables
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
<evaluateDefaultValues active="0"/>
<layer-tree-group expanded="1" checked="Qt::Checked" name="">
<customproperties/>
<layer-tree-layer expanded="1" providerKey="ogr" checked="Qt::Checked" id="raleigh_downtown20161228143332835" source="E:/boundless/repos/desktop-lessons/vector_layers_attributes/Edit multiple features attributes/data/raleigh_downtown.shp" name="Raleigh downtown">
<layer-tree-layer expanded="1" providerKey="ogr" checked="Qt::Checked" id="raleigh_downtown20161228143332835" source="E:/boundless/repos/desktop-lessons/vector_layers_attributes/Edit_multiple_features_attributes/data/raleigh_downtown.shp" name="Raleigh downtown">
<customproperties/>
</layer-tree-layer>
<layer-tree-layer expanded="1" providerKey="ogr" checked="Qt::Checked" id="raleigh_downtown_streets20161228143254740" source="E:/boundless/repos/desktop-lessons/vector_layers_attributes/Edit multiple features attributes/data/raleigh_downtown_streets.shp" name="Streets">
<layer-tree-layer expanded="1" providerKey="ogr" checked="Qt::Checked" id="raleigh_downtown_streets20161228143254740" source="E:/boundless/repos/desktop-lessons/vector_layers_attributes/Edit_multiple_features_attributes/data/raleigh_downtown_streets.shp" name="Streets">
<customproperties/>
</layer-tree-layer>
<layer-tree-layer expanded="1" providerKey="ogr" checked="Qt::Checked" id="raleigh_downtown_buildings20170320122317569" source="E:/boundless/repos/desktop-lessons/vector_layers_attributes/Edit multiple features attributes/data/raleigh_downtown_buildings.shp" name="Buildings">
<layer-tree-layer expanded="1" providerKey="ogr" checked="Qt::Checked" id="raleigh_downtown_buildings20170320122317569" source="E:/boundless/repos/desktop-lessons/vector_layers_attributes/Edit_multiple_features_attributes/data/raleigh_downtown_buildings.shp" name="Buildings">
<customproperties/>
</layer-tree-layer>
</layer-tree-group>
<relations/>
<mapcanvas>
<units>feet</units>
<extent>
<xmin>2108538.56693823775276542</xmin>
<ymin>736499.42365499236620963</ymin>
<xmax>2109218.90961974998936057</xmax>
<ymax>737517.45137102552689612</ymax>
<xmin>2108153.50982284685596824</xmin>
<ymin>736582.06148340972140431</ymin>
<xmax>2108833.85250435909256339</xmax>
<ymax>737600.08919944288209081</ymax>
</extent>
<rotation>0</rotation>
<projections>1</projections>
Expand Down Expand Up @@ -201,7 +201,7 @@
<customproperties/>
</Composition>
</Composer>
<Composer title="A4 portrait" visible="1">
<Composer title="A4 portrait" visible="0">
<Composition resizeToContentsMarginLeft="0" snapping="0" showPages="1" guidesVisible="1" resizeToContentsMarginTop="0" worldFileMap="" alignmentSnap="1" printResolution="300" paperWidth="210" gridVisible="0" snapGridOffsetX="0" smartGuides="1" snapGridOffsetY="0" resizeToContentsMarginRight="0" snapTolerancePixels="5" printAsRaster="0" generateWorldFile="0" paperHeight="297" numPages="1" snapGridResolution="10" resizeToContentsMarginBottom="0">
<symbol alpha="1" clip_to_extent="1" type="fill" name="">
<layer pass="0" class="SimpleFill" locked="0">
Expand Down Expand Up @@ -254,7 +254,7 @@
<styleFont description="Ubuntu,12,-1,5,50,0,0,0,0,0" style=""/>
</style>
</styles>
<ComposerItem pagey="222.915" page="1" id="" lastValidViewScaleFactor="-1" positionMode="0" positionLock="false" x="16.1386" y="222.915" visibility="1" zValue="2" background="true" transparency="0" frameJoinStyle="miter" blendMode="0" width="177.723" outlineWidth="0.3" excludeFromExports="0" uuid="{5aa84e88-5af7-4adf-a9e4-2f84832130bc}" height="61.1" itemRotation="0" frame="false" pagex="16.1386">
<ComposerItem pagey="222.915" page="1" id="" lastValidViewScaleFactor="-1" positionMode="0" positionLock="false" x="16.1386" y="222.915" visibility="1" zValue="2" background="true" transparency="0" frameJoinStyle="miter" blendMode="0" width="127.5" outlineWidth="0.3" excludeFromExports="0" uuid="{5aa84e88-5af7-4adf-a9e4-2f84832130bc}" height="55.9" itemRotation="0" frame="false" pagex="16.1386">
<FrameColor alpha="255" red="0" blue="0" green="0"/>
<BackgroundColor alpha="255" red="255" blue="255" green="255"/>
<customproperties/>
Expand Down Expand Up @@ -313,7 +313,7 @@
<annotationFontProperties description="Ubuntu,11,-1,5,50,0,0,0,0,0" style=""/>
</ComposerMapGrid>
<AtlasMap scalingMode="2" atlasDriven="0" margin="0.10000000000000001"/>
<ComposerItem pagey="21.0793" page="1" id="" lastValidViewScaleFactor="1.82979" positionMode="0" positionLock="false" x="16.2886" y="21.0793" visibility="1" zValue="1" background="true" transparency="0" frameJoinStyle="miter" blendMode="0" width="177.423" outlineWidth="0.3" excludeFromExports="0" uuid="{6f50d521-9f0f-48c1-859f-ffd55c041a73}" height="196.057" itemRotation="0" frame="true" pagex="16.2886">
<ComposerItem pagey="21.0793" page="1" id="" lastValidViewScaleFactor="1.34468" positionMode="0" positionLock="false" x="16.2886" y="21.0793" visibility="1" zValue="1" background="true" transparency="0" frameJoinStyle="miter" blendMode="0" width="177.423" outlineWidth="0.3" excludeFromExports="0" uuid="{6f50d521-9f0f-48c1-859f-ffd55c041a73}" height="196.057" itemRotation="0" frame="true" pagex="16.2886">
<FrameColor alpha="255" red="0" blue="0" green="0"/>
<BackgroundColor alpha="255" red="255" blue="255" green="255"/>
<customproperties/>
Expand Down

0 comments on commit fee9220

Please sign in to comment.