Styling wms by request parameter - geoserver

in general:
Is it possible to differently style some of the wms features from a single wms query based on the cql filter, or other parameter?
in particular:
on a wms query, returning the raster of a collection of features (i.e. points styled as red dots),
i wish geoserver to differrently style (blue dot) just one particular feature identified by a http-req-parameter sent with the wms request
keeping the others in the collection with default style
and avoiding an overlap of two wms:

A quicker (and probably easier) way than #Fmba's suggestion is to request the layer twice, once with the default color and a second time with a filter and a highlight style. You could either do this in one request or make two requests so that the browser can cache the default layer and only refetch the highlights.
For the first request it would look something like:
http://....../wms?service=wms&.....&layers=dots,dots&styles=,highlight&cql_filter=INCLUDE;INTERSECT(the_geom,%20POINT%20(-74.817265%2040.5296504))
This requests the layer (dots) twice, once with the default style (or you could use a named style here too) and then with the highlight style. Finally you must supply two filters (the first is just true to return everything).
while in the second you would just add another layer as usual.

You can use both filters and variable substitution for this.
Your SLD could be something like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!-- a Named Layer is the basic building block of an SLD document -->
<NamedLayer>
<Name>default_point</Name>
<UserStyle>
<!-- Styles can have names, titles and abstracts -->
<Title>Default Point</Title>
<Abstract>A sample style that draws a point</Abstract>
<FeatureTypeStyle>
<Rule>
<Name>rule1</Name>
<Title>Red Square</Title>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>square</WellKnownName>
<Fill>
<CssParameter name="fill">#FF0000</CssParameter>
</Fill>
</Mark>
<Size>6</Size>
</Graphic>
</PointSymbolizer>
</Rule>
<Rule>
<Name>rule2</Name>
<Title>Blue Square</Title>
<ogc:Filter>
<ogc:PropertyIsEqualTo>
<ogc:PropertyName>name</ogc:PropertyName>
<ogc:Function name="env">
<ogc:Literal>element</ogc:Literal>
</ogc:Function>
</ogc:PropertyIsEqualTo>
</ogc:Filter>
<PointSymbolizer>
<Graphic>
<Mark>
<WellKnownName>square</WellKnownName>
<Fill>
<CssParameter name="fill">#0000FF</CssParameter>
</Fill>
</Mark>
<Size>6</Size>
</Graphic>
</PointSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
See that we are using a parameter called 'element' (as we defined in the SLD) in the 'env' parameter (at the end of the request), wich you can assign a value in the wms request, so only the feature with a value of 'name_yo_want_to_filter' for the attribute 'name' would be rendered as blue, like this:
http://your_geoserver/wms?LAYERS=your_layer&STYLES=&FORMAT=image%2Fpng&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&SRS=EPSG%3A25830&BBOX=177329.45520721,4198063.2254456,177681.24924735,4198495.164411&WIDTH=417&HEIGHT=512&env=element:name_yo_want_to_filter
Bear in mind that 'fid' would not be a valid parameter as it is usually hidden, so geoserver wont accept a 'PropertyIsEqualTo' filter of it.
Ref: http://docs.geoserver.org/latest/en/user/styling/sld-extensions/substitution.html
Ref: http://docs.geoserver.org/latest/en/user/styling/sld-reference/filters.html

Related

Geoserver raster with external SLD

I want to use an external SLD (hosted in my server) for symbolizing a raster in Geoserver.
The SLD below works if used as default style in Geoserver. If I copy it (changing some colors) and put outside Geoserver, save as SLD (or XML), and call the GetMap with SLD=https://my_server/mySLD.sld the map I get is still with the 'default, Geoserver' style
<StyledLayerDescriptor version="1.0.0"
xsi:schemaLocation="http://www.opengis.net/sld StyledLayerDescriptor.xsd"
xmlns="http://www.opengis.net/sld"
xmlns:ogc="http://www.opengis.net/ogc"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:se="http://www.opengis.net/se">
<NamedLayer>
<Name>my_schema:my_layer</Name>
<UserStyle>
<FeatureTypeStyle>
<Rule>
<RasterSymbolizer>
<Geometry>
<PropertyName>GRAY_INDEX</PropertyName>
</Geometry>
<Opacity>1</Opacity>
<ColorMap>
<ColorMapEntry color="#E69800" label="1" opacity="0.0" quantity="0.0"/>
<ColorMapEntry color="#1b4bde" label="Building" opacity="1.0" quantity="1.0"/>
<ColorMapEntry color="#bcbcbc" label="Ground cover" opacity="1.0" quantity="2.0"/>
</ColorMap>
</RasterSymbolizer>
</Rule>
</FeatureTypeStyle>
</UserStyle>
</NamedLayer>
</StyledLayerDescriptor>
shortly, WMS call would be like this (also tried withou STYLES param)
https://my_geoserver_url/wms?service=WMS&version=1.1.0&request=GetMap&layers=my_schema:my_layer&STYLES=&SLD=https://my_server/my_sld.sld&transparent=true&bbox=...&format=image/png
I did this for dynamic filtering in vectorial data and all good (SLDs are created dynamically via PHP), so I am wondering if the problem is that with RASTER data is not possible
You are trying to operate in library mode:
Style lookup in library mode operates as follows:
For each layer in the layers list, the applied style is either a named style specified in the styles list (if present), or the layerdefault style
For a named style, if the external style document has a <NamedLayer>...<UserStyle> with matching layer name and style name, then it is used. Otherwise, the style name is searched for in the
catalog. If it is not found there, an error occurs.
For a default style, the external style document is searched to find a <NamedLayer> element with the layer name. If it contains a
<UserStyle> with the <IsDefault> element having the value 1 then that
style is used. Otherwise, the default server style for the layer
(which must exist) is used.
So you either need to provide a named style in the styles parameter or make your style a default style by adding <IsDefault>1</IsDefault> to it.

XSL-FO: Looking for If-statement to detect odd or even page.

I'm trying to find a way to detect if the page being generated is odd or even in a template to left/right justify content. For example, a block of text with symbol next to it. The symbol would be left justified on one page, and right justified on the next.
I don't think checking fo:page-number is possible. And I can't figure out a way that would work with region-start/region-end because the symbol wouldn't line up with it's associated block of text in region-body.
<fo:layout-master-set>
<fo:simple-page-master master-name="EvenPage">
<fo:region-body />
</fo:simple-page-master>
<fo:simple-page-master master-name="OddPage">
<fo:region-body />
</fo:simple-page-master>
<fo:page-sequence-master master-name="Content">
<fo:repeatable-page-master-alternatives>
<fo:conditional-page-master-reference master-reference="OddPage" odd-or-even="odd"/>
<fo:conditional-page-master-reference master-reference="EvenPage" odd-or-even="even"/>
</fo:repeatable-page-master-alternatives>
</fo:page-sequence-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="Content">
<fo:flow>
<xsl:apply-templates select="*"/>
</fo:flow>
</fo:page-sequence>
There is no if-statement to detect an odd or even page.
You could (or may be able to) use float="outside" to float your symbol to the outside of the page. However, it's not clear to me from FOP's stated limitations on fo:float support (http://xmlgraphics.apache.org/fop/fo.html#floats) whether float="outside" is supported or not (although it is supported by other XSL formatters, including AH Formatter).

Adding Images or Thumbnails to Atom 1.0 Entries

This StackOverflow answer suggests that you should use HTML entry content and use a standard <img> tag to link to your images.
<content type="html">
<![CDATA[
<a href="http://test.lvh.me:3000/listings/341-test-pics?locale=en">
<img alt="test_pic" src="http://test.lvh.me:3000/system/images/20/medium/test_pic.jpg?1343246102" />
</a>
]]>
</content>
I have also found something called the Yahoo media extensions here which allows you to add custom additional elements.
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
<!-- ommitted -->
<entry>
<!-- ommitted -->
<media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="path_to_image.jpg" />
</entry>
</feed>
Google also seems to have its own similar extensions. See here.
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">
<!-- ommitted -->
<entry>
<!-- ommitted -->
<g:image_link>http://www.google.com/images/google_sm.gif</g:image_link>
</entry>
</feed>
My own intuition tells me I should simply be able to add links to images like so:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<!-- ommitted -->
<entry>
<!-- ommitted -->
<link rel="enclosure" type="image/png" length="1337"
href="http://example.org/image.png"/>
</entry>
</feed>
What is the correct approach for maximum compatibility?
The best practice is to do what Wordpress RSS 2.0 feeds do — if you want your post image to appear in feedly for example, put the <p><img...></p> at the top of the content. My eleventy setup has post header image inside article, but outside content variable's contents which are used in the feed. I solve the problem adding the image back:
<item>
...
<content:encoded>
<![CDATA[<p>{% include "src/components/partials/post-hero-img.njk" %}</p>{{ post.templateContent | textDeletePresentationDivs | htmlToAbsoluteUrls(absolutePostUrl) | safe }}]]>
</content:encoded>
source in git
I checked, neither Atom nor RSS 2.0 feeds have post images set anywhere as standalone tags. They're simply at the top of the article's content.
With regards to your examples...
The "vanilla" Atom RSS feed has a schema xmlns="http://www.w3.org/2005/Atom" and its documentation is defined in RFC4287.
According to it, "vanilla" Atom RSS feed strictly can have <logo> which is the 2:1 ratio image, the logo of the feed. Sadly, it is placed in the root of XML (notice atom:logo in the spec, it's not atom:entry:logo). Practically, this means, you can put a picture of your RSS feed itself, but not per-article. If you do put <logo> inside <entry>, the feed won't pass the validators and post image won't appear in feedly (I tried).
Also, spec defines <icon> which is vaguely defined as a small, square image, also placed in the root. Feedly seem to detect the website's favicon anyway, although it doesn't hurt to set this tag up in rss explicitly.
That's all there is — Atom spec doesn't officially define a way how to put images per-article.
Here's where additional namespaces come in (or RSS 2.0, different spec, different XML). You mentioned xmlns:media="http://search.yahoo.com/mrss/" in example. I tried it, post images won't show in feedly. Plus, spec link http://search.yahoo.com/mrss/ is not showing any specs.
Google namespace you quoted, xmlns:g="http://base.google.com/ns/1.0" also doesn't work, post images don't show up in feedly.
The link approach, <link rel="enclosure" type="image/png" length="1337" href="http://example.org/image.png"/> would be promising except length is meant to state the filesize in bytes. In Eleventy that's problematic value to get, for example.
To sum up, the best practice is put post header image at the top of the content, inside <content>.

How can I add parameters to the Yahoo MRSS feed generated by Kaltura KMC?

I'm using the Kaltura KMC to generate a Yahoo! MRSS feed (per the info here).
The feed it creates looks like this:
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:dcterms="http://purl.org/dc/terms/">
<channel>
<title>yahoo mrss feed</title>
<link>http://xxxx.com</link>
<description></description>
<item>
<title>My Dog Clip</title>
<link>http://xxxx.com?videoid=0_udwmgjec</link>
<media:content url="http://xxxx.com/p/100/sp/10000/serveFlavor/flavorId/0_e5h0z4cf">
<media:title>My Dog Clip</media:title>
<media:description>Here is a clip of the dog playing!</media:description>
<media:keywords>dog clip</media:keywords>
<media:thumbnail url="http://xxxx.com/p/100/sp/10000/thumbnail/entry_id/0_udwmgjec/version/100002"></media:thumbnail>
<media:category scheme="http://search.yahoo.com/mrss/category_schema">Entertainment & TV</media:category>
<media:player url="http://xxxx.com/kwidget/wid/_100/entry_id/0_udwmgjec/ui_conf_id/48501"></media:player>
<media:rating scheme="urn:simple"></media:rating>
</media:content>
</item>
</channel>
</rss>
This is pretty good, but I see two things that need adjusting:
On the <media:content> tag, I'd like to add the type parameter, indicating the MIME type. Is there a way to do this through the KMC interface?
I'd like to change the default size of the thumbnail it generates (and also add the image suffix, like .jpg, to the end of the URL). Is there an option for that in the KMC?
It seems like I might end up needing to use the API to build the MRSS feed myself on the fly (pulling the video data from Kaltura via the API). What do you think?
Thank you...
You can use the dynamic MRSS
To upload your owned XSD, and modify the original.

How to theme Series when using a theme.xml in system.web.helpers.chart

The support on this is currently horrible.
I'm creating my own theme for a System.Web.Helpers.Chart by using a XML file.
I've figured that the XML is basically a serialized version of the UIDataVizualazation namespace.
It works fine but I have no idea how to set theme objects tied to the Series property.
<Chart >
<ChartAreas>
<ChartArea>
<AxisY>
<MajorGrid />
</AxisY>
<AxisX>
<MajorGrid />
</AxisX>
</ChartArea>
</ChartAreas>
<Legends>
<Legend />
</Legends>
</Chart>
This is something I can manage pretty easily but according to the Chart object System.Web.UI.DataVisualization.Charting.Chart
has a series property that is a collection of series objects and
<Series>
<Series />
</Series>
Just doesn't do it. So if someone can point me towards a Xml schema for this or a pointer on how to access the Series property so I can change things like isValueShownAsLabel attribute I would appriciate it
Through experimentation I found that the case matters.
It should be:
<Series>
<series>
</series>
</Series>
Also this property may be of usefulness to anyone that is looking for an answer to this:
CustomProperties="PieLabelStyle=Outside"
Which can be placed in a series or point and perhaps other elements as well.
A list of the properties can be found here.
You can Serialize and Deserialize Chart yourself.
Take a look here Chart Serialization
I know this is too late to help you now but you can change series properties such as line width, colour, and labelling using
<Series>
<Series Name="Default" _Template_="All" BorderWidth="3" IsValueShownAsLabel="True" />
</Series>

Resources