[Geoserver-users] Ordering a GetFeature Info request

Hi Everyone,
Is it possible to order the result of a GetFeatureInfo request using
the content.ftl ? I tried this using the Freemarker sort_by directive,
but was greeted with this..

   "java.io.IOException: Error occured processing template. Error
occured processing template. Underlying collection is not a list, it's
org.geotools.data.jdbc.JDBCFeatureCollection
Map data"

So, it would seem that the Freemarker sequence directives cannot be
used. My trivial template looks something like this..

<#list features?sort_by("lvlid") as feature>
<ul>
        <li>ISO Code:${feature.iso_ctry.value}</li>
        <li>Level: ${feature.lvl.value}</li>
        <li> LVLID: ${feature.lvlid.value}</li>
        <li>Name:${feature.name.value}</li>

</ul>
</#list>

Any ideas how to get this to work or if it is even possible?

Best regards,
Jason

Jason Pickering ha scritto:

Hi Everyone,
Is it possible to order the result of a GetFeatureInfo request using
the content.ftl ? I tried this using the Freemarker sort_by directive,
but was greeted with this..

   "java.io.IOException: Error occured processing template. Error
occured processing template. Underlying collection is not a list, it's
org.geotools.data.jdbc.JDBCFeatureCollection
Map data"

So, it would seem that the Freemarker sequence directives cannot be
used. My trivial template looks something like this..

<#list features?sort_by("lvlid") as feature>
<ul>
        <li>ISO Code:${feature.iso_ctry.value}</li>
        <li>Level: ${feature.lvl.value}</li>
        <li> LVLID: ${feature.lvlid.value}</li>
        <li>Name:${feature.name.value}</li>

</ul>
</#list>

Any ideas how to get this to work or if it is even possible?

That would require a code change, and would work only against postgis,
the only datastore that is guaranteed to support sorting at the moment.
We would also have to roll out a new vendor parameter in the request,
that is, you'd have to specify sorting in the GetFeatureInfo request,
adding sorting at the template level might be more complex.

Justin, any suggestion?

Cheers
Andrea

That would require a code change, and would work only against postgis,
the only datastore that is guaranteed to support sorting at the moment.
We would also have to roll out a new vendor parameter in the request,
that is, you'd have to specify sorting in the GetFeatureInfo request,
adding sorting at the template level might be more complex.

Justin, any suggestion?

Given that GetFeatureInfo request usually do not return a ton of features we could perhaps suck all the features into a memory based collection, and run it through the template, then sorting with freemarker would be possible.

The trouble is there would have to be some magic number to cap the number of features to prevent loading too much into memory... which would mean that this sorting functionality could not be guaranteed.

Cheers
Andrea

!DSPAM:4007,4816d2c3187327082231907!

--
Justin Deoliveira
The Open Planning Project
jdeolive@anonymised.com

Hi Justin and Andrea,

Well, it is easy to cap the number of features that are returned from
the GetFeatureInfo request. Perhaps it could be implemented, with the
caveat that not too many features could be sorted, which I guess would
depend heavily on the information contained in the response.

The other strategy that I had considered was just pulling the
information back as text/xml and then using the JavaScript DOM parser
to do my sorting for me, which would obviously require some work on a
client.

What do you think would be preferential? Seems that the ability to
sort server side would be better, but maybe there are potential memory
issues?

Best regards,
Jason

On Tue, Apr 29, 2008 at 3:55 PM, Justin Deoliveira
<jdeolive@anonymised.com> wrote:

>
> That would require a code change, and would work only against postgis,
> the only datastore that is guaranteed to support sorting at the moment.
> We would also have to roll out a new vendor parameter in the request,
> that is, you'd have to specify sorting in the GetFeatureInfo request,
> adding sorting at the template level might be more complex.
>
> Justin, any suggestion?
>

Given that GetFeatureInfo request usually do not return a ton of features
we could perhaps suck all the features into a memory based collection, and
run it through the template, then sorting with freemarker would be possible.

The trouble is there would have to be some magic number to cap the number
of features to prevent loading too much into memory... which would mean that
this sorting functionality could not be guaranteed.

>
> Cheers
> Andrea
>
> !DSPAM:4007,4816d2c3187327082231907!
>
>

--
Justin Deoliveira
The Open Planning Project
jdeolive@anonymised.com

Jason Pickering ha scritto:

Hi Justin and Andrea,

Well, it is easy to cap the number of features that are returned from
the GetFeatureInfo request. Perhaps it could be implemented, with the
caveat that not too many features could be sorted, which I guess would
depend heavily on the information contained in the response.

GetFeatureInfo has a parameter, FEATURE_COUNT, that limits the number
of returned features. By default it's 1, in our preview we expand
it to 50 just to grab some more features. So the user is in control here, and it's pretty safe to assume nobody is going to ask for one
million of them.
So sorting in memory would actually work.
I'm just wondering how:
* turning the feature collection into a plain java collection and
   have freemarker do its own sorting
* add a vendor parameter that states the params you want to use
   for sorting

The latter would allow other output formats to be game for sorting as well. Preferences?

Cheers
Andrea

Not sure about which way would be best. Seems that they would both be
useful ,but you knew I would say that. :slight_smile:

As for Freemarker, there are a range of possibly useful functions
described here...
http://freemarker.sourceforge.net/docs/ref_builtins_sequence.html
There also seem to be some rather serious caveats as well. "This will
work only if all subvariables are strings, or if all subvariables are
numbers, or, since FreeMarker 2.3.1, if all subvariables are date
values (date, time, or date+time). If the subvariables are strings, it
uses locale (language) specific lexical sorting (which is usually not
case sensitive)." Seems pretty limiting if I read that text correctly.
The sort_by directive seems to offer better possibilities.

I think that adding a vendor option would allow possibly more data
types but would it really be used that often? Would you ever want to
sort by geometry for instance? does not seem so, but who knows but
perhaps. It feels like it would require more work however, since
Freemarker has already done this, at least for strings and some other
types. A vendor option would also not require people using Geoserver
to mess around with Freemarker templates if they are not so inclined.

For my requirements, I just need to sort by a text field or integer field.

Best regards,
Jason

On Tue, Apr 29, 2008 at 7:47 PM, Andrea Aime <aaime@anonymised.com> wrote:

Jason Pickering ha scritto:

> Hi Justin and Andrea,
>
> Well, it is easy to cap the number of features that are returned from
> the GetFeatureInfo request. Perhaps it could be implemented, with the
> caveat that not too many features could be sorted, which I guess would
> depend heavily on the information contained in the response.
>

GetFeatureInfo has a parameter, FEATURE_COUNT, that limits the number
of returned features. By default it's 1, in our preview we expand
it to 50 just to grab some more features. So the user is in control here,
and it's pretty safe to assume nobody is going to ask for one
million of them.
So sorting in memory would actually work.
I'm just wondering how:
* turning the feature collection into a plain java collection and
  have freemarker do its own sorting
* add a vendor parameter that states the params you want to use
  for sorting

The latter would allow other output formats to be game for sorting as well.
Preferences?

Cheers
Andrea