[Geoserver-users] How to set units when using CQL spatial operators?

Hi all,

I am using CQL spatial filter like BEYOND and DWITHIN and reading the docs at

http://docs.geoserver.org/stable/en/user/filter/ecql_reference.html#spatial-predicate

It seems that you may set the distance and the units according to “units is one of feet, meters, statute miles, nautical miles, kilometers

I tried with a very simple OL code snippet:

new OpenLayers.Layer.WMS(“countries”,
http://localhost/geoserver/wms”,{
layers: “NaturalEarth:countries”,
format: “image/png”,
transparent: true,
cql_filter: “DWITHIN(geom,POINT(12.48 41.89),8,kilometers)”,
sld_body: sld
},

But I get a map where 8 is clearly interpreted as decimal degrees.

And it seems the same also looking at GeoServer’s log.

2013-11-03 22:16:15,452 DEBUG [org.geotools.jdbc] - SELECT “gid”,encode(ST_AsBinary(ST_Force_2D(“geom”)),‘base64’) as “geom” FROM “public”.“countries” WHERE (ST_DWithin(“geom”,ST_GeomFromText(‘POINT (12.48 41.89)’, 4326),8.0) AND “geom” && ST_GeomFromText(‘POLYGON ((-86.748515625 -17.787734375, -86.748515625 101.567734375, 111.708515
625 101.567734375, 111.708515625 -17.787734375, -86.748515625 -17.787734375))’, 4326))
2013-11-03 22:16:15,495 DEBUG [org.geotools.jdbc] - CLOSE CONNECTION
2013-11-03 22:16:15,497 DEBUG [org.geotools.rendering] - Style cache hit ratio: 0.9583333333333334 , hits 23, requests 24
2013-11-03 22:16:15,498 INFO [org.geoserver.wms] -
Request: getMap
Time =
Filter = [[ geom dwithin POINT (12.48 41.89), distance: 8.0 ]]
Format = image/png
Buffer = 0
Filters = [[ geom dwithin POINT (12.48 41.89), distance: 8.0 ]]
Height = 675
Width = 1125
Tiled = false
Palette = null
SRS = EPSG:4326
FeatureVersion = null
Styles = [StyleImpl[ name=Default Styler, DEFAULT]]
Layers = [org.geoserver.wms.MapLayerInfo@anonymised.com]
MaxFeatures = null
Crs = GEOGCS[“WGS 84”,
DATUM[“World Geodetic System 1984”,
SPHEROID[“WGS 84”, 6378137.0, 298.257223563, AUTHORITY[“EPSG”,“7030”]],
AUTHORITY[“EPSG”,“6326”]],
PRIMEM[“Greenwich”, 0.0, AUTHORITY[“EPSG”,“8901”]],
UNIT[“degree”, 0.017453292519943295],
AXIS[“Geodetic longitude”, EAST],
AXIS[“Geodetic latitude”, NORTH],
AUTHORITY[“EPSG”,“4326”]]
Bbox = ReferencedEnvelope[-86.396953125 : 111.356953125, -17.436171875 : 101.216171875]
RemoteOwsType = null
RemoteOwsURL = null
Env = {}
FormatOptions = {}
Angle = 0.0
CQLFilter = [[ geom dwithin POINT (12.48 41.89), distance: 8.0 ]]
Elevation =
FeatureId = null
StartIndex = null
ViewParams = null
BgColor = java.awt.Color[r=255,g=255,b=255]
Transparent = true
SldBody = NaturalEarth:countries1#0000001#FFFFCC0.65
ValidateSchema = false
Sld = null
SldVersion = null
TilesOrigin = null
Exceptions = SE_XML
Version = 1.1.1
Request = GetMap
Get = true
RawKvp = {BBOX=-86.396953125,-17.436171875,111.356953125,101.216171875, SERVICE=WMS, HEIGHT=675, REQUEST=GetMap, STYLES=, WIDTH=1125, CQL_FILTER=DWITHIN(geom,POINT(12.48 41.89),8,kilometers), TRANSPARENT=TRUE, VERSION=1.1.1, FORMAT=image/png, SLD_BODY=NaturalEarth:countries1#0000001#FFFFCC0.65, LAYERS=NaturalEarth:countries, SRS=EPSG:4326}

So is it the units binded to the SRS of the map and/or the layer?

Thanks for your help

Stefano


41.95581N 12.52854E

http://www.linkedin.com/in/stefanoiacovella

http://twitter.com/#!/Iacovellas

On Sun, Nov 3, 2013 at 10:25 PM, Stefano Iacovella <
stefano.iacovella@anonymised.com> wrote:

Hi all,

I am using CQL spatial filter like BEYOND and DWITHIN and reading the docs
at

http://docs.geoserver.org/stable/en/user/filter/ecql_reference.html#spatial-predicate

...

So is it the units binded to the SRS of the map and/or the layer?

It really depends on what you have in the backend, as far as I know, Oracle
is the only data
store that honors the units, mostly because it has an operator that matches
1-1 dwithin with
direct unit support.

For postgis for example, geometry is bound to use the native units, but
geography types
is bound to meters instead.

General support for distance searches is a long wanted item (one of the
oldest tickets
in Jira, http://jira.codehaus.org/browse/GEOS-937), to implement it against
most data
sources, which have no notion of units in distance searches, the filter
should be rewritten
on the fly to an intersection against a polygon, computing the polygon
would require
choosing one or more local projections (we don't have enough ellipsoidal
math available
in code to do a buffer in geographic coordinates) and so on.

Not impossible, but it would be some work, which nobody ever stepped up for
funding so far

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

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

2013/11/4 Andrea Aime <andrea.aime@anonymised.com>

For postgis for example, geometry is bound to use the native units, but
geography types
is bound to meters instead.

General support for distance searches is a long wanted item (one of the
oldest tickets
in Jira, http://jira.codehaus.org/browse/GEOS-937), to implement it
against most data
sources, which have no notion of units in distance searches, the filter
should be rewritten
on the fly to an intersection against a polygon, computing the polygon
would require
choosing one or more local projections (we don't have enough ellipsoidal
math available
in code to do a buffer in geographic coordinates) and so on.

Not impossible, but it would be some work, which nobody ever stepped up
for funding so far

Cheers
Andrea

Thanks Andrea,

Indeed I missed that the filter is not rewritten according to SRS of Data.

Cheers,

Stefano

---------------------------------------------------
41.95581N 12.52854E

http://www.linkedin.com/in/stefanoiacovella

http://twitter.com/#!/Iacovellas