[mapserver-users] About FILTER and FILTERITEM
Rahkonen Jukka (Tike)
jukka.rahkonen at mmmtike.fi
Tue May 20 05:09:46 PDT 2014
Hi,
Obviously I was wrong and concatenation works with MS 6.x series as suggested by Håvart Tveite:
FILTER ("[STATE_NAME]"+"[STATE_FIPS]"="Illinois17")
This is a good question to Mapserver Guru Quiz final (no internet connections allowed).
-Jukka-
Rahkonen Jukka wrote:
>
> Hi,
>
> I started to play with filter and filteritem because I happened to see this
> question http://gis.stackexchange.com/questions/65724/mapserver-6-2-
> concatenate-attributes-in-filter. I thought that the idea was odd and unpractical
> but interesting and I thought it would be fast to test. It was not but at least it
> was educational.
>
> I can do such concatenation simply with Spatialite data by using the layer DATA
> as CONNECTION "\ms4w\apps\states_spl_3.sqlite"
> DATA "select * from states_view where STATE_NAME||STATE_FIPS='Illinois17'"
>
> I am ready to believe that such concatenation with FILTER is not possible with
> the 6.x series. Other opinions?
>
> -Jukka Rahkonen-
>
> Lime, Steve D (MNIT) wrote:
> >
> > FIlters are used primarily under the hood for certain types of query operations.
> > The main differences are:
> >
> > - FILTERs are defined in the native query language of the underlying
> > driver. So for PostGIS you'd actually write a little SQL snippet.
> > - FILTERs are applied when data are pulled from the underlying data
> > source (like a WHERE clause) and have no impact on rendering choices.
> >
> > For drivers that don't have an native query capability (e.g.
> > shapefiles) the syntax is identical to expressions. For drivers that
> > do have a native query capability there really isn't much use for
> > filters since you can just add a where clause to the data statement.
> >
> > Where I have found them useful sometimes is for simplifying class expressions.
> > Let's say you have a shapefile and you only want to show features of a
> > certain type, and then for those features you want to draw things
> > differently based on another attribute.
> >
> > You could use logical expressions:
> >
> > CLASS
> > EXPRESSION ([type] = 1 AND '[attr]' = 'a')
> > ...
> > END
> > CLASS
> > EXPRESSION ([type] = 1 AND '[attr]' = 'b')
> > ...
> > END
> >
> > or you could use a combination of FILTER and EXPRESSIONS
> >
> > FILTERITEM 'type'
> > FILTER '1'
> >
> > CLASSITEM 'attr'
> > CLASS
> > EXPRESSION 'a'
> > ...
> > END
> > CLASS
> > EXPRESSION 'b'
> > ...
> > END
> >
> > Personal preference I guess and the second option is a bit more
> > performant, especially in older versions. I guess my recommendation
> > would be avoid FILTERs unless you have a good reason to use them.
> >
> > Steve
> >
> > ________________________________________
> > From: mapserver-users-bounces at lists.osgeo.org [mapserver-users-
> > bounces at lists.osgeo.org] on behalf of Rahkonen Jukka (Tike)
> > [jukka.rahkonen at mmmtike.fi]
> > Sent: Wednesday, May 14, 2014 8:05 AM
> > To: mapserver-users at lists.osgeo.org
> > Subject: Re: [mapserver-users] About FILTER and FILTERITEM
> >
> > Hi,
> >
> > Thank you very much, Christy. By your example I made some tests and
> > now filters like this work for me FILTER (([WORKERS]>20000000) OR
> > ("[STATE_FIPS]"="17"))
> >
> > The secret element was the right syntax for string attributes
> > ("[STATE_FIPS]"="17").
> > Now when I know how it must be used I can find corresponding examples
> > from the expression page of Mapserver documentation. Could someone
> > explain shortly what is the difference between filter and expression?
> > To me they seem to do pretty similar work.
> >
> > -Jukka Rahkonen-
> >
> > Christy Nieman wrote:
> >
> > > You do not need to set both FILTERITEM and FILTER. You can just set
> > > FILTER to an expression using as many attributes as you need. e.g.
> > > FILTER (( [POPULATION] < 500000 ) AND ("[DISPLAY]" == "1")). Just
> > > like you can have multiple attributes in a class EXPRESSION.
> > >
> > > I think it's the section of the document that is key - the
> > > "MapServer
> > Expressions"
> > > section talks about using FILTER and EXPRESSION in more complex
> > > logical expressions, where as the section you quoted is talking
> > > about basic string comparison.
> > >
> > > Christy
> > >
> > > On 14/05/14 08:03 AM, Rahkonen Jukka (Tike) wrote:
> > > > Hi,
> > > >
> > > > From document page: http://mapserver.org/mapfile/expressions.html
> > > > "To use a string comparison for filtering a LAYER, both FILTERITEM
> > > > and FILTER
> > > must be set. FILTERITEM is set to the attribute name. FILTER is set
> > > to the value for comparison. The same rule applies to CLASSITEM in
> > > the LAYER object and EXPRESSION in the CLASS object."
> > > >
> > > > That would mean that only one attribute from the data can be used
> > > > for
> > > building a filter. Is this true or just old information living in the document?
> > > >
> > > > -Jukka Rahkonen-
> > > > _______________________________________________
> > > > mapserver-users mailing list
> > > > mapserver-users at lists.osgeo.org
> > > > http://lists.osgeo.org/mailman/listinfo/mapserver-users
> > >
> > > _______________________________________________
> > > mapserver-users mailing list
> > > mapserver-users at lists.osgeo.org
> > > http://lists.osgeo.org/mailman/listinfo/mapserver-users
> > _______________________________________________
> > mapserver-users mailing list
> > mapserver-users at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/mapserver-users
> >
More information about the MapServer-users
mailing list