Strabon
changeset 1479:1decd8c5c45d
Rewrite of the getSRIDfromGMLString() function in JTSWrapper.java using the unmarshaller features. Added comments to explain what is happening in each case.
author | George Stamoulis <gstam@di.uoa.gr> |
---|---|
date | Thu Feb 12 13:36:46 2015 +0200 (2015-02-12) |
parents | 6a0a8fe14ea6 |
children | 4435a397080a |
files | evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java |
line diff
1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java Wed Feb 11 18:31:49 2015 +0200 1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java Thu Feb 12 13:36:46 2015 +0200 1.3 @@ -36,6 +36,8 @@ 1.4 import com.vividsolutions.jts.io.gml2.GMLReader; 1.5 import com.vividsolutions.jts.io.gml2.GMLWriter; 1.6 1.7 +import eu.earthobservatory.constants.GeoConstants; 1.8 + 1.9 /** 1.10 * This class is a singleton and provides access to the readers/writers 1.11 * of Java Topology Suite. 1.12 @@ -206,22 +208,50 @@ 1.13 1.14 reader.close(); 1.15 1.16 - //get the geometry srdi from the xml input 1.17 - geometry.setSRID(getSRIDfromGMLString(gml)); 1.18 + /** 1.19 + * When unmarshalling GML, GML-JTS tries to parse srsName as EPSG code using the following patterns: 1.20 + * EPSG:{0,number,integer} 1.21 + * urn:ogc:def:crs:EPSG::{0,number,#} 1.22 + * urn:ogc:def:crs:EPSG:{1}:{0,number,#} 1.23 + * urn:x-ogc:def:crs:EPSG::{0,number,#} 1.24 + * urn:x-ogc:def:crs:EPSG:{1}:{0,number,#} 1.25 + * http://www.opengis.net/gml/srs/epsg.xml#\{0,number,#} 1.26 + * If srsName matched one of the pattern, it will be parsed as assigned to the SRID property of the JTS geometry. 1.27 + * If none of the patterns matched, srsName will be simply saved to the UserData property of the JTS geometry. 1.28 + */ 1.29 1.30 - return geometry; 1.31 + /** 1.32 + * SOLUTION: To deal with the fact that the srsName might not come in one of the supported formats, 1.33 + * we check the userData variable of the geometry after the unmarshal call. If it is not null, 1.34 + * then we have the string that represents the srid and we need to extract it and set it in the geometry inastance. 1.35 + */ 1.36 + if (geometry.getUserData() != null) { 1.37 + geometry.setSRID(getSRIDfromGMLString((String)geometry.getUserData())); 1.38 + return geometry; 1.39 + } 1.40 + else { 1.41 + return geometry; 1.42 + } 1.43 } 1.44 1.45 /** 1.46 - * Parse the gml string to find the SRID of the represented geometry. 1.47 + * Parse the userData string to find the SRID of the represented geometry. 1.48 + * We assume that the string represents an EPSG srid as defined in http://www.opengis.net/def/crs/EPSG/0 1.49 * 1.50 * @param gml 1.51 * @return 1.52 */ 1.53 - private int getSRIDfromGMLString(String gml) { 1.54 - String[] srs = gml.split("srsName=\"http://www.opengis.net/def/crs/EPSG/0/"); 1.55 - String[] num = srs[1].split("\""); 1.56 - return Integer.parseInt(num[0]); 1.57 + private int getSRIDfromGMLString(String reference) { 1.58 + int srid = GeoConstants.defaultSRID; 1.59 + 1.60 + try { 1.61 + srid = Integer.parseInt(reference.substring(reference.lastIndexOf('/') + 1)); 1.62 + 1.63 + } catch (NumberFormatException e) { 1.64 + logger.warn("[Strabon.AbstractWKT] Was expecting an integer. The URL of the EPSG SRID was {}. Continuing with the default SRID, {}", reference, srid); 1.65 + } 1.66 + 1.67 + return srid; 1.68 } 1.69 1.70 public synchronized String GMLWrite(Geometry geom) {