Strabon

changeset 1386:800df0b6eca9

moved AbstractWKT.getURI_forSRID() to WKTHelper and added there also creator methods for stRDF and GeoSPARQL WKT literals
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed Sep 17 15:05:15 2014 +0300 (2014-09-17)
parents e2fddbbc87f9
children a110fd2b1880
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/iterator/StSPARQLGroupIterator.java generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java
line diff
     1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java	Wed Sep 17 15:04:57 2014 +0300
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java	Wed Sep 17 15:05:15 2014 +0300
     1.3 @@ -175,31 +175,6 @@
     1.4  	}
     1.5  	
     1.6  	/**
     1.7 -	 * Returns the URI corresponding to the given SRID.
     1.8 -	 * The given SRID might be an EPSG one or our custom 84000
     1.9 -	 * corresponding to CRS84. If the given SRID is less than
    1.10 -	 * or equal to 0, then an empty string is returned.
    1.11 -	 * 
    1.12 -	 * @param srid
    1.13 -	 * @return
    1.14 -	 */
    1.15 -	public static String getURI_forSRID(int srid) {
    1.16 -		String uri = "";
    1.17 -		if (srid == GeoConstants.WGS84_LONG_LAT_SRID) {
    1.18 -			uri = GeoConstants.WGS84_LONG_LAT;
    1.19 -			
    1.20 -		} else if (srid > 0) { // assuming EPSG now
    1.21 -			uri = GeoConstants.EPSG_URI_PREFIX + srid; 
    1.22 -		}
    1.23 -		
    1.24 -		if (uri.length() > 0) {
    1.25 -			uri = "<" + uri + ">";
    1.26 -		}
    1.27 -		
    1.28 -		return uri;
    1.29 -	}
    1.30 -	
    1.31 -	/**
    1.32  	 * Returns the SRID corresponding to the URI of the given CRS. We assume
    1.33  	 * EPSG URIs only.
    1.34  	 * 
     2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java	Wed Sep 17 15:04:57 2014 +0300
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java	Wed Sep 17 15:05:15 2014 +0300
     2.3 @@ -72,4 +72,90 @@
     2.4  		
     2.5  		return srid;
     2.6  	}
     2.7 +	
     2.8 +	/**
     2.9 +	 * Given the WKT representation of a geometry, a SRID, and a datatype, it
    2.10 +	 * creates a WKT literal conforming to the syntax implied by the given
    2.11 +	 * datatype. If the given datatype is NULL or different than one of the
    2.12 +	 * standard ones (e.g., {@link GeoConstants.WKT} or
    2.13 +	 * {@link GeoConstants.WKTLITERAL}), then the default literal is returned,
    2.14 +	 * which is determined by {@link GeoConstants.default_WKT_datatype}.  
    2.15 +	 * 
    2.16 +	 * @param plainWKT
    2.17 +	 * @param srid
    2.18 +	 * @param datatype
    2.19 +	 * @return
    2.20 +	 */
    2.21 +	public static String createWKT(String plainWKT, int srid, String datatype) {
    2.22 +		if (GeoConstants.WKTLITERAL.equals(datatype)) {
    2.23 +			return createWKTLiteral(plainWKT, srid);
    2.24 +			
    2.25 +		} else if (GeoConstants.WKT.equals(datatype)) {
    2.26 +			return createstRDFWKT(plainWKT, srid);
    2.27 +			
    2.28 +		} else { // no datatype, create default
    2.29 +			return createWKT(plainWKT, srid, GeoConstants.default_WKT_datatype);
    2.30 +		}
    2.31 +	}
    2.32 +	
    2.33 +	/**
    2.34 +	 * Given the well-known representation of a geometry and a SRID, it creates
    2.35 +	 * a stRDF WKT literal. If the given SRID is the default for that type, then
    2.36 +	 * it is ignored. 
    2.37 +	 * 
    2.38 +	 * @param plainWKT
    2.39 +	 * @param srid
    2.40 +	 * @return
    2.41 +	 */
    2.42 +	public static String createstRDFWKT(String plainWKT, int srid) {
    2.43 +		if (srid == GeoConstants.default_stRDF_SRID) {
    2.44 +			return plainWKT;
    2.45 +			
    2.46 +		} else {
    2.47 +			return plainWKT + ";" + getURI_forSRID(srid);
    2.48 +		}
    2.49 +	}
    2.50 +	
    2.51 +	/**
    2.52 +	 * Given the well-known representation of a geometry and a SRID, it creates
    2.53 +	 * a GeoSPARQL wktLiteral literal. If the given SRID is the default for that type, then
    2.54 +	 * it is ignored.
    2.55 +	 * 
    2.56 +	 * @param plainWKT
    2.57 +	 * @param srid
    2.58 +	 * @return
    2.59 +	 */
    2.60 +	public static String createWKTLiteral(String plainWKT, int srid) {
    2.61 +		if (srid == GeoConstants.default_GeoSPARQL_SRID) {
    2.62 +			return plainWKT;
    2.63 +			
    2.64 +		} else {
    2.65 +			return getURI_forSRID(srid) + " " + plainWKT; 
    2.66 +		}
    2.67 +	}
    2.68 +	
    2.69 +	/**
    2.70 +	 * Returns the URI corresponding to the given SRID.
    2.71 +	 * The given SRID might be an EPSG one or our custom 84000
    2.72 +	 * corresponding to CRS84. If the given SRID is less than
    2.73 +	 * or equal to 0, then an empty string is returned.
    2.74 +	 * 
    2.75 +	 * @param srid
    2.76 +	 * @return
    2.77 +	 */
    2.78 +	public static String getURI_forSRID(int srid) {
    2.79 +		String uri = "";
    2.80 +		if (srid == GeoConstants.WGS84_LONG_LAT_SRID) {
    2.81 +			uri = GeoConstants.WGS84_LONG_LAT;
    2.82 +			
    2.83 +		} else if (srid > 0) { // assuming EPSG now
    2.84 +			uri = GeoConstants.EPSG_URI_PREFIX + srid; 
    2.85 +		}
    2.86 +		
    2.87 +		if (uri.length() > 0) {
    2.88 +			uri = "<" + uri + ">";
    2.89 +		}
    2.90 +		
    2.91 +		return uri;
    2.92 +	}
    2.93  }
     3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java	Wed Sep 17 15:04:57 2014 +0300
     3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/iterator/StSPARQLGroupIterator.java	Wed Sep 17 15:05:15 2014 +0300
     3.3 @@ -52,8 +52,8 @@
     3.4  import org.openrdf.query.algebra.evaluation.ValueExprEvaluationException;
     3.5  import org.openrdf.query.algebra.evaluation.function.Function;
     3.6  import org.openrdf.query.algebra.evaluation.function.FunctionRegistry;
     3.7 -import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT;
     3.8  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
     3.9 +import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper;
    3.10  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.aggregate.ExtentFunc;
    3.11  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BoundaryFunc;
    3.12  import org.openrdf.query.algebra.evaluation.function.spatial.stsparql.construct.BufferFunc;
    3.13 @@ -358,7 +358,9 @@
    3.14  				if (val != null) {
    3.15  					if(val instanceof StrabonPolyhedron)
    3.16  					{ // TODO FIXME why we assume here strdf:WKT? Can we generalize?
    3.17 -						String label = val.toString() + ";" + AbstractWKT.getURI_forSRID(((StrabonPolyhedron)val).getGeometry().getSRID());
    3.18 +						String label = WKTHelper.createWKT(val.toString(), 
    3.19 +														   ((StrabonPolyhedron)val).getGeometry().getSRID(), 
    3.20 +														   GeoConstants.WKT);
    3.21  						Literal wkt = new LiteralImpl(label,new URIImpl(GeoConstants.WKT));
    3.22  						sol.setBinding(name,wkt);
    3.23  					}
    3.24 @@ -367,12 +369,8 @@
    3.25  						sol.setBinding(name, val);
    3.26  					}
    3.27  				}
    3.28 -
    3.29  			}
    3.30  
    3.31 -
    3.32 -
    3.33 -
    3.34  		}
    3.35  
    3.36  		/**
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java	Wed Sep 17 15:04:57 2014 +0300
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/model/GeneralDBPolyhedron.java	Wed Sep 17 15:05:15 2014 +0300
     4.3 @@ -3,14 +3,12 @@
     4.4  import java.io.IOException;
     4.5  
     4.6  import org.openrdf.model.URI;
     4.7 -import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT;
     4.8  import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
     4.9 +import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper;
    4.10  import org.openrdf.sail.rdbms.model.RdbmsValue;
    4.11  
    4.12  import com.vividsolutions.jts.io.ParseException;
    4.13  
    4.14 -import eu.earthobservatory.constants.GeoConstants;
    4.15 -
    4.16  /**
    4.17   * 
    4.18   * @author Manos Karpathiotakis <mk@di.uoa.gr>
    4.19 @@ -94,32 +92,18 @@
    4.20  
    4.21  
    4.22  	public String stringValue() {
    4.23 -		if(String.valueOf(datatype) == GeoConstants.WKT) {
    4.24 -			return new String(this.polyhedronStringRep) + ";" + AbstractWKT.getURI_forSRID(this.getPolyhedron().getGeometry().getSRID());
    4.25 -			
    4.26 -		} else {
    4.27 -			return new String(AbstractWKT.getURI_forSRID(this.getPolyhedron().getGeometry().getSRID()) + " " + this.polyhedronStringRep);
    4.28 -		} // TODO FIXME we miss GML here
    4.29 +		// TODO FIXME we miss GML here
    4.30 +		return WKTHelper.createWKT(this.polyhedronStringRep, 
    4.31 +								   this.getPolyhedron().getGeometry().getSRID(), 
    4.32 +								   String.valueOf(datatype));
    4.33  	}
    4.34  
    4.35  	@Override
    4.36  	public String toString() {
    4.37 -		if(String.valueOf(datatype) == GeoConstants.WKT)
    4.38 -		{
    4.39 -			return new String("\""+this.polyhedronStringRep+";" +AbstractWKT.getURI_forSRID(this.getPolyhedron().getGeometry().getSRID())+"\"" + "^^<" +
    4.40 -					((StrabonPolyhedron.EnableConstraintRepresentation)  ?
    4.41 -							GeoConstants.stRDFSemiLinearPointset : String.valueOf(datatype))+">");
    4.42 -		}
    4.43 -		else if(String.valueOf(datatype) == GeoConstants.WKTLITERAL)
    4.44 -		{
    4.45 -			return new String("\""+AbstractWKT.getURI_forSRID(this.getPolyhedron().getGeometry().getSRID())+" "+this.polyhedronStringRep
    4.46 -					+"\"" + "^^<" +
    4.47 -					((StrabonPolyhedron.EnableConstraintRepresentation)  ?
    4.48 -							GeoConstants.stRDFSemiLinearPointset : String.valueOf(datatype))
    4.49 -							+">");
    4.50 -		}
    4.51 -		//must not reach this place
    4.52 -		return null;
    4.53 +		// TODO FIXME we miss GML here
    4.54 +		return "\"" + WKTHelper.createWKT(this.polyhedronStringRep, 
    4.55 +				   						  this.getPolyhedron().getGeometry().getSRID(), 
    4.56 +				   						  String.valueOf(datatype)) +"\"" + "^^<" + String.valueOf(datatype) + ">";
    4.57  	}
    4.58  
    4.59  	@Override
     5.1 --- a/vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java	Wed Sep 17 15:04:57 2014 +0300
     5.2 +++ b/vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java	Wed Sep 17 15:05:15 2014 +0300
     5.3 @@ -204,7 +204,12 @@
     5.4  	/**
     5.5  	 * Default SRID (WGS84 longitude/latitude)
     5.6  	 */
     5.7 -	public static final Integer defaultSRID 	= WGS84_LONG_LAT_SRID;
     5.8 +	public static final Integer defaultSRID 			= WGS84_LONG_LAT_SRID;
     5.9 +	
    5.10 +	/**
    5.11 +	 * Default datatype for creating new well-known text literals
    5.12 +	 */
    5.13 +	public static final String default_WKT_datatype 	= WKTLITERAL; 
    5.14  	
    5.15  	/**																		*
    5.16  	 *  						Extended functions 							*