Strabon

changeset 1482:bd7c59599449 temporals

Changed the getSRID functions as in the default branch.
author George Stamoulis <gstam@di.uoa.gr>
date Sat Feb 21 12:38:36 2015 +0200 (2015-02-21)
parents faad70631f8b
children 1b37b53e9065
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java 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/function/spatial/AbstractWKT.java	Mon Feb 09 19:19:29 2015 +0200
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java	Sat Feb 21 12:38:36 2015 +0200
     1.3 @@ -11,6 +11,7 @@
     1.4  
     1.5  import java.net.URI;
     1.6  
     1.7 +import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper;
     1.8  import org.slf4j.Logger;
     1.9  import org.slf4j.LoggerFactory;
    1.10  
    1.11 @@ -152,15 +153,17 @@
    1.12  			// FIXME: handle invalid URIs
    1.13  			URI crs = URI.create(wkt.substring(1, uriIndx));
    1.14  			
    1.15 +			/*
    1.16  			if (GeoConstants.CRS84_URI.equals(crs.toString())) {
    1.17  				srid = GeoConstants.EPSG4326_SRID;
    1.18 -				
    1.19 -			} else { // parse it to get the srid
    1.20 -				// FIXME: this code assumes an EPSG URI
    1.21 +			}
    1.22 +			else {
    1.23  				srid = getEPSG_SRID(crs.toString());
    1.24 -				
    1.25 -			}
    1.26 +			}*/
    1.27  			
    1.28 +			// FIXME: this code assumes an EPSG URI or CRS84
    1.29 +			srid = WKTHelper.getSRID(crs.toString());
    1.30 +							
    1.31  			// trim spaces after URI and get the WKT value
    1.32  			wkt = wkt.substring(uriIndx + 1).trim();
    1.33  		}
    1.34 @@ -190,7 +193,7 @@
    1.35  	 * 
    1.36  	 * @param wkt
    1.37  	 * @return
    1.38 -	 */
    1.39 +	 
    1.40  	protected int getEPSG_SRID(String wkt) {
    1.41  		int srid = GeoConstants.defaultSRID;
    1.42  		
    1.43 @@ -203,5 +206,5 @@
    1.44  		}
    1.45  		
    1.46  		return srid;
    1.47 -	}
    1.48 +	}*/
    1.49  }
     2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java	Mon Feb 09 19:19:29 2015 +0200
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java	Sat Feb 21 12:38:36 2015 +0200
     2.3 @@ -53,24 +53,40 @@
     2.4  	 * Returns the SRID of the given WKT (if any). If the WKT
     2.5  	 * does not contain any, then the default is returned.
     2.6  	 * 
     2.7 -	 * FIXME I think that this works only for stRDF. If this is its purpose, rename it to reflect it.
     2.8 +	 * The given string can also be just a plain URI of the SRID:
     2.9 +	 * 	1.If it is an EPSG URI the SRID of it is returned.
    2.10 +	 * 	2.If it is CRS84 URI then SRID 4326 is returned.
    2.11 +	 * 	3.If none of the above two, the default SRID(4326) is returned.
    2.12  	 * 
    2.13 -	 * @param wkt
    2.14 +	 * @param wktOrCrs
    2.15  	 * @return
    2.16  	 */
    2.17 -	public static Integer getSRID(String wkt) {
    2.18 +	public static Integer getSRID(String wktOrCrs) {
    2.19  		int srid = GeoConstants.default_stRDF_SRID;
    2.20  		
    2.21 -		if (wkt == null) return srid;
    2.22 +		if (wktOrCrs == null) return srid;
    2.23  		
    2.24 -		int pos = wkt.lastIndexOf(STRDF_SRID_DELIM);
    2.25 +		int pos = wktOrCrs.lastIndexOf(STRDF_SRID_DELIM);
    2.26  		if (pos != -1) {
    2.27 +			//Input is a string with the geometry and the srid URI
    2.28  			try {
    2.29 -				srid = Integer.parseInt(wkt.substring(wkt.lastIndexOf(CUT_DELIM) + 1).replace(URI_ENDING, ""));
    2.30 +				srid = Integer.parseInt(wktOrCrs.substring(wktOrCrs.lastIndexOf(CUT_DELIM) + 1).replace(URI_ENDING, ""));
    2.31 +			} catch (NumberFormatException e) {
    2.32 +				logger.warn("[Strabon.WKTHelper] Was expecting an integer. The URL of the SRID was {}. Continuing with the default SRID, {}", wktOrCrs.substring(pos + 1), srid);			
    2.33 +			}
    2.34 +		}
    2.35 +		else {
    2.36 +			//Input is a string with srid URI
    2.37 +			if (GeoConstants.CRS84_URI.equals(wktOrCrs)) {
    2.38 +				return GeoConstants.EPSG4326_SRID;
    2.39  				
    2.40 -			} catch (NumberFormatException e) {
    2.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);
    2.42 -				
    2.43 +			} else { // should be an EPSG one, need to parse
    2.44 +				try {
    2.45 +					srid = Integer.parseInt(wktOrCrs.substring(wktOrCrs.lastIndexOf(CUT_DELIM) + 1).replace(URI_ENDING, ""));
    2.46 +					
    2.47 +				} catch (NumberFormatException e) {
    2.48 +					logger.warn("[Strabon.WKTHelper] Malformed URI for CRS. The URL was {}.", wktOrCrs);
    2.49 +				}
    2.50  			}
    2.51  		}
    2.52  		
     3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java	Mon Feb 09 19:19:29 2015 +0200
     3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java	Sat Feb 21 12:38:36 2015 +0200
     3.3 @@ -23,6 +23,7 @@
     3.4  import org.opengis.referencing.crs.CoordinateReferenceSystem;
     3.5  import org.opengis.referencing.operation.MathTransform;
     3.6  import org.opengis.referencing.operation.TransformException;
     3.7 +import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper;
     3.8  import org.slf4j.Logger;
     3.9  import org.slf4j.LoggerFactory;
    3.10  
    3.11 @@ -189,14 +190,38 @@
    3.12  	 * @throws JAXBException
    3.13  	 */
    3.14  	public Geometry GMLread(String gml) throws JAXBException {
    3.15 -        StringReader reader = new StringReader(gml);
    3.16 -		
    3.17 +		StringReader reader = new StringReader(gml);
    3.18 +
    3.19          JAXBContext context = JAXBContext.newInstance("org.jvnet.ogc.gml.v_3_1_1.jts");	
    3.20          Unmarshaller unmarshaller = context.createUnmarshaller();
    3.21          Geometry geometry = (Geometry) unmarshaller.unmarshal(reader);
    3.22  		
    3.23  		reader.close();
    3.24 -        return geometry;
    3.25 +		
    3.26 +		/**
    3.27 +		 * When unmarshalling GML, GML-JTS tries to parse srsName as EPSG code using the following patterns:
    3.28 +		 * 	EPSG:{0,number,integer}
    3.29 +         *  urn:ogc:def:crs:EPSG::{0,number,#}
    3.30 +         *  urn:ogc:def:crs:EPSG:{1}:{0,number,#}
    3.31 +         *  urn:x-ogc:def:crs:EPSG::{0,number,#}
    3.32 +         *  urn:x-ogc:def:crs:EPSG:{1}:{0,number,#}
    3.33 +         *  http://www.opengis.net/gml/srs/epsg.xml#\{0,number,#}
    3.34 +		 * If srsName matched one of the pattern, it will be parsed as assigned to the SRID property of the JTS geometry.
    3.35 +         * If none of the patterns matched, srsName will be simply saved to the UserData property of the JTS geometry.
    3.36 +		 */
    3.37 +		
    3.38 +		/**
    3.39 +		 * SOLUTION: To deal with the fact that the srsName might not come in one of the supported formats,
    3.40 +		 * we check the userData variable of the geometry after the unmarshal call. If it is not null,
    3.41 +		 * then we have the string that represents the srid and we need to extract it and set it in the geometry inastance.
    3.42 +		 */
    3.43 +		if (geometry.getUserData() != null) {
    3.44 +			geometry.setSRID(WKTHelper.getSRID((String)geometry.getUserData()));
    3.45 +	        return geometry;
    3.46 +		}
    3.47 +		else {
    3.48 +			return geometry;
    3.49 +		}		
    3.50  	}
    3.51  	
    3.52  	public synchronized String GMLWrite(Geometry geom) {