[Geoserver-users] A simple "zoom to feature" method?

Hi,

I’m trying to create a list of WMS query urls that zoom to specific poligons on the map. I need to calculate the bbox for every poligon, does anyone know of a simple way of doing this?

please help!

Dario Pacheco ha scritto:

Hi,

I'm trying to create a list of WMS query urls that zoom to specific poligons on the map. I need to calculate the bbox for every poligon, does anyone know of a simple way of doing this?

The only way that comes to mind is the following:
- go to config/wfs/contents and enable "generate feature
   bounds"
- execute a wfs query such as:
http://192.168.1.200:9090/geoserver/wfs?request=GetFeature&version=1.0.0&typeName=topp:states&propertyName=STATE_NAME

And you should get the following as an answer:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection xmlns="http://www.opengis.net/wfs&quot; xmlns:wfs="http://www.opengis.net/wfs&quot;
   xmlns:topp="http://www.openplans.org/topp&quot; xmlns:gml="http://www.opengis.net/gml&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation="http://www.openplans.org/topp http://192.168.1.200:9090/geoserver/wfs?service=WFS&amp;version=1.0.0&amp;request=DescribeFeatureType&amp;typeName=topp:states http://www.opengis.net/wfs http://192.168.1.200:9090/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd&quot;&gt;
   <gml:boundedBy>
     <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
       <gml:coordinates xmlns:gml="http://www.opengis.net/gml&quot; decimal="." cs="," ts=" ">-124.731422,24.955967
         -66.969849,49.371735</gml:coordinates>
     </gml:Box>
   </gml:boundedBy>
   <gml:featureMember>
     <topp:states fid="states.1">
       <gml:boundedBy>
         <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates xmlns:gml="http://www.opengis.net/gml&quot; decimal="." cs="," ts=" ">-91.516129,36.986771
             -87.507889,42.509361</gml:coordinates>
         </gml:Box>
       </gml:boundedBy>
       <topp:STATE_NAME>Illinois</topp:STATE_NAME>
     </topp:states>
   </gml:featureMember>
   ...

So you have the name of the state, and its bounds. You just have
to parse the GML, if you're using OpenLayers it already has classes
to do so, otherwise I guess it's just a matter of loading it
into a DOM and extracting the bits of interest.

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

Hi Andrea,

I just ran into an error using this featureBounds setting in services.xml
Everything goes well with the getFeature request but an error occurs when using the propertyName filter with the request.
I think it has something to do with not overriding the getBounds method on a AbstractFeatureCollection subclass but was not able to find the specific case yet

The following error occurs:

org.geoserver.platform.ServiceException: error:Translator error
  at org.geoserver.wfs.xml.GML2OutputFormat.encode(GML2OutputFormat.java:255)
  at org.geoserver.wfs.xml.GML2OutputFormat.write(GML2OutputFormat.java:264)
  at org.geoserver.wfs.WFSGetFeatureOutputFormat.write(WFSGetFeatureOutputFormat.java:137)
  at org.geoserver.ows.Dispatcher.response(Dispatcher.java:711)
  at org.geoserver.ows.Dispatcher.handleRequestInternal(Dispatcher.java:215)
  at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
  at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.vfny.geoserver.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:264)
  at org.acegisecurity.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:107)
  at org.acegisecurity.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:72)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
  at org.acegisecurity.ui.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:110)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
  at org.acegisecurity.providers.anonymous.AnonymousProcessingFilter.doFilter(AnonymousProcessingFilter.java:125)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
  at org.acegisecurity.ui.basicauth.BasicProcessingFilter.doFilter(BasicProcessingFilter.java:178)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
  at org.acegisecurity.context.HttpSessionContextIntegrationFilter.doFilter(HttpSessionContextIntegrationFilter.java:229)
  at org.acegisecurity.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:274)
  at org.acegisecurity.util.FilterChainProxy.doFilter(FilterChainProxy.java:148)
  at org.acegisecurity.util.FilterToBeanProxy.doFilter(FilterToBeanProxy.java:98)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.geoserver.filters.LoggingFilter.doFilter(LoggingFilter.java:73)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.geoserver.filters.ReverseProxyFilter.doFilter(ReverseProxyFilter.java:163)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.geoserver.filters.GZIPFilter.doFilter(GZIPFilter.java:41)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
  at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:857)
  at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:565)
  at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1509)
  at java.lang.Thread.run(Thread.java:619)
Caused by: javax.xml.transform.TransformerException: Translator error
  at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:133)
  at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:108)
  at org.geoserver.wfs.xml.GML2OutputFormat.encode(GML2OutputFormat.java:245)
  ... 52 more
Caused by: java.lang.UnsupportedOperationException: subclasses should override
  at org.geotools.feature.collection.AbstractFeatureCollection.getBounds(AbstractFeatureCollection.java:560)
  at org.geotools.gml.producer.FeatureTransformer$FeatureTranslator.encode(FeatureTransformer.java:490)
  at org.geotools.xml.transform.TransformerBase$XMLReaderSupport.parse(TransformerBase.java:714)
  at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
  at org.geotools.xml.transform.TransformerBase$Task.run(TransformerBase.java:296)
  at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:129)
  ... 54 more

And thos os the wfs result:

<ServiceExceptionReport version="1.2.0" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd&quot;&gt;

<ServiceException>

       error:Translator error
Translator error
subclasses should override
</ServiceException>
</ServiceExceptionReport>

Hope you can help me out a little

Cheers Kris

-----Original Message-----
From: Andrea Aime [mailto:aaime@…1671…]
Sent: Monday, February 02, 2009 9:31 AM
To: Dario Pacheco
Cc: geoserver-users@lists.sourceforge.net
Subject: Re: [Geoserver-users] A simple "zoom to feature" method?

Dario Pacheco ha scritto:

Hi,

I'm trying to create a list of WMS query urls that zoom to specific
poligons on the map. I need to calculate the bbox for every poligon,
does anyone know of a simple way of doing this?

The only way that comes to mind is the following:
- go to config/wfs/contents and enable "generate feature
   bounds"
- execute a wfs query such as:
http://192.168.1.200:9090/geoserver/wfs?request=GetFeature&version=1.0.0&typeName=topp:states&propertyName=STATE_NAME

And you should get the following as an answer:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection xmlns="http://www.opengis.net/wfs&quot;
xmlns:wfs="http://www.opengis.net/wfs&quot;
   xmlns:topp="http://www.openplans.org/topp&quot;
xmlns:gml="http://www.opengis.net/gml&quot;
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation="http://www.openplans.org/topp
http://192.168.1.200:9090/geoserver/wfs?service=WFS&amp;version=1.0.0&amp;request=DescribeFeatureType&amp;typeName=topp:states
http://www.opengis.net/wfs
http://192.168.1.200:9090/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd&quot;&gt;
   <gml:boundedBy>
     <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
       <gml:coordinates xmlns:gml="http://www.opengis.net/gml&quot;
decimal="." cs="," ts=" ">-124.731422,24.955967
         -66.969849,49.371735</gml:coordinates>
     </gml:Box>
   </gml:boundedBy>
   <gml:featureMember>
     <topp:states fid="states.1">
       <gml:boundedBy>
         <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326&quot;&gt;
           <gml:coordinates xmlns:gml="http://www.opengis.net/gml&quot;
decimal="." cs="," ts=" ">-91.516129,36.986771
             -87.507889,42.509361</gml:coordinates>
         </gml:Box>
       </gml:boundedBy>
       <topp:STATE_NAME>Illinois</topp:STATE_NAME>
     </topp:states>
   </gml:featureMember>
   ...

So you have the name of the state, and its bounds. You just have
to parse the GML, if you're using OpenLayers it already has classes
to do so, otherwise I guess it's just a matter of loading it
into a DOM and extracting the bits of interest.

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Geoserver-users mailing list
Geoserver-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-users

Kris Geusebroek wrote:

Hi Andrea,

I just ran into an error using this featureBounds setting in services.xml
Everything goes well with the getFeature request but an error occurs when using the propertyName filter with the request.
I think it has something to do with not overriding the getBounds method on a AbstractFeatureCollection subclass but was not able to find the specific case yet

The following error occurs:

org.geoserver.platform.ServiceException: error:Translator error
  at org.geoserver.wfs.xml.GML2OutputFormat.encode(GML2OutputFormat.java:255)
  at org.geoserver.wfs.xml.GML2OutputFormat.write(GML2OutputFormat.java:264)
Caused by: java.lang.UnsupportedOperationException: subclasses should override
  at org.geotools.feature.collection.AbstractFeatureCollection.getBounds(AbstractFeatureCollection.java:560)
  at org.geotools.gml.producer.FeatureTransformer$FeatureTranslator.encode(FeatureTransformer.java:490)
  at org.geotools.xml.transform.TransformerBase$XMLReaderSupport.parse(TransformerBase.java:714)
  at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
  at org.geotools.xml.transform.TransformerBase$Task.run(TransformerBase.java:296)
  at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:129)
  ... 54 more

And thos os the wfs result:

<ServiceExceptionReport version="1.2.0" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd&quot;&gt;

<ServiceException>

       error:Translator error
Translator error
subclasses should override
</ServiceException>
</ServiceExceptionReport>

Hope you can help me out a little

It seems you're playing with a broken datastore implementation. Is it something we're shipping with? Apparently the returned feature collection does not have the necessary code to respond to a getBounds
request.
Cheers
Andrea

Hi andrea,

It's just the 1.7.2 war without any aditions
Using tomcat 6 and postgis database

Cheers Kris

-----Original Message-----
From: Andrea Aime [mailto:aaime@…1671…]
Sent: Monday, February 02, 2009 12:35 PM
To: Kris Geusebroek
Cc: Dario Pacheco; geoserver-users@lists.sourceforge.net
Subject: Re: [Geoserver-users] A simple "zoom to feature" method?

Kris Geusebroek wrote:

Hi Andrea,

I just ran into an error using this featureBounds setting in services.xml
Everything goes well with the getFeature request but an error occurs when using the propertyName filter with the request.
I think it has something to do with not overriding the getBounds method on a AbstractFeatureCollection subclass but was not able to find the specific case yet

The following error occurs:

org.geoserver.platform.ServiceException: error:Translator error
  at org.geoserver.wfs.xml.GML2OutputFormat.encode(GML2OutputFormat.java:255)
  at org.geoserver.wfs.xml.GML2OutputFormat.write(GML2OutputFormat.java:264)
Caused by: java.lang.UnsupportedOperationException: subclasses should override
  at org.geotools.feature.collection.AbstractFeatureCollection.getBounds(AbstractFeatureCollection.java:560)
  at org.geotools.gml.producer.FeatureTransformer$FeatureTranslator.encode(FeatureTransformer.java:490)
  at org.geotools.xml.transform.TransformerBase$XMLReaderSupport.parse(TransformerBase.java:714)
  at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
  at org.geotools.xml.transform.TransformerBase$Task.run(TransformerBase.java:296)
  at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:129)
  ... 54 more

And thos os the wfs result:

<ServiceExceptionReport version="1.2.0" xsi:schemaLocation="http://www.opengis.net/ogc http://schemas.opengis.net/wfs/1.0.0/OGC-exception.xsd&quot;&gt;

<ServiceException>

       error:Translator error
Translator error
subclasses should override
</ServiceException>
</ServiceExceptionReport>

Hope you can help me out a little

It seems you're playing with a broken datastore implementation. Is it
something we're shipping with? Apparently the returned feature
collection does not have the necessary code to respond to a getBounds
request.
Cheers
Andrea

Kris Geusebroek wrote:

Hi andrea,

It's just the 1.7.2 war without any aditions
Using tomcat 6 and postgis database

Hum, you're right, I reproduced the issue, it's
tracked here:
http://jira.codehaus.org/browse/GEOS-2602

In order to work around it, you should ask
the geometry to be returned as well... which
of course will mean a much bigger gml to deal with,
but gives you a way out for the time being.

Cheers
Andrea

Andrea Aime ha scritto:

Kris Geusebroek wrote:

Hi andrea,

It's just the 1.7.2 war without any aditions
Using tomcat 6 and postgis database

Hum, you're right, I reproduced the issue, it's
tracked here:
http://jira.codehaus.org/browse/GEOS-2602

In order to work around it, you should ask
the geometry to be returned as well... which
of course will mean a much bigger gml to deal with,
but gives you a way out for the time being.

For the record, I've just fixed the above bug,
if anybody wants to try out a nightly build with
the fix, check here:
http://gridlock.openplans.org/geoserver/1.7.x/
and grab a build made Feb 5 (tomorrow) or later.

Cheers
Andrea

--
Andrea Aime
OpenGeo - http://opengeo.org
Expert service straight from the developers.