Hi,

I have created an issue and a PR:

Jira-issue:
https://osgeo-org.atlassian.net/browse/GEOT-6587

Pull request:
https://github.com/geotools/geotools/pull/2926

Regards,
Paul

Von: Jody Garnett <jody.garn...@gmail.com>
Gesendet: Dienstag, 12. Mai 2020 02:49
An: Biskup, Paul <paul.bis...@fit.fichtner.de>; Uhrig, Stefan 
<stefan.uh...@sap.com>
Cc: geotools-devel@lists.sourceforge.net
Betreff: Re: [Geotools-devel] Exception in SAP-HANA-datastore when using a 
HANA-view

Thanks for joining the developer list with a fix, yes please create an issue in 
jira, and a PR with your fix. Checking the plugin 
pom.xml<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgeotools%2Fgeotools%2Fblob%2Fmaster%2Fmodules%2Fplugin%2Fjdbc%2Fjdbc-hana%2Fpom.xml&data=02%7C01%7CPaul.Biskup%40fit.fichtner.de%7Cc85b4b889cce4009e5dd08d7f60e65fd%7Cb43430ce7d754158ab7b1f39e6fe6b3f%7C0%7C0%7C637248414005411269&sdata=3dWt1qoFf3nzlIS%2BASbHfftbykV5gY3wEe7fLsl1Z0U%3D&reserved=0>
 shows Stefan is the module maintainer and should be in a position to review.

Stay safe!
--
Jody Garnett


On Mon, 11 May 2020 at 08:42, Biskup, Paul 
<paul.bis...@fit.fichtner.de<mailto:paul.bis...@fit.fichtner.de>> wrote:
Hi all,

I’ve been recently using the SAP HANA-datastore in GeoServer, which works great.
Unfortunately there is a problem if you publish a HANA-view as a layer and try 
to do a spatial GetFeature-request on this layer. The view can be published and 
displayed as WMS, but if you do a GetFeature-request, you get this exception:

<ows:ExceptionText>java.lang.RuntimeException: java.io.IOException
java.io.IOExceptionSAP DBTech JDBC: [8]: invalid argument: The given SRID (-1) 
does not match the field's SRID (31466) at function __st_geomfromwkb__() (at 
pos 134) </ows:ExceptionText>

The SRID from the geometry-column in my view is EPSG:31466.

I have already analyzed the problem and have also found a fix for this problem.
The problem is, that in a spatial GetFeature-request the code tries to get the 
SRID from the layer by executing this SQL-Statement:

                                "SELECT SRS_ID FROM PUBLIC.ST_GEOMETRY_COLUMNS 
WHERE SCHEMA_NAME = ? AND TABLE_NAME = ? AND COLUMN_NAME = ?");

https://github.com/geotools/geotools/blob/b1be2cef1c06058f726bce94ac665ee50b571db6/modules/plugin/jdbc/jdbc-hana/src/main/java/org/geotools/data/hana/HanaDialect.java#L193<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgeotools%2Fgeotools%2Fblob%2Fb1be2cef1c06058f726bce94ac665ee50b571db6%2Fmodules%2Fplugin%2Fjdbc%2Fjdbc-hana%2Fsrc%2Fmain%2Fjava%2Forg%2Fgeotools%2Fdata%2Fhana%2FHanaDialect.java%23L193&data=02%7C01%7CPaul.Biskup%40fit.fichtner.de%7Cc85b4b889cce4009e5dd08d7f60e65fd%7Cb43430ce7d754158ab7b1f39e6fe6b3f%7C0%7C0%7C637248414005411269&sdata=HxfLFNA5IUyQi58IFiHORZDgJnzpsBYwaG580Ojnvxk%3D&reserved=0>

But the PUBLIC.ST_GEOMETRY-view in HANA is only filled for tables and not for 
views. That is why in my request the SRID of the layer can not be found and a 
„-1“ is returned.
Further have I analyzed, that the received SRID is passed in the 
„prepareGeometryValue“-function, which is used to create the sql-statement.
https://github.com/geotools/geotools/blob/b1be2cef1c06058f726bce94ac665ee50b571db6/modules/plugin/jdbc/jdbc-hana/src/main/java/org/geotools/data/hana/HanaDialect.java#L732<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fgeotools%2Fgeotools%2Fblob%2Fb1be2cef1c06058f726bce94ac665ee50b571db6%2Fmodules%2Fplugin%2Fjdbc%2Fjdbc-hana%2Fsrc%2Fmain%2Fjava%2Forg%2Fgeotools%2Fdata%2Fhana%2FHanaDialect.java%23L732&data=02%7C01%7CPaul.Biskup%40fit.fichtner.de%7Cc85b4b889cce4009e5dd08d7f60e65fd%7Cb43430ce7d754158ab7b1f39e6fe6b3f%7C0%7C0%7C637248414005421260&sdata=j9zzFk3oBN0A3FKzSD7rdnxdJkpXLYS7qvspSZ9eZUk%3D&reserved=0>

There is an easy fix for this problem:
If you change the „prepareGeometryValue“-code like this, the SRID will only be 
passed to the „ST_GeomFromWKB“-function, if it is „>1“:

    public void prepareGeometryValue(
            Class<? extends Geometry> gClass,
            int dimension,
            int srid,
            Class binding,
            StringBuffer sql) {
        String pattern = null;
        if (srid > -1) {
            pattern = "ST_GeomFromWKB( ? ,{0})";
            sql.append(MessageFormat.format(pattern, Integer.toString(srid)));
        } else {
            sql.append("ST_GeomFromWKB( ? )");
        }
    }

If no SRID is passed, the HANA-function assumes, that the SRID is in the same 
coordinate system as the passed coordinates.
The fix is working in my locally build JDBC-HANA-Datastore and GeoServer.

Could you please take a look at this and tell me if I should create an issue in 
your JIRA?

Best regards,
Paul
_______________________________________________
GeoTools-Devel mailing list
GeoTools-Devel@lists.sourceforge.net<mailto:GeoTools-Devel@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/geotools-devel<https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fgeotools-devel&data=02%7C01%7CPaul.Biskup%40fit.fichtner.de%7Cc85b4b889cce4009e5dd08d7f60e65fd%7Cb43430ce7d754158ab7b1f39e6fe6b3f%7C0%7C0%7C637248414005421260&sdata=sz0ZAJ7talziuKsKDrXneJ4Chk2ecot8fOFTatOlHzg%3D&reserved=0>
_______________________________________________
GeoTools-Devel mailing list
GeoTools-Devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to