Strabon
changeset 1481:82f0d492d319
Added comments on how getSRID() function in WKTHelper.java works according to the input, and changed the implementation to match the description.
author | George Stamoulis <gstam@di.uoa.gr> |
---|---|
date | Fri Feb 13 17:31:49 2015 +0200 (2015-02-13) |
parents | 4435a397080a |
children | fdbcb246115b |
files | evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java |
line diff
1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java Fri Feb 13 13:29:40 2015 +0200 1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java Fri Feb 13 17:31:49 2015 +0200 1.3 @@ -53,30 +53,40 @@ 1.4 * Returns the SRID of the given WKT (if any). If the WKT 1.5 * does not contain any, then the default is returned. 1.6 * 1.7 - * FIXME I think that this works only for stRDF. If this is its purpose, rename it to reflect it. 1.8 + * The given string can also be just a plain URI of the SRID: 1.9 + * 1.If it is an EPSG URI the SRID of it is returned. 1.10 + * 2.If it is CRS84 URI then SRID 4326 is returned. 1.11 + * 3.If none of the above two, the default SRID(4326) is returned. 1.12 * 1.13 - * @param wkt 1.14 + * @param wktOrCrs 1.15 * @return 1.16 */ 1.17 - public static Integer getSRID(String wkt) { 1.18 + public static Integer getSRID(String wktOrCrs) { 1.19 int srid = GeoConstants.default_stRDF_SRID; 1.20 1.21 - if (wkt == null) return srid; 1.22 + if (wktOrCrs == null) return srid; 1.23 1.24 - try { 1.25 - if (GeoConstants.CRS84_URI.equals(wkt)) { 1.26 - srid = GeoConstants.EPSG4326_SRID; 1.27 + int pos = wktOrCrs.lastIndexOf(STRDF_SRID_DELIM); 1.28 + if (pos != -1) { 1.29 + //Input is a string with the geometry and the srid URI 1.30 + try { 1.31 + srid = Integer.parseInt(wktOrCrs.substring(wktOrCrs.lastIndexOf(CUT_DELIM) + 1).replace(URI_ENDING, "")); 1.32 + } catch (NumberFormatException e) { 1.33 + logger.warn("[Strabon.WKTHelper] Was expecting an integer. The URL of the SRID was {}. Continuing with the default SRID, {}", wktOrCrs.substring(pos + 1), srid); 1.34 } 1.35 - else { 1.36 - srid = Integer.parseInt(wkt.substring(wkt.lastIndexOf(CUT_DELIM) + 1).replace(URI_ENDING, "")); 1.37 - } 1.38 - } catch (NumberFormatException e) { 1.39 - int pos = wkt.lastIndexOf(STRDF_SRID_DELIM); 1.40 - if (pos != -1) { 1.41 - logger.warn("[Strabon.WKTHelper] Was expecting an integer. The URL of the SRID was {}. Continuing with the default SRID, {}", wkt.substring(pos + 1), srid); 1.42 - } 1.43 - else { 1.44 - logger.warn("[Strabon.WKTHelper] Was expecting an integer. The URL of the SRID was {}. Continuing with the default SRID, {}", wkt, srid); 1.45 + } 1.46 + else { 1.47 + //Input is a string with srid URI 1.48 + if (GeoConstants.CRS84_URI.equals(wktOrCrs)) { 1.49 + return GeoConstants.EPSG4326_SRID; 1.50 + 1.51 + } else { // should be an EPSG one, need to parse 1.52 + try { 1.53 + srid = Integer.parseInt(wktOrCrs.substring(wktOrCrs.lastIndexOf(CUT_DELIM) + 1).replace(URI_ENDING, "")); 1.54 + 1.55 + } catch (NumberFormatException e) { 1.56 + logger.warn("[Strabon.WKTHelper] Malformed URI for CRS. The URL was {}.", wktOrCrs); 1.57 + } 1.58 } 1.59 } 1.60