Query rows with empty geometries produce exception
--------------------------------------------------

                 Key: GEOT-2765
                 URL: http://jira.codehaus.org/browse/GEOT-2765
             Project: GeoTools
          Issue Type: Bug
          Components: data jdbc-ng
    Affects Versions: 2.5.7
            Reporter: albert valls
         Attachments: browser_error.gif, geoserver FAILS.log, OracleDialect.java


An error came up changing from geoserver 1.7.4 with the Old Oracle Datastore to 
the latest 1.7.6 with the Oracle NG Datastore.

The WFS that before was working fine, now is failing. It queries an Oracle 
table with some rows that don't have geometry:

--------------------------------------------------------
select count(1) from activitats;

  COUNT(1)               
  ---------------------- 
  1691                   
  1 rows selected

select count(1) from activitats where GEOM is null;

  COUNT(1)               
  ---------------------- 
  17                     
  1 rows selected
--------------------------------------------------------

I want to obtain the rows that don't have geometry, the WFS filter used is:

<ogc:Filter xmlns:ogc="http://www.opengis.net/ogc";>
        <ogc:PropertyIsNull>
                <ogc:PropertyName>GEOM</ogc:PropertyName>
        </ogc:PropertyIsNull>
</ogc:Filter>

And at the attachment file you can see the logs produced at geoserver.

The solution is to edit the java Class: org.geotools.data.oracle.OracleDialect 
replacing the following method:

--------------------------------------------------------
public Geometry decodeGeometryValue(GeometryDescriptor descriptor,
            ResultSet rs, String column, GeometryFactory factory, Connection cx 
)
            throws IOException, SQLException {
        
        //read the geometry
        Geometry geom = readGeometry( rs, column, factory, cx );
        
        //grab the binding
        Class targetClazz = descriptor.getType().getBinding();
        
        // in Oracle you can have polygons in a column declared to be 
multipolygon, and so on...
        // so we better convert geometries, since our feature model is not so 
lenient
        if(targetClazz.equals(MultiPolygon.class) && geom instanceof Polygon){
            if (geom == null) return factory.createMultiPolygon(null);// added 
avalls to suppport null/empty geometries
                        else return factory.createMultiPolygon(new Polygon[] 
{(Polygon) geom});
        }
        else if(targetClazz.equals(MultiPoint.class) && geom instanceof Point) {
                        if (geom == null) return 
factory.createGeometryCollection(null);// added avalls to suppport null/empty 
geometries
            else return factory.createMultiPoint(new Point[] {(Point) geom});
        }
        else if(targetClazz.equals(MultiLineString.class) && geom instanceof 
LineString) {
                        if (geom == null) return 
factory.createMultiLineString(null);// added avalls to suppport null/empty 
geometries
            else return factory.createMultiLineString(new LineString[] 
{(LineString) geom});
        }
        else if(targetClazz.equals(GeometryCollection.class)) {
                        if (geom == null) return 
factory.createGeometryCollection(null);// added avalls to suppport null/empty 
geometries
            else return factory.createGeometryCollection(new Geometry[] {geom});
        }
        return geom;
}
--------------------------------------------------------

If you need further information don't hesitate to ask.

albert



-- 
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

        

------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to