# HG changeset patch # User George Stamoulis # Date 1424515116 -7200 # Node ID bd7c59599449fb7d72d30c66f9cd48d83835b56c # Parent faad70631f8b473328b50d340f6bd5f309699d20 Changed the getSRID functions as in the default branch. diff -r faad70631f8b -r bd7c59599449 evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java Mon Feb 09 19:19:29 2015 +0200 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java Sat Feb 21 12:38:36 2015 +0200 @@ -11,6 +11,7 @@ import java.net.URI; +import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -152,15 +153,17 @@ // FIXME: handle invalid URIs URI crs = URI.create(wkt.substring(1, uriIndx)); + /* if (GeoConstants.CRS84_URI.equals(crs.toString())) { srid = GeoConstants.EPSG4326_SRID; - - } else { // parse it to get the srid - // FIXME: this code assumes an EPSG URI + } + else { srid = getEPSG_SRID(crs.toString()); - - } + }*/ + // FIXME: this code assumes an EPSG URI or CRS84 + srid = WKTHelper.getSRID(crs.toString()); + // trim spaces after URI and get the WKT value wkt = wkt.substring(uriIndx + 1).trim(); } @@ -190,7 +193,7 @@ * * @param wkt * @return - */ + protected int getEPSG_SRID(String wkt) { int srid = GeoConstants.defaultSRID; @@ -203,5 +206,5 @@ } return srid; - } + }*/ } diff -r faad70631f8b -r bd7c59599449 evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java Mon Feb 09 19:19:29 2015 +0200 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java Sat Feb 21 12:38:36 2015 +0200 @@ -53,24 +53,40 @@ * Returns the SRID of the given WKT (if any). If the WKT * does not contain any, then the default is returned. * - * FIXME I think that this works only for stRDF. If this is its purpose, rename it to reflect it. + * The given string can also be just a plain URI of the SRID: + * 1.If it is an EPSG URI the SRID of it is returned. + * 2.If it is CRS84 URI then SRID 4326 is returned. + * 3.If none of the above two, the default SRID(4326) is returned. * - * @param wkt + * @param wktOrCrs * @return */ - public static Integer getSRID(String wkt) { + public static Integer getSRID(String wktOrCrs) { int srid = GeoConstants.default_stRDF_SRID; - if (wkt == null) return srid; + if (wktOrCrs == null) return srid; - int pos = wkt.lastIndexOf(STRDF_SRID_DELIM); + int pos = wktOrCrs.lastIndexOf(STRDF_SRID_DELIM); if (pos != -1) { + //Input is a string with the geometry and the srid URI try { - srid = Integer.parseInt(wkt.substring(wkt.lastIndexOf(CUT_DELIM) + 1).replace(URI_ENDING, "")); + srid = Integer.parseInt(wktOrCrs.substring(wktOrCrs.lastIndexOf(CUT_DELIM) + 1).replace(URI_ENDING, "")); + } catch (NumberFormatException e) { + logger.warn("[Strabon.WKTHelper] Was expecting an integer. The URL of the SRID was {}. Continuing with the default SRID, {}", wktOrCrs.substring(pos + 1), srid); + } + } + else { + //Input is a string with srid URI + if (GeoConstants.CRS84_URI.equals(wktOrCrs)) { + return GeoConstants.EPSG4326_SRID; - } catch (NumberFormatException e) { - logger.warn("[Strabon.WKTHelper] Was expecting an integer. The URL of the SRID was {}. Continuing with the default SRID, {}", wkt.substring(pos + 1), srid); - + } else { // should be an EPSG one, need to parse + try { + srid = Integer.parseInt(wktOrCrs.substring(wktOrCrs.lastIndexOf(CUT_DELIM) + 1).replace(URI_ENDING, "")); + + } catch (NumberFormatException e) { + logger.warn("[Strabon.WKTHelper] Malformed URI for CRS. The URL was {}.", wktOrCrs); + } } } diff -r faad70631f8b -r bd7c59599449 evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java Mon Feb 09 19:19:29 2015 +0200 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java Sat Feb 21 12:38:36 2015 +0200 @@ -23,6 +23,7 @@ import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.opengis.referencing.operation.MathTransform; import org.opengis.referencing.operation.TransformException; +import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -189,14 +190,38 @@ * @throws JAXBException */ public Geometry GMLread(String gml) throws JAXBException { - StringReader reader = new StringReader(gml); - + StringReader reader = new StringReader(gml); + JAXBContext context = JAXBContext.newInstance("org.jvnet.ogc.gml.v_3_1_1.jts"); Unmarshaller unmarshaller = context.createUnmarshaller(); Geometry geometry = (Geometry) unmarshaller.unmarshal(reader); reader.close(); - return geometry; + + /** + * When unmarshalling GML, GML-JTS tries to parse srsName as EPSG code using the following patterns: + * EPSG:{0,number,integer} + * urn:ogc:def:crs:EPSG::{0,number,#} + * urn:ogc:def:crs:EPSG:{1}:{0,number,#} + * urn:x-ogc:def:crs:EPSG::{0,number,#} + * urn:x-ogc:def:crs:EPSG:{1}:{0,number,#} + * http://www.opengis.net/gml/srs/epsg.xml#\{0,number,#} + * If srsName matched one of the pattern, it will be parsed as assigned to the SRID property of the JTS geometry. + * If none of the patterns matched, srsName will be simply saved to the UserData property of the JTS geometry. + */ + + /** + * SOLUTION: To deal with the fact that the srsName might not come in one of the supported formats, + * we check the userData variable of the geometry after the unmarshal call. If it is not null, + * then we have the string that represents the srid and we need to extract it and set it in the geometry inastance. + */ + if (geometry.getUserData() != null) { + geometry.setSRID(WKTHelper.getSRID((String)geometry.getUserData())); + return geometry; + } + else { + return geometry; + } } public synchronized String GMLWrite(Geometry geom) {