Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Is there anyway to specify which coordinate system to use with a filter?

using the following filter:

new OpenLayers.Filter.Spatial({
    property: "boundsText",
    type: OpenLayers.Filter.Spatial.INTERSECTS,
    value: geom
})

Produces this HTTP POST to my GeoServer:

<ogc:intersects>
<ogc:propertyname>bounds</ogc:propertyname>
<gml:polygon xmlns:gml="http://www.opengis.net/gml" srsName="EPSG:4326">
    <gml:outerboundaryis>
        <gml:linearring>
            <gml:coordinates decimal="." cs="," ts=" ">-7670608.6611,2132898.8368875 -6261721.356,254382.4300875 -6653078.94075,6633511.0615125 -12758257.26285,6790054.0954125 -7670608.6611,2132898.8368875</gml:coordinates>
        </gml:linearring>
    </gml:outerboundaryis>
</gml:polygon>
</ogc:intersects>

and i get the following response error from GeoServer:

-7670608.6611 outside of (-180.0,180.0)

How can i change whatever coordinate system is being sent in my filter to decimal degrees?

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

I was able to do it by using the transform() operation on the geometry like so:

var geographic = new OpenLayers.Projection("EPSG:4326");
var mercator = new OpenLayers.Projection("EPSG:900913");

new OpenLayers.Filter.Spatial({
    property: "boundsText",
    type: OpenLayers.Filter.Spatial.INTERSECTS,
    value: geom.transform(mercator, geographic)
})

Key line being:

value: geom.transform(mercator, geographic)

You might actually want to add the clone() (depending on your situation) so it won't actually transform your existing geometry:

value: geom.clone().transform(mercator, geographic)
share|improve this answer
add comment

You can specify coordinate system to use with a filter using "projection" option.

new OpenLayers.Filter.Spatial({
    property: "boundsText",
    type: OpenLayers.Filter.Spatial.INTERSECTS,
    value: geom,
    projection:"EPSG:900913"
})

See: http://openlayers.org/dev/examples/filter.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.