Skip to content
Permalink
Browse files

Add some more polygon labeling tests

  • Loading branch information
nyalldawson committed Dec 28, 2019
1 parent c924ce5 commit a16e4245505079f6e4fdf64b2fad825f715b83b5
@@ -183,6 +183,30 @@ def test_polygon_placement_with_obstacle(self):
self.removeMapLayer(self.layer)
self.layer = None

def test_polygon_placement_bumps(self):
# Horizontal label placement for polygon with bumps, checking that
# labels are placed close to the pole of inaccessibility (max distance
# to rings)
self.layer = TestQgsPalLabeling.loadFeatureLayer('polygon_with_bump')
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self.lyr.placement = QgsPalLayerSettings.Horizontal
self.checkTest()
self.removeMapLayer(self.layer)
self.layer = None

def test_polygon_placement_small_bump(self):
# Horizontal label placement for polygon with a small bump, checking that
# labels AREN'T placed right at the pole of inaccessibility
# when that position is far from the polygon's centroid
# i.e. when label candidates have close-ish max distance to rings
# then we pick the one closest to the polygon's centroid
self.layer = TestQgsPalLabeling.loadFeatureLayer('polygon_small_bump')
self._TestMapSettings = self.cloneMapSettings(self._MapSettings)
self.lyr.placement = QgsPalLayerSettings.Horizontal
self.checkTest()
self.removeMapLayer(self.layer)
self.layer = None

def test_polygon_multiple_labels(self):
# Horizontal label placement for polygon with hole
# Note for this test, the mask is used to check only pixels outside of the polygon.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,8 @@
{
"type": "FeatureCollection",
"name": "polygon_small_bump",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::32613" } },
"features": [
{ "type": "Feature", "properties": { "text": "Polygon" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 606722.192113020224497, 4823316.557413971982896 ], [ 606714.300620584050193, 4826139.521358795464039 ], [ 610059.109923510462977, 4826627.80451797042042 ], [ 610335.423757166252472, 4826990.08265543077141 ], [ 612357.210945975850336, 4826401.058041367679834 ], [ 612348.641468286281452, 4823301.780262888409197 ], [ 606722.192113020224497, 4823316.557413971982896 ] ] ] } }
]
}
@@ -0,0 +1,252 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis minScale="1e+08" simplifyAlgorithm="0" readOnly="0" simplifyMaxScale="1" maxScale="100000" labelsEnabled="1" styleCategories="AllStyleCategories" simplifyDrawingHints="1" simplifyDrawingTol="1" version="3.11.0-Master" hasScaleBasedVisibilityFlag="0" simplifyLocal="1">
<flags>
<Identifiable>1</Identifiable>
<Removable>1</Removable>
<Searchable>1</Searchable>
</flags>
<renderer-v2 forceraster="0" type="singleSymbol" symbollevels="0" enableorderby="0">
<symbols>
<symbol type="fill" alpha="1" clip_to_extent="1" force_rhr="0" name="0">
<layer enabled="1" locked="0" pass="0" class="SimpleFill">
<prop v="3x:0,0,0,0,0,0" k="border_width_map_unit_scale"/>
<prop v="133,149,161,255" k="color"/>
<prop v="bevel" k="joinstyle"/>
<prop v="0,0" k="offset"/>
<prop v="3x:0,0,0,0,0,0" k="offset_map_unit_scale"/>
<prop v="MM" k="offset_unit"/>
<prop v="0,0,0,255" k="outline_color"/>
<prop v="no" k="outline_style"/>
<prop v="0.26" k="outline_width"/>
<prop v="MM" k="outline_width_unit"/>
<prop v="solid" k="style"/>
<data_defined_properties>
<Option type="Map">
<Option value="" type="QString" name="name"/>
<Option name="properties"/>
<Option value="collection" type="QString" name="type"/>
</Option>
</data_defined_properties>
</layer>
</symbol>
</symbols>
<rotation/>
<sizescale/>
</renderer-v2>
<labeling type="simple">
<settings calloutType="simple">
<text-style fontWordSpacing="0" fontKerning="1" fontStrikeout="0" fontSize="11" blendMode="0" useSubstitutions="0" fontUnderline="0" fontSizeUnit="Point" fieldName="text" fontWeight="50" textOpacity="1" fontLetterSpacing="0" textOrientation="horizontal" namedStyle="Regular" fontItalic="0" fontCapitals="0" textColor="0,0,0,255" isExpression="0" fontFamily="Cantarell" multilineHeight="1" previewBkgrdColor="255,255,255,255" fontSizeMapUnitScale="3x:0,0,0,0,0,0">
<text-buffer bufferNoFill="0" bufferDraw="0" bufferJoinStyle="64" bufferSizeMapUnitScale="3x:0,0,0,0,0,0" bufferColor="255,255,255,255" bufferSize="1" bufferOpacity="1" bufferBlendMode="0" bufferSizeUnits="MM"/>
<text-mask maskEnabled="0" maskSizeUnits="MM" maskType="0" maskSizeMapUnitScale="3x:0,0,0,0,0,0" maskOpacity="1" maskSize="1.5" maskJoinStyle="64" maskedSymbolLayers=""/>
<background shapeOffsetMapUnitScale="3x:0,0,0,0,0,0" shapeRadiiUnit="MM" shapeRadiiX="0" shapeRadiiY="0" shapeBorderWidthMapUnitScale="3x:0,0,0,0,0,0" shapeBorderWidthUnit="MM" shapeOpacity="1" shapeOffsetX="0" shapeOffsetUnit="MM" shapeJoinStyle="64" shapeBorderColor="128,128,128,255" shapeSizeUnit="MM" shapeType="0" shapeSizeX="0" shapeRotationType="0" shapeRotation="0" shapeOffsetY="0" shapeFillColor="255,255,255,255" shapeRadiiMapUnitScale="3x:0,0,0,0,0,0" shapeSizeMapUnitScale="3x:0,0,0,0,0,0" shapeBorderWidth="0" shapeDraw="0" shapeSizeType="0" shapeSVGFile="" shapeSizeY="0" shapeBlendMode="0">
<symbol type="marker" alpha="1" clip_to_extent="1" force_rhr="0" name="markerSymbol">
<layer enabled="1" locked="0" pass="0" class="SimpleMarker">
<prop v="0" k="angle"/>
<prop v="141,90,153,255" k="color"/>
<prop v="1" k="horizontal_anchor_point"/>
<prop v="bevel" k="joinstyle"/>
<prop v="circle" k="name"/>
<prop v="0,0" k="offset"/>
<prop v="3x:0,0,0,0,0,0" k="offset_map_unit_scale"/>
<prop v="MM" k="offset_unit"/>
<prop v="35,35,35,255" k="outline_color"/>
<prop v="solid" k="outline_style"/>
<prop v="0" k="outline_width"/>
<prop v="3x:0,0,0,0,0,0" k="outline_width_map_unit_scale"/>
<prop v="MM" k="outline_width_unit"/>
<prop v="diameter" k="scale_method"/>
<prop v="2" k="size"/>
<prop v="3x:0,0,0,0,0,0" k="size_map_unit_scale"/>
<prop v="MM" k="size_unit"/>
<prop v="1" k="vertical_anchor_point"/>
<data_defined_properties>
<Option type="Map">
<Option value="" type="QString" name="name"/>
<Option name="properties"/>
<Option value="collection" type="QString" name="type"/>
</Option>
</data_defined_properties>
</layer>
</symbol>
</background>
<shadow shadowOffsetGlobal="1" shadowRadiusMapUnitScale="3x:0,0,0,0,0,0" shadowOffsetDist="1" shadowRadius="1.5" shadowRadiusUnit="MM" shadowOffsetMapUnitScale="3x:0,0,0,0,0,0" shadowRadiusAlphaOnly="0" shadowScale="100" shadowColor="0,0,0,255" shadowOffsetAngle="135" shadowOpacity="0.7" shadowDraw="0" shadowBlendMode="6" shadowUnder="0" shadowOffsetUnit="MM"/>
<dd_properties>
<Option type="Map">
<Option value="" type="QString" name="name"/>
<Option name="properties"/>
<Option value="collection" type="QString" name="type"/>
</Option>
</dd_properties>
<substitutions/>
</text-style>
<text-format useMaxLineLengthForAutoWrap="1" formatNumbers="0" plussign="0" placeDirectionSymbol="0" reverseDirectionSymbol="0" wrapChar="" leftDirectionSymbol="&lt;" autoWrapLength="0" addDirectionSymbol="0" rightDirectionSymbol=">" multilineAlign="0" decimals="3"/>
<placement placementFlags="10" geometryGenerator="" yOffset="0" centroidWhole="0" fitInPolygonOnly="0" overrunDistance="0" priority="5" geometryGeneratorEnabled="0" distUnits="MM" centroidInside="0" geometryGeneratorType="PointGeometry" distMapUnitScale="3x:0,0,0,0,0,0" quadOffset="4" maxCurvedCharAngleOut="-20" maxCurvedCharAngleIn="20" offsetUnits="MapUnit" rotationAngle="0" predefinedPositionOrder="TR,TL,BR,BL,R,L,TSR,BSR" overrunDistanceUnit="MM" preserveRotation="1" dist="0" placement="5" repeatDistance="0" repeatDistanceMapUnitScale="3x:0,0,0,0,0,0" xOffset="0" layerType="PolygonGeometry" labelOffsetMapUnitScale="3x:0,0,0,0,0,0" offsetType="0" repeatDistanceUnits="MM" overrunDistanceMapUnitScale="3x:0,0,0,0,0,0"/>
<rendering scaleVisibility="0" scaleMax="10000000" minFeatureSize="0" fontMaxPixelSize="10000" upsidedownLabels="0" scaleMin="1" limitNumLabels="0" obstacleType="0" obstacleFactor="1" fontMinPixelSize="3" drawLabels="1" maxNumLabels="2000" displayAll="0" mergeLines="0" zIndex="0" obstacle="1" fontLimitPixelSize="0" labelPerPart="0"/>
<dd_properties>
<Option type="Map">
<Option value="" type="QString" name="name"/>
<Option name="properties"/>
<Option value="collection" type="QString" name="type"/>
</Option>
</dd_properties>
<callout type="simple">
<Option type="Map">
<Option value="pole_of_inaccessibility" type="QString" name="anchorPoint"/>
<Option type="Map" name="ddProperties">
<Option value="" type="QString" name="name"/>
<Option name="properties"/>
<Option value="collection" type="QString" name="type"/>
</Option>
<Option value="false" type="bool" name="drawToAllParts"/>
<Option value="0" type="QString" name="enabled"/>
<Option value="&lt;symbol type=&quot;line&quot; alpha=&quot;1&quot; clip_to_extent=&quot;1&quot; force_rhr=&quot;0&quot; name=&quot;symbol&quot;>&lt;layer enabled=&quot;1&quot; locked=&quot;0&quot; pass=&quot;0&quot; class=&quot;SimpleLine&quot;>&lt;prop v=&quot;square&quot; k=&quot;capstyle&quot;/>&lt;prop v=&quot;5;2&quot; k=&quot;customdash&quot;/>&lt;prop v=&quot;3x:0,0,0,0,0,0&quot; k=&quot;customdash_map_unit_scale&quot;/>&lt;prop v=&quot;MM&quot; k=&quot;customdash_unit&quot;/>&lt;prop v=&quot;0&quot; k=&quot;draw_inside_polygon&quot;/>&lt;prop v=&quot;bevel&quot; k=&quot;joinstyle&quot;/>&lt;prop v=&quot;60,60,60,255&quot; k=&quot;line_color&quot;/>&lt;prop v=&quot;solid&quot; k=&quot;line_style&quot;/>&lt;prop v=&quot;0.3&quot; k=&quot;line_width&quot;/>&lt;prop v=&quot;MM&quot; k=&quot;line_width_unit&quot;/>&lt;prop v=&quot;0&quot; k=&quot;offset&quot;/>&lt;prop v=&quot;3x:0,0,0,0,0,0&quot; k=&quot;offset_map_unit_scale&quot;/>&lt;prop v=&quot;MM&quot; k=&quot;offset_unit&quot;/>&lt;prop v=&quot;0&quot; k=&quot;ring_filter&quot;/>&lt;prop v=&quot;0&quot; k=&quot;use_custom_dash&quot;/>&lt;prop v=&quot;3x:0,0,0,0,0,0&quot; k=&quot;width_map_unit_scale&quot;/>&lt;data_defined_properties>&lt;Option type=&quot;Map&quot;>&lt;Option value=&quot;&quot; type=&quot;QString&quot; name=&quot;name&quot;/>&lt;Option name=&quot;properties&quot;/>&lt;Option value=&quot;collection&quot; type=&quot;QString&quot; name=&quot;type&quot;/>&lt;/Option>&lt;/data_defined_properties>&lt;/layer>&lt;/symbol>" type="QString" name="lineSymbol"/>
<Option value="0" type="double" name="minLength"/>
<Option value="3x:0,0,0,0,0,0" type="QString" name="minLengthMapUnitScale"/>
<Option value="MM" type="QString" name="minLengthUnit"/>
<Option value="0" type="double" name="offsetFromAnchor"/>
<Option value="3x:0,0,0,0,0,0" type="QString" name="offsetFromAnchorMapUnitScale"/>
<Option value="MM" type="QString" name="offsetFromAnchorUnit"/>
<Option value="0" type="double" name="offsetFromLabel"/>
<Option value="3x:0,0,0,0,0,0" type="QString" name="offsetFromLabelMapUnitScale"/>
<Option value="MM" type="QString" name="offsetFromLabelUnit"/>
</Option>
</callout>
</settings>
</labeling>
<customproperties>
<property key="dualview/previewExpressions" value="text"/>
<property key="embeddedWidgets/count" value="0"/>
<property key="variableNames"/>
<property key="variableValues"/>
</customproperties>
<blendMode>0</blendMode>
<featureBlendMode>0</featureBlendMode>
<layerOpacity>1</layerOpacity>
<SingleCategoryDiagramRenderer diagramType="Histogram" attributeLegend="1">
<DiagramCategory diagramOrientation="Up" spacingUnitScale="3x:0,0,0,0,0,0" scaleBasedVisibility="0" showAxis="0" backgroundColor="#ffffff" enabled="0" minScaleDenominator="100000" sizeScale="3x:0,0,0,0,0,0" barWidth="5" opacity="1" backgroundAlpha="255" direction="1" height="15" sizeType="MM" labelPlacementMethod="XHeight" penAlpha="255" scaleDependency="Area" penWidth="0" spacingUnit="MM" lineSizeType="MM" minimumSize="0" penColor="#000000" rotationOffset="270" width="15" maxScaleDenominator="1e+08" spacing="0" lineSizeScale="3x:0,0,0,0,0,0">
<fontProperties description="Ubuntu,11,-1,5,50,0,0,0,0,0" style=""/>
<attribute label="" color="#000000" field=""/>
<axisSymbol>
<symbol type="line" alpha="1" clip_to_extent="1" force_rhr="0" name="">
<layer enabled="1" locked="0" pass="0" class="SimpleLine">
<prop v="square" k="capstyle"/>
<prop v="5;2" k="customdash"/>
<prop v="3x:0,0,0,0,0,0" k="customdash_map_unit_scale"/>
<prop v="MM" k="customdash_unit"/>
<prop v="0" k="draw_inside_polygon"/>
<prop v="bevel" k="joinstyle"/>
<prop v="35,35,35,255" k="line_color"/>
<prop v="solid" k="line_style"/>
<prop v="0.26" k="line_width"/>
<prop v="MM" k="line_width_unit"/>
<prop v="0" k="offset"/>
<prop v="3x:0,0,0,0,0,0" k="offset_map_unit_scale"/>
<prop v="MM" k="offset_unit"/>
<prop v="0" k="ring_filter"/>
<prop v="0" k="use_custom_dash"/>
<prop v="3x:0,0,0,0,0,0" k="width_map_unit_scale"/>
<data_defined_properties>
<Option type="Map">
<Option value="" type="QString" name="name"/>
<Option name="properties"/>
<Option value="collection" type="QString" name="type"/>
</Option>
</data_defined_properties>
</layer>
</symbol>
</axisSymbol>
</DiagramCategory>
</SingleCategoryDiagramRenderer>
<DiagramLayerSettings priority="0" placement="0" zIndex="0" linePlacementFlags="2" dist="0" obstacle="0" showAll="1">
<properties>
<Option type="Map">
<Option value="" type="QString" name="name"/>
<Option name="properties"/>
<Option value="collection" type="QString" name="type"/>
</Option>
</properties>
</DiagramLayerSettings>
<geometryOptions geometryPrecision="0" removeDuplicateNodes="0">
<activeChecks/>
<checkConfiguration type="Map">
<Option type="Map" name="QgsGeometryGapCheck">
<Option value="0" type="double" name="allowedGapsBuffer"/>
<Option value="false" type="bool" name="allowedGapsEnabled"/>
<Option value="" type="QString" name="allowedGapsLayer"/>
</Option>
</checkConfiguration>
</geometryOptions>
<referencedLayers/>
<referencingLayers/>
<fieldConfiguration>
<field name="text">
<editWidget type="TextEdit">
<config>
<Option/>
</config>
</editWidget>
</field>
</fieldConfiguration>
<aliases>
<alias index="0" name="" field="text"/>
</aliases>
<excludeAttributesWMS/>
<excludeAttributesWFS/>
<defaults>
<default applyOnUpdate="0" expression="" field="text"/>
</defaults>
<constraints>
<constraint notnull_strength="0" exp_strength="0" unique_strength="0" constraints="0" field="text"/>
</constraints>
<constraintExpressions>
<constraint desc="" exp="" field="text"/>
</constraintExpressions>
<expressionfields/>
<attributeactions>
<defaultAction key="Canvas" value="{00000000-0000-0000-0000-000000000000}"/>
</attributeactions>
<attributetableconfig actionWidgetStyle="dropDown" sortExpression="" sortOrder="0">
<columns>
<column width="-1" hidden="1" type="actions"/>
<column width="-1" hidden="0" type="field" name="text"/>
</columns>
</attributetableconfig>
<conditionalstyles>
<rowstyles/>
<fieldstyles/>
</conditionalstyles>
<storedexpressions/>
<editform tolerant="1"></editform>
<editforminit/>
<editforminitcodesource>0</editforminitcodesource>
<editforminitfilepath></editforminitfilepath>
<editforminitcode><![CDATA[# -*- coding: utf-8 -*-
"""
QGIS forms can have a Python function that is called when the form is
opened.
Use this function to add extra logic to your forms.
Enter the name of the function in the "Python Init function"
field.
An example follows:
"""
from PyQt4.QtGui import QWidget

def my_form_open(dialog, layer, feature):
geom = feature.geometry()
control = dialog.findChild(QWidget, "MyLineEdit")
]]></editforminitcode>
<featformsuppress>0</featformsuppress>
<editorlayout>generatedlayout</editorlayout>
<editable>
<field name="text" editable="1"/>
</editable>
<labelOnTop>
<field labelOnTop="0" name="text"/>
</labelOnTop>
<widgets/>
<previewExpression>text</previewExpression>
<mapTip></mapTip>
<layerGeometryType>2</layerGeometryType>
</qgis>
@@ -0,0 +1,8 @@
{
"type": "FeatureCollection",
"name": "polygon_with_bump",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::32613" } },
"features": [
{ "type": "Feature", "properties": { "text": "Polygon" }, "geometry": { "type": "Polygon", "coordinates": [ [ [ 606838.421769172884524, 4823365.723994126543403 ], [ 606830.548566220561042, 4825499.961815882474184 ], [ 609650.881638120510615, 4825504.254800137132406 ], [ 611167.537569519481622, 4826799.859664612449706 ], [ 612373.130530139664188, 4826772.515005190856755 ], [ 612320.06524959357921, 4823344.497881907969713 ], [ 606838.421769172884524, 4823365.723994126543403 ] ] ] } }
]
}

0 comments on commit a16e424

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