[Geoserver-devel] ShapeFileException

Hi,

I use the following versions:

geoserver = 1.3.1
datastore = postgis 1.1.1

I've been writing some code that allows Geoserver's WFS to output additional formats by making a call to the GDAL/OGR utility 'ogr2ogr'. Since Geoserver already generates shape files I extract the data in this format and then run the ogr2ogr tool to get the format specified by the WFS outputFormat request parameter. This is done by creating an org.vfny.geoserver.wfs.responses.OGRFeatureResponseDelegate which contains the basic behaviour for OGR conversion and creating concrete classes to provide specific parameters for the ogr2ogr tool.

One of the tables I'm trying to extract features from is causing a problem:

org.geotools.data.shapefile.shp.ShapefileException: Cannot handle geometry class : com.vividsolutions.jts.geom.Geometry
        at org.geotools.data.shapefile.shp.JTSUtilities.getShapeType(JTSUtilities.java:363)
        at org.geotools.data.shapefile.ShapefileDataStore$Writer.flush(ShapefileDataStore.java:1335)
        at org.geotools.data.shapefile.ShapefileDataStore$Writer.close(ShapefileDataStore.java:1425)
        at org.geotools.data.InProcessLockingManager$1.close(InProcessLockingManager.java:344)
        at org.geotools.data.AbstractFeatureStore.addFeatures(AbstractFeatureStore.java:232)
        at org.vfny.geoserver.wfs.responses.ShapeFeatureResponseDelegate.writeOut(ShapeFeatureResponseDelegate.java:294)
        at org.vfny.geoserver.wfs.responses.ShapeFeatureResponseDelegate.encode(ShapeFeatureResponseDelegate.java:208)
        at org.vfny.geoserver.wfs.responses.OGRFeatureResponseDelegate.getShapeZip(OGRFeatureResponseDelegate.java:276)
        at org.vfny.geoserver.wfs.responses.OGRFeatureResponseDelegate.encode(OGRFeatureResponseDelegate.java:153)
        at org.vfny.geoserver.wfs.responses.FeatureResponse.writeTo(FeatureResponse.java:132)
        at org.vfny.geoserver.servlets.AbstractService.doService(AbstractService.java:520)
        at org.vfny.geoserver.servlets.AbstractService.doGet(AbstractService.java:279)
        at org.vfny.geoserver.wfs.servlets.WfsDispatcher.doResponse(WfsDispatcher.java:290)
        at org.vfny.geoserver.wfs.servlets.WfsDispatcher.doGet(WfsDispatcher.java:219)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.vfny.geoserver.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:111)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)

Does anyone know why this might be happening?

I'm happy to provide the code if anyone wants to use it or needs to see it to help with the problem.

Thanks,

Duncan Clarkson

Duncan Clarkson wrote:

Hi,

I use the following versions:

geoserver = 1.3.1
datastore = postgis 1.1.1

I've been writing some code that allows Geoserver's WFS to output additional formats by making a call to the GDAL/OGR utility 'ogr2ogr'.

Very cool. Would be great to have that as a community plug-in.

Since Geoserver already generates shape files I extract the data in this format and then run the ogr2ogr tool to get the format specified by the WFS outputFormat request parameter. This is done by creating an org.vfny.geoserver.wfs.responses.OGRFeatureResponseDelegate which contains the basic behaviour for OGR conversion and creating concrete classes to provide specific parameters for the ogr2ogr tool.

One of the tables I'm trying to extract features from is causing a problem:

org.geotools.data.shapefile.shp.ShapefileException: Cannot handle geometry class : com.vividsolutions.jts.geom.Geometry
        at org.geotools.data.shapefile.shp.JTSUtilities.getShapeType(JTSUtilities.java:363)
        at org.geotools.data.shapefile.ShapefileDataStore$Writer.flush(ShapefileDataStore.java:1335)
        at org.geotools.data.shapefile.ShapefileDataStore$Writer.close(ShapefileDataStore.java:1425)
        at org.geotools.data.InProcessLockingManager$1.close(InProcessLockingManager.java:344)
        at org.geotools.data.AbstractFeatureStore.addFeatures(AbstractFeatureStore.java:232)
        at org.vfny.geoserver.wfs.responses.ShapeFeatureResponseDelegate.writeOut(ShapeFeatureResponseDelegate.java:294)
        at org.vfny.geoserver.wfs.responses.ShapeFeatureResponseDelegate.encode(ShapeFeatureResponseDelegate.java:208)
        at org.vfny.geoserver.wfs.responses.OGRFeatureResponseDelegate.getShapeZip(OGRFeatureResponseDelegate.java:276)
        at org.vfny.geoserver.wfs.responses.OGRFeatureResponseDelegate.encode(OGRFeatureResponseDelegate.java:153)
        at org.vfny.geoserver.wfs.responses.FeatureResponse.writeTo(FeatureResponse.java:132)
        at org.vfny.geoserver.servlets.AbstractService.doService(AbstractService.java:520)
        at org.vfny.geoserver.servlets.AbstractService.doGet(AbstractService.java:279)
        at org.vfny.geoserver.wfs.servlets.WfsDispatcher.doResponse(WfsDispatcher.java:290)
        at org.vfny.geoserver.wfs.servlets.WfsDispatcher.doGet(WfsDispatcher.java:219)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.vfny.geoserver.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:111)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
        at java.lang.Thread.run(Thread.java:595)

Does anyone know why this might be happening?

Any chance this is an oracle datastore? Or some datastore other than shapefile, postgis, mysql? The problem is that the featureType of the feature being written isn't specific enough with what type of Geometry it is. It's a problem with Oracle, as they don't follow simple features for sql internally, and by default their geometry fields can contain most anything. This is bad when translating to something like shapefile, since (I believe) there can only be one type of geometry in each field. The code there is trying to write the headers, and its not coming up with the best way to do so.

This is kind of a long standing problem that has never had a great answer. The real answer is to be found in the FM branch, where we can control the output, and basically 'cast' it to a specific geometry based on user prefs. But as of now I don't think we have a good way for a user to specify that in fact X geometry column in oracle is actually made fully of LineStrings.

There may be a way to hack something directly in your code, since you're already sort of doing translation, to attempt to do like a cast by wrapping it in a ReTypeFeatureReader, though I'm not sure if it would work right. To try this you'd basically take the reader from the FeatureResults, get the FeatureType, make a new FeatureType from it with the geometry the same as the first feature found, and wrap it in a ReTypeFeatureReader (in org.geotools.data) with the new FeatureType. If this doesn't make sense and you want to try it out let me know and I can explain in more depth. But looking at the code it has a decent chance of working right. The one error you'd get if the table actually had different geometries in it, but in that case there's not much you can really do.

If it's with postgis or shapefile then I'm surprised it's happening, and I'll have to think about it/look in to it more.

C

I'm happy to provide the code if anyone wants to use it or needs to see it to help with the problem.

Thanks,

Duncan Clarkson

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Geoserver-devel mailing list
Geoserver-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geoserver-devel

!DSPAM:1003,44aa4ef3210369771116852!

--
Chris Holmes
The Open Planning Project
http://topp.openplans.org

Chris Holmes wrote:

Duncan Clarkson wrote:

Hi,

I use the following versions:

geoserver = 1.3.1
datastore = postgis 1.1.1

I've been writing some code that allows Geoserver's WFS to output additional formats by making a call to the GDAL/OGR utility 'ogr2ogr'.

Very cool. Would be great to have that as a community plug-in.

No problem. I'll send the code to the list when I'm done.

Since Geoserver already generates shape files I extract the data in this format and then run the ogr2ogr tool to get the format specified by the WFS outputFormat request parameter. This is done by creating an org.vfny.geoserver.wfs.responses.OGRFeatureResponseDelegate which contains the basic behaviour for OGR conversion and creating concrete classes to provide specific parameters for the ogr2ogr tool.

One of the tables I'm trying to extract features from is causing a problem:

org.geotools.data.shapefile.shp.ShapefileException: Cannot handle geometry class : com.vividsolutions.jts.geom.Geometry
        at org.geotools.data.shapefile.shp.JTSUtilities.getShapeType(JTSUtilities.java:363)

        at org.geotools.data.shapefile.ShapefileDataStore$Writer.flush(ShapefileDataStore.java:1335)

        at org.geotools.data.shapefile.ShapefileDataStore$Writer.close(ShapefileDataStore.java:1425)

        at org.geotools.data.InProcessLockingManager$1.close(InProcessLockingManager.java:344)

        at org.geotools.data.AbstractFeatureStore.addFeatures(AbstractFeatureStore.java:232)

        at org.vfny.geoserver.wfs.responses.ShapeFeatureResponseDelegate.writeOut(ShapeFeatureResponseDelegate.java:294)

        at org.vfny.geoserver.wfs.responses.ShapeFeatureResponseDelegate.encode(ShapeFeatureResponseDelegate.java:208)

        at org.vfny.geoserver.wfs.responses.OGRFeatureResponseDelegate.getShapeZip(OGRFeatureResponseDelegate.java:276)

        at org.vfny.geoserver.wfs.responses.OGRFeatureResponseDelegate.encode(OGRFeatureResponseDelegate.java:153)

        at org.vfny.geoserver.wfs.responses.FeatureResponse.writeTo(FeatureResponse.java:132)

        at org.vfny.geoserver.servlets.AbstractService.doService(AbstractService.java:520)

        at org.vfny.geoserver.servlets.AbstractService.doGet(AbstractService.java:279)

        at org.vfny.geoserver.wfs.servlets.WfsDispatcher.doResponse(WfsDispatcher.java:290)

        at org.vfny.geoserver.wfs.servlets.WfsDispatcher.doGet(WfsDispatcher.java:219)

        at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)

        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

        at org.vfny.geoserver.filters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:111)

        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)

        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)

        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)

        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)

        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)

        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)

        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)

        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)

        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)

        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)

        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)

        at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)

        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)

        at java.lang.Thread.run(Thread.java:595)

Does anyone know why this might be happening?

Any chance this is an oracle datastore? Or some datastore other than shapefile, postgis, mysql? The problem is that the featureType of the feature being written isn't specific enough with what type of Geometry it is. It's a problem with Oracle, as they don't follow simple features for sql internally, and by default their geometry fields can contain most anything. This is bad when translating to something like shapefile, since (I believe) there can only be one type of geometry in each field. The code there is trying to write the headers, and its not coming up with the best way to do so.

The datastore is definitely postgis 1.1.1 but I've found out what the problem is. I feel slightly foolish as the bounding box I was requesting actually had no features of the specific type I asked for! So what you get back is the "Cannot handle geometry class : com.vividsolutions.jts.geom.Geometry" exception. An exception is what you'd expect I guess but is this one specific enough? I didn't know there were no features there until I ran a PostGIS query for the bbox. The same request for GML returns:

<gml:boundedBy>
  <gml:null>unknown</gml:null>
</gml:boundedBy>

Easier to interpret IMO.

Duncan