[Geoserver-users] SLD time functions

Using GeoServer 2.1.4 I'm looking for the possibility to use (system) time
functions in SLDs.

Concrete: we have layer stores with data sets containing a text time stamp
like '2010-03-01' or '2012/04/01'. Now the SLD should display all data which
are older than 2 years - looking at the actual date ... - in an other color
than the default color.

Are there any suggestions?

Best
Wolfram

--
View this message in context: http://osgeo-org.1560.n6.nabble.com/SLD-time-functions-tp5042909.html
Sent from the GeoServer - User mailing list archive at Nabble.com.

On Tue, Mar 26, 2013 at 9:35 AM, wwsmith <wwsmith@anonymised.com> wrote:

Using GeoServer 2.1.4 I'm looking for the possibility to use (system) time
functions in SLDs.

Concrete: we have layer stores with data sets containing a text time stamp
like '2010-03-01' or '2012/04/01'. Now the SLD should display all data which
are older than 2 years - looking at the actual date ... - in an other color
than the default color.

Are there any suggestions?

There are no functions for date manipulation out of the box.
However, it's not hard to implement them if you can develop in Java,
the function subsystem is pluggable, new functions can be added
in GeoServer by dropping in a custom jar in the right format.

GeoTools has a tutorial on its plugin system that uses functions as
an example... the example is quite a bit more complex than necessary,
you actually just need to create the function and you can register it
directly without having to also create a factory for it:
http://docs.geotools.org/latest/userguide/tutorial/factory.html

It's really just:
1) create the function, e.g.
https://github.com/geotools/geotools/blob/master/modules/library/main/src/main/java/org/geotools/filter/function/string/ConcatenateFunction.java
2) register the function in SPI, eg.:
https://github.com/geotools/geotools/blob/master/modules/library/main/src/main/resources/META-INF/services/org.opengis.filter.expression.Function#L168

You just create a jar with those two files, drop it in GeoServer, and you
get the extra function available to SLD, WFS and so on

Cheers
Andrea

--

Our support, Your Success! Visit http://opensdi.geo-solutions.it for
more information.

Ing. Andrea Aime
@geowolf
Technical Lead

GeoSolutions S.A.S.
Via Poggio alle Viti 1187
55054 Massarosa (LU)
Italy
phone: +39 0584 962313
fax: +39 0584 1660272
mob: +39 339 8844549

http://www.geo-solutions.it
http://twitter.com/geosolutions_it

-------------------------------------------------------

Hi Andrea,

I know it has been a very long time since this question came up and you
answered it, but I have a question about this topic.

I want to set a CQL filter in GeoServer which compares a date-attribute i.e.
DATE_COL to /now/, with /now/ being a Java function. Very much like this:
DATE_COL > getDateNow()

In your answer to the OP you wrote that it's quite simple:

geowolf wrote

It's really just:
1) create the function, e.g.
https://github.com/geotools/geotools/blob/master/modules/library/main/src/main/java/org/geotools/filter/function/string/ConcatenateFunction.java
2) register the function in SPI, eg.:
https://github.com/geotools/geotools/blob/master/modules/library/main/src/main/resources/META-INF/services/org.opengis.filter.expression.Function#L168

You just create a jar with those two files, drop it in GeoServer, and you
get the extra function available to SLD, WFS and so on

I have two questions about this:
1. What do you mean with registering the function in SPI?
2. Which two files do you need to create a jar?

--
Sent from: http://osgeo-org.1560.x6.nabble.com/GeoServer-User-f3786390.html

Hi,

To answer #1, SPI is the Java 'Service Provider Interface'. It is one option on the JVM to provide concrete implementations to interfaces at runtime[1]. To create the jar, you'd need to compile your class and make sure to include the file in META-INF/services that Andrea mentioned. Build tools like Maven can help with compiling, etc.

As a note, we wrote a similar function in GeoMesa[2]. On a good day, you could add the jar I linked to a GeoServer 2.15.x (newer *may* work, but things could go wrong) and the function currentDate may work.

I've used it for layers with live data to run queries like "DATE_COL > currentDate('-PT5m')" to show only the records which have updated in the last 5 minutes. As the GeoMesa documentation notes, the syntax for the duration is here[3].

Cheers,

Jim

1. SPI Background: https://www.baeldung.com/java-spi

https://www.journaldev.com/31602/java-spi-service-provider-interface-and-serviceloader

2. Scala code: https://github.com/locationtech/geomesa/blob/master/geomesa-filter/src/main/scala/org/locationtech/geomesa/filter/function/CurrentDateFunction.scala

Meta-inf line to wire it up: https://github.com/locationtech/geomesa/blob/master/geomesa-filter/src/main/resources/META-INF/services/org.opengis.filter.expression.Function#L2

Docs: https://www.geomesa.org/documentation/user/datastores/filter_functions.html#currentdate

Jar: https://repo1.maven.org/maven2/org/locationtech/geomesa/geomesa-filter_2.11/2.4.0/geomesa-filter_2.11-2.4.0.jar

3. https://docs.oracle.com/javase/8/docs/api/java/time/Duration.html#parse-java.lang.CharSequence-

On 1/9/20 10:34 AM, steefdam via Geoserver-users wrote:

Hi Andrea,

I know it has been a very long time since this question came up and you
answered it, but I have a question about this topic.

I want to set a CQL filter in GeoServer which compares a date-attribute i.e.
DATE_COL to /now/, with /now/ being a Java function. Very much like this:
DATE_COL > getDateNow()

In your answer to the OP you wrote that it's quite simple:

geowolf wrote

It's really just:
1) create the function, e.g.
https://github.com/geotools/geotools/blob/master/modules/library/main/src/main/java/org/geotools/filter/function/string/ConcatenateFunction.java
2) register the function in SPI, eg.:
https://github.com/geotools/geotools/blob/master/modules/library/main/src/main/resources/META-INF/services/org.opengis.filter.expression.Function#L168

You just create a jar with those two files, drop it in GeoServer, and you
get the extra function available to SLD, WFS and so on

I have two questions about this:
1. What do you mean with registering the function in SPI?
2. Which two files do you need to create a jar?

--
Sent from: http://osgeo-org.1560.x6.nabble.com/GeoServer-User-f3786390.html

_______________________________________________
Geoserver-users mailing list

Please make sure you read the following two resources before posting to this list:
- Earning your support instead of buying it, but Ian Turton: http://www.ianturton.com/talks/foss4g.html#/
- The GeoServer user list posting guidelines: http://geoserver.org/comm/userlist-guidelines.html

If you want to request a feature or an improvement, also see this: https://github.com/geoserver/geoserver/wiki/Successfully-requesting-and-integrating-new-features-and-improvements-in-GeoServer

Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

There is also a tutorial on writing a function in the geotools library documentation:

https://docs.geotools.org/latest/userguide/tutorial/function.html

It also tries to explain about META-INF/services

ยทยทยท

Jody Garnett