Skip to content
Permalink
Browse files

Support FILTER values with colons

  • Loading branch information
Éric Lemoine
Éric Lemoine committed May 15, 2019
1 parent 2cc8e11 commit b0ae641b066aff175fa47e5d2999cbe3f6bbb188
@@ -1431,16 +1431,18 @@ namespace QgsWms
{
// filter format: "LayerName,LayerName2:filterString;LayerName3:filterString2;..."
// several filters can be defined for one layer
const QStringList splits = f.split( ':' );
if ( splits.size() == 2 )
const int colonIndex = f.indexOf( ':' );
if ( colonIndex != -1 )
{
const QStringList layers = splits[0].split( ',' );
for ( const QString &layer : layers )
const QString layers = f.section( ':', 0, 0 );
const QString filter = f.section( ':', 1 );
const QStringList layersList = layers.split( ',' );
for ( const QString &layer : layersList )
{
QgsWmsParametersFilter filter;
filter.mFilter = splits[1];
filter.mType = QgsWmsParametersFilter::SQL;
filters.insert( layer, filter );
QgsWmsParametersFilter parametersFilter;
parametersFilter.mFilter = filter;
parametersFilter.mType = QgsWmsParametersFilter::SQL;
filters.insert( layer, parametersFilter );
}
}
else
@@ -869,6 +869,26 @@ def test_wms_getmap_filter(self):
r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_Filter5")

# test that filters with colons in values work as expected
projectPath = os.path.join(self.testdata_path, "test_project_wms_filter.qgs")
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(projectPath),
"SERVICE": "WMS",
"VERSION": "1.1.1",
"REQUEST": "GetMap",
"LAYERS": "points",
"STYLES": "",
"FORMAT": "image/png",
"BBOX": "-80000,25000,-15000,50000.0",
"HEIGHT": "500",
"WIDTH": "500",
"CRS": "EPSG:3857",
"FILTER": "points:\"name\" = 'foo:bar'"
}.items())])

r, h = self._result(self._execute_request(qs))
self._img_diff_error(r, h, "WMS_GetMap_Filter6")

# Error in filter (missing quote after africa) with multiple layer filter
qs = "?" + "&".join(["%s=%s" % i for i in list({
"MAP": urllib.parse.quote(self.projectPath),
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,306 @@
<!DOCTYPE qgis PUBLIC 'http://mrcc.com/qgis.dtd' 'SYSTEM'>
<qgis projectname="" version="3.6.0-Noosa">
<homePath path=""/>
<title></title>
<autotransaction active="0"/>
<evaluateDefaultValues active="0"/>
<trust active="0"/>
<projectCrs>
<spatialrefsys>
<proj4>+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs</proj4>
<srsid>3857</srsid>
<srid>3857</srid>
<authid>EPSG:3857</authid>
<description>WGS 84 / Pseudo-Mercator</description>
<projectionacronym>merc</projectionacronym>
<ellipsoidacronym>WGS84</ellipsoidacronym>
<geographicflag>false</geographicflag>
</spatialrefsys>
</projectCrs>
<layer-tree-group>
<customproperties/>
<layer-tree-layer providerKey="ogr" source="./test_project_wms_filter.gpkg|layername=points" id="points_751bafcd_6bc0_4d4b_9901_dd09704a0e9b" checked="Qt::Checked" name="points" expanded="1">
<customproperties/>
</layer-tree-layer>
<custom-order enabled="0">
<item>points_751bafcd_6bc0_4d4b_9901_dd09704a0e9b</item>
</custom-order>
</layer-tree-group>
<snapping-settings enabled="0" mode="2" tolerance="12" unit="1" type="1" intersection-snapping="0">
<individual-layer-settings>
<layer-setting units="1" enabled="0" id="points_751bafcd_6bc0_4d4b_9901_dd09704a0e9b" tolerance="12" type="1"/>
</individual-layer-settings>
</snapping-settings>
<relations/>
<mapcanvas annotationsVisible="1" name="theMapCanvas">
<units>meters</units>
<extent>
<xmin>-218187.4328507388709113</xmin>
<ymin>-102171.74223070539301261</ymin>
<xmax>169699.14840226876549423</xmax>
<ymax>120478.54350206544040702</ymax>
</extent>
<rotation>0</rotation>
<destinationsrs>
<spatialrefsys>
<proj4>+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs</proj4>
<srsid>3857</srsid>
<srid>3857</srid>
<authid>EPSG:3857</authid>
<description>WGS 84 / Pseudo-Mercator</description>
<projectionacronym>merc</projectionacronym>
<ellipsoidacronym>WGS84</ellipsoidacronym>
<geographicflag>false</geographicflag>
</spatialrefsys>
</destinationsrs>
<rendermaptile>0</rendermaptile>
<expressionContextScope/>
</mapcanvas>
<legend updateDrawingOrder="true">
<legendlayer showFeatureCount="0" checked="Qt::Checked" name="points" drawingOrder="-1" open="true">
<filegroup hidden="false" open="true">
<legendlayerfile isInOverview="0" layerid="points_751bafcd_6bc0_4d4b_9901_dd09704a0e9b" visible="1"/>
</filegroup>
</legendlayer>
</legend>
<mapViewDocks/>
<mapViewDocks3D/>
<projectlayers>
<maplayer hasScaleBasedVisibilityFlag="0" simplifyDrawingHints="1" autoRefreshTime="0" refreshOnNotifyMessage="" minScale="1e+08" refreshOnNotifyEnabled="0" simplifyMaxScale="1" maxScale="0" simplifyLocal="1" readOnly="0" geometry="Point" styleCategories="AllStyleCategories" labelsEnabled="0" simplifyDrawingTol="1" type="vector" autoRefreshEnabled="0" simplifyAlgorithm="0">
<extent>
<xmin>-77432.828125</xmin>
<ymin>26718.03125</ymin>
<xmax>-18059.41015625</xmax>
<ymax>46261.78515625</ymax>
</extent>
<id>points_751bafcd_6bc0_4d4b_9901_dd09704a0e9b</id>
<datasource>./test_project_wms_filter.gpkg|layername=points</datasource>
<keywordList>
<value></value>
</keywordList>
<layername>points</layername>
<srs>
<spatialrefsys>
<proj4>+proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +wktext +no_defs</proj4>
<srsid>3857</srsid>
<srid>3857</srid>
<authid>EPSG:3857</authid>
<description>WGS 84 / Pseudo-Mercator</description>
<projectionacronym>merc</projectionacronym>
<ellipsoidacronym>WGS84</ellipsoidacronym>
<geographicflag>false</geographicflag>
</spatialrefsys>
</srs>
<resourceMetadata>
<identifier></identifier>
<parentidentifier></parentidentifier>
<language></language>
<type>dataset</type>
<title></title>
<abstract></abstract>
<links/>
<fees></fees>
<encoding></encoding>
<crs>
<spatialrefsys>
<proj4></proj4>
<srsid>0</srsid>
<srid>0</srid>
<authid></authid>
<description></description>
<projectionacronym></projectionacronym>
<ellipsoidacronym></ellipsoidacronym>
<geographicflag>false</geographicflag>
</spatialrefsys>
</crs>
<extent/>
</resourceMetadata>
<provider encoding="UTF-8">ogr</provider>
<vectorjoins/>
<layerDependencies/>
<dataDependencies/>
<legend type="default-vector"/>
<expressionfields/>
<map-layer-style-manager current="default">
<map-layer-style name="default"/>
</map-layer-style-manager>
<auxiliaryLayer/>
<flags>
<Identifiable>1</Identifiable>
<Removable>1</Removable>
<Searchable>1</Searchable>
</flags>
<renderer-v2 enableorderby="0" type="singleSymbol" symbollevels="0" forceraster="0">
<symbols>
<symbol clip_to_extent="1" alpha="1" type="marker" name="0" force_rhr="0">
<layer class="SimpleMarker" locked="0" enabled="1" pass="0">
<prop v="0" k="angle"/>
<prop v="231,113,72,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="Pixel" 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="Pixel" k="outline_width_unit"/>
<prop v="diameter" k="scale_method"/>
<prop v="30" k="size"/>
<prop v="3x:0,0,0,0,0,0" k="size_map_unit_scale"/>
<prop v="Pixel" 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>
</symbols>
<rotation/>
<sizescale/>
</renderer-v2>
<customproperties/>
<blendMode>0</blendMode>
<featureBlendMode>0</featureBlendMode>
<layerOpacity>1</layerOpacity>
<geometryOptions geometryPrecision="0" removeDuplicateNodes="0">
<activeChecks/>
<checkConfiguration/>
</geometryOptions>
<fieldConfiguration>
<field name="id">
<editWidget type="">
<config>
<Option/>
</config>
</editWidget>
</field>
<field name="name">
<editWidget type="">
<config>
<Option/>
</config>
</editWidget>
</field>
<field name="date">
<editWidget type="">
<config>
<Option/>
</config>
</editWidget>
</field>
</fieldConfiguration>
<aliases>
<alias field="id" index="0" name=""/>
<alias field="name" index="1" name=""/>
<alias field="date" index="2" name=""/>
</aliases>
<excludeAttributesWMS/>
<excludeAttributesWFS/>
<defaults>
<default applyOnUpdate="0" expression="" field="id"/>
<default applyOnUpdate="0" expression="" field="name"/>
<default applyOnUpdate="0" expression="" field="date"/>
</defaults>
<constraints>
<constraint constraints="3" notnull_strength="1" field="id" exp_strength="0" unique_strength="1"/>
<constraint constraints="0" notnull_strength="0" field="name" exp_strength="0" unique_strength="0"/>
<constraint constraints="0" notnull_strength="0" field="date" exp_strength="0" unique_strength="0"/>
</constraints>
<constraintExpressions>
<constraint desc="" exp="" field="id"/>
<constraint desc="" exp="" field="name"/>
<constraint desc="" exp="" field="date"/>
</constraintExpressions>
<expressionfields/>
<attributeactions>
<defaultAction key="Canvas" value="{00000000-0000-0000-0000-000000000000}"/>
</attributeactions>
<attributetableconfig sortExpression="" actionWidgetStyle="dropDown" sortOrder="0">
<columns/>
</attributetableconfig>
<conditionalstyles>
<rowstyles/>
<fieldstyles/>
</conditionalstyles>
<editform tolerant="1"></editform>
<editforminit/>
<editforminitcodesource>0</editforminitcodesource>
<editforminitfilepath></editforminitfilepath>
<editforminitcode><![CDATA[]]></editforminitcode>
<featformsuppress>0</featformsuppress>
<editorlayout>generatedlayout</editorlayout>
<editable/>
<labelOnTop/>
<widgets/>
<previewExpression></previewExpression>
<mapTip></mapTip>
</maplayer>
</projectlayers>
<layerorder>
<layer id="points_751bafcd_6bc0_4d4b_9901_dd09704a0e9b"/>
</layerorder>
<properties>
<Gui>
<SelectionColorGreenPart type="int">255</SelectionColorGreenPart>
<SelectionColorAlphaPart type="int">255</SelectionColorAlphaPart>
<SelectionColorRedPart type="int">255</SelectionColorRedPart>
<CanvasColorRedPart type="int">255</CanvasColorRedPart>
<CanvasColorBluePart type="int">255</CanvasColorBluePart>
<CanvasColorGreenPart type="int">255</CanvasColorGreenPart>
<SelectionColorBluePart type="int">0</SelectionColorBluePart>
</Gui>
<Measure>
<Ellipsoid type="QString">WGS84</Ellipsoid>
</Measure>
<Measurement>
<DistanceUnits type="QString">meters</DistanceUnits>
<AreaUnits type="QString">m2</AreaUnits>
</Measurement>
<Legend>
<filterByMap type="bool">false</filterByMap>
</Legend>
<Paths>
<Absolute type="bool">false</Absolute>
</Paths>
<SpatialRefSys>
<ProjectionsEnabled type="int">1</ProjectionsEnabled>
</SpatialRefSys>
<PositionPrecision>
<Automatic type="bool">true</Automatic>
<DecimalPlaces type="int">2</DecimalPlaces>
</PositionPrecision>
<PAL>
<CandidatesPoint type="int">16</CandidatesPoint>
<DrawRectOnly type="bool">false</DrawRectOnly>
<ShowingAllLabels type="bool">false</ShowingAllLabels>
<SearchMethod type="int">0</SearchMethod>
<CandidatesPolygon type="int">30</CandidatesPolygon>
<ShowingPartialsLabels type="bool">true</ShowingPartialsLabels>
<TextFormat type="int">0</TextFormat>
<ShowingCandidates type="bool">false</ShowingCandidates>
<CandidatesLine type="int">50</CandidatesLine>
</PAL>
</properties>
<visibility-presets/>
<transformContext/>
<projectMetadata>
<identifier></identifier>
<parentidentifier></parentidentifier>
<language></language>
<type></type>
<title></title>
<abstract></abstract>
<links/>
<author></author>
<creation>2019-05-15T14:23:27</creation>
</projectMetadata>
<Annotations/>
<Layouts/>
</qgis>

0 comments on commit b0ae641

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