[Geoserver-devel] [jira] Created: (GEOS-1962) Linestring data type containing 1 point causes errors

Linestring data type containing 1 point causes errors
-----------------------------------------------------

                 Key: GEOS-1962
                 URL: http://jira.codehaus.org/browse/GEOS-1962
             Project: GeoServer
          Issue Type: Bug
          Components: PostGIS
    Affects Versions: 1.6.0-RC1
            Reporter: Tyler Erickson
            Assignee: Andrea Aime

I have a PostGIS view that constructs lines from a series of points using the ST_makeline function. If the series of points happens to be a single point, GeoServer throws errors when the featuretype is requsted.

-------------- Example View that constructs a Linestring from a series of point geometries ---------
CREATE OR REPLACE VIEW v_vehicle_lines AS
SELECT obs.vehicleid, obs.obs_date, count(obs.vehicleid) AS obs_count, min(obs.datestamp) AS min_time, max(obs.datestamp) AS max_time, (max(obs.datestamp) - min(obs.datestamp))::time without time zone AS elapsed_time, st_makeline(obs.geom) AS route_geom
   FROM ( SELECT v_truck_obs.vehicleid, v_truck_obs.datestamp, date_trunc('day'::text, v_truck_obs.datestamp) AS obs_date, v_truck_obs.geom
           FROM v_truck_obs
          ORDER BY v_truck_obs.datestamp) obs
  GROUP BY obs.vehicleid, obs.obs_date
  ORDER BY obs.vehicleid, obs.obs_date;

----- ERRORS thrown ----------

02 Jun 15:17:07 WARN [org.geoserver.ows] -
java.io.IOException
  at org.vfny.geoserver.wms.responses.map.kml.KMZMapProducer.writeTo(KMZMapProducer.java:133)
  at org.vfny.geoserver.wms.responses.GetMapResponse.writeTo(GetMapResponse.java:561)
  at org.geoserver.ows.adapters.ResponseAdapter.write(ResponseAdapter.java:60)
  at org.geoserver.ows.Dispatcher.response(Dispatcher.java:608)
  at org.geoserver.ows.Dispatcher.handleRequestInternal(Dispatcher.java:192)
  at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:139)
  at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:44)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:684)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:625)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:392)
  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:347)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:459)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1054)
  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.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1045)
  at org.vfny.geoserver.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:108)
  at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1045)
  at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:358)
  at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:231)
  at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:629)
  at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:453)
  at org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:149)
  at org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:123)
  at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:141)
  at org.mortbay.jetty.Server.handle(Server.java:303)
  at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:452)
  at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:721)
  at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:509)
  at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:209)
  at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:349)
  at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:320)
  at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)
Caused by: javax.xml.transform.TransformerException: Translator error
  at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:132)
  at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:107)
  at org.vfny.geoserver.wms.responses.map.kml.KMZMapProducer.writeTo(KMZMapProducer.java:130)
  ... 46 more
Caused by: java.util.NoSuchElementException: Could not obtain the next feature:org.geotools.data.DataSourceException: An exception occurred while parsing WKB data
  at org.geotools.data.store.FeatureReaderIterator.next(FeatureReaderIterator.java:67)
  at org.geotools.feature.collection.DelegateFeatureIterator.next(DelegateFeatureIterator.java:54)
  at org.geotools.data.crs.ForceCoordinateSystemIterator.next(ForceCoordinateSystemIterator.java:120)
  at org.geotools.feature.collection.DelegateFeatureIterator.next(DelegateFeatureIterator.java:54)
  at org.vfny.geoserver.wms.responses.map.kml.KMLVectorTransformer$KMLTranslator.encode(KMLVectorTransformer.java:266)
  at org.vfny.geoserver.wms.responses.map.kml.KMLVectorTransformer$KMLTranslator.encode(KMLVectorTransformer.java:241)
  at org.vfny.geoserver.wms.responses.map.kml.KMLTransformer$KMLTranslator.encodeVectorLayer(KMLTransformer.java:190)
  at org.vfny.geoserver.wms.responses.map.kml.KMLTransformer$KMLTranslator.encode(KMLTransformer.java:126)
  at org.geotools.xml.transform.TransformerBase$XMLReaderSupport.parse(TransformerBase.java:702)
  at org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:484)
  at org.geotools.xml.transform.TransformerBase$Task.run(TransformerBase.java:295)
  at org.geotools.xml.transform.TransformerBase.transform(TransformerBase.java:128)
  ... 48 more
Caused by: org.geotools.data.DataSourceException: An exception occurred while parsing WKB data
  at org.geotools.data.postgis.attributeio.PgWKBAttributeIO.WKB2Geometry(PgWKBAttributeIO.java:113)
  at org.geotools.data.postgis.attributeio.PgWKBAttributeIO.read(PgWKBAttributeIO.java:184)
  at org.geotools.data.jdbc.QueryData.read(QueryData.java:212)
  at org.geotools.data.jdbc.JDBCFeatureReader.readFeature(JDBCFeatureReader.java:107)
  at org.geotools.data.jdbc.JDBCFeatureReader.next(JDBCFeatureReader.java:88)
  at org.geotools.data.store.FeatureReaderIterator.next(FeatureReaderIterator.java:64)
  ... 59 more
Caused by: java.lang.IllegalArgumentException: point array must contain 0 or >1 elements
  at com.vividsolutions.jts.geom.LineString.init(LineString.java:83)
  at com.vividsolutions.jts.geom.LineString.<init>(LineString.java:74)
  at com.vividsolutions.jts.geom.GeometryFactory.createLineString(GeometryFactory.java:470)
  at com.vividsolutions.jts.io.WKBReader.readLineString(WKBReader.java:210)
  at com.vividsolutions.jts.io.WKBReader.readGeometry(WKBReader.java:171)
  at com.vividsolutions.jts.io.WKBReader.read(WKBReader.java:137)
  at com.vividsolutions.jts.io.WKBReader.read(WKBReader.java:118)
  at org.geotools.data.postgis.attributeio.PgWKBAttributeIO.WKB2Geometry(PgWKBAttributeIO.java:111)
  ... 64 more

--------------Work around--------------------
The errors can be avoided by creating a view that only returns Linestring geometries where the number of points is greater than 1, and basing then create the GeoServer featuretype using this view.

CREATE OR REPLACE VIEW geoserver.v_vehicle_trip AS
SELECT vehicleid, roi_id, vehicle_trip_no, num_obs, datestamp_start,
       datestamp_end, geom
  FROM v_vehicle_trip
WHERE ST_NumPoints("geom")>1;

--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira