Strabon

changeset 389:578b40921312

added proper GML namespace for a working GMLReader, added GMLread function in JTSWrapper, updated references to JTSWrapper.GMLReader and made it deprecated
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed Jun 27 22:28:49 2012 +0300 (2012-06-27)
parents 390625cc49c3
children c10fc476477b
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java resultio/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java resultio/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java
line diff
     1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java	Wed Jun 27 20:09:43 2012 +0300
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/GeoConstants.java	Wed Jun 27 22:28:49 2012 +0300
     1.3 @@ -33,11 +33,30 @@
     1.4  	public static final String WKT 						= stRDF + "WKT";
     1.5  
     1.6  	/**
     1.7 -	 * The URI for the datatype Geography Markup Langague (GML)
     1.8 +	 * The URI for the datatype Geography Markup Language (GML) as it defined
     1.9 +	 * in the model stRDF and query language stSPARQL
    1.10  	 */
    1.11  	public static final String GML						= stRDF + "GML";
    1.12  
    1.13  	/**
    1.14 +	 * 
    1.15 +	 * The URI for the namespace of GML.
    1.16 +	 * 
    1.17 +	 * Initially, it was set to "http://www.opengis.net/def/geometryType/OGC-GML/3.2/".
    1.18 +	 * Afterwards, it was set to "http://www.opengis.net/gml/3.2/" in order to be compliant
    1.19 +	 * with GML version 3.3, as defined by OGC in the document with title
    1.20 +	 * <tt>"OGC® Geography Markup Language (GML) — Extended schemas and encoding rules"</tt>
    1.21 +	 * ({@link https://portal.opengeospatial.org/files/?artifact_id=46568}). However, none
    1.22 +	 * of these work with the parser provided by JTS, which assumes that the namespace for
    1.23 +	 * GML should be only "http://www.opengis.net/gml" and nothing else. In every other case,
    1.24 +	 * an exception is thrown by the GML parser.
    1.25 +	 * 
    1.26 +	 * 
    1.27 +	 * @see {@link org.openrdf.query.algebra.evaluation.util.JTSWrapper.GMLReader}, {@link GMLReader}
    1.28 +	 */
    1.29 +	public static final String GML_OGC					= "http://www.opengis.net/gml";
    1.30 +	
    1.31 +	/**
    1.32  	 * The namespace for geometry functions declared by GeoSPARQL
    1.33  	 */
    1.34  	public static final String geof						= "http://www.opengis.net/def/queryLanguage/OGC-GeoSPARQL/1.0/function/";
     2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java	Wed Jun 27 20:09:43 2012 +0300
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java	Wed Jun 27 22:28:49 2012 +0300
     2.3 @@ -113,7 +113,7 @@
     2.4  		} catch (ParseException e) {
     2.5  			try {
     2.6  				// try as GML
     2.7 -				geometry = JTSWrapper.GMLReader(representation);
     2.8 +				geometry = jts.GMLread(representation);
     2.9  				
    2.10  			} catch (Exception e1) {
    2.11  				throw new IllegalArgumentException(e1);
    2.12 @@ -172,7 +172,7 @@
    2.13  	public StrabonPolyhedron(String WKT, int algorithm) throws Exception {
    2.14  		if(WKT.contains("gml"))
    2.15  		{
    2.16 -			Geometry geo = JTSWrapper.GMLReader(WKT);
    2.17 +			Geometry geo = jts.GMLread(WKT);
    2.18  			this.geometry = new StrabonPolyhedron(geo).geometry;
    2.19  		}
    2.20  		else
     3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java	Wed Jun 27 20:09:43 2012 +0300
     3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java	Wed Jun 27 22:28:49 2012 +0300
     3.3 @@ -1,6 +1,3 @@
     3.4 -/**
     3.5 - * 
     3.6 - */
     3.7  package org.openrdf.query.algebra.evaluation.util;
     3.8  
     3.9  import java.io.IOException;
    3.10 @@ -23,6 +20,7 @@
    3.11  import org.xml.sax.SAXException;
    3.12  
    3.13  import com.vividsolutions.jts.geom.Geometry;
    3.14 +import com.vividsolutions.jts.io.gml2.GMLReader;
    3.15  import com.vividsolutions.jts.io.ParseException;
    3.16  import com.vividsolutions.jts.io.WKBReader;
    3.17  import com.vividsolutions.jts.io.WKBWriter;
    3.18 @@ -65,6 +63,11 @@
    3.19  	 */
    3.20  	private WKBWriter wkbw;
    3.21  	
    3.22 +	/**
    3.23 +	 * Reader for GML
    3.24 +	 */
    3.25 +	private GMLReader gmlr;
    3.26 +	
    3.27  	
    3.28  	private JTSWrapper() {
    3.29  		// use a private constructor to force call of getInstance method and forbid subclassing
    3.30 @@ -73,6 +76,7 @@
    3.31  		wkbr = new WKBReader();
    3.32  		wkbw = new WKBWriter(); // PostGIS
    3.33  //		wkbw = new WKBWriter(2, WKBConstants.wkbXDR); // MonetDB
    3.34 +		gmlr = new GMLReader();
    3.35  	}
    3.36  	
    3.37  	public static synchronized JTSWrapper getInstance() {
    3.38 @@ -153,12 +157,27 @@
    3.39  	 * 
    3.40  	 * @param gml
    3.41  	 * @return
    3.42 -	 * @throws IOException
    3.43 -	 * @throws SAXException
    3.44 -	 * @throws ParserConfigurationException
    3.45 +	 * @throws ParserConfigurationException 
    3.46 +	 * @throws IOException 
    3.47 +	 * @throws SAXException 
    3.48 +	 */
    3.49 +	public Geometry GMLread(String gml) throws SAXException, IOException, ParserConfigurationException {
    3.50 +			return gmlr.read(gml, null);
    3.51 +	}
    3.52 +		
    3.53 +	
    3.54 +	/**
    3.55 +	 * Parses and returns a {@link Geometry} object constructed from the given GML representation.
    3.56 +	 * 
    3.57 +	 * Why not use the class {@link GMLReader} that does the job and need to load on our own
    3.58 +	 * the XML parser of JTS?
    3.59 +	 * 
    3.60 +	 * @param gml
    3.61 +	 * @return
    3.62  	 * @throws JAXBException
    3.63  	 */
    3.64 -	public static Geometry GMLReader(String gml) throws IOException, SAXException, ParserConfigurationException, JAXBException {
    3.65 +	@Deprecated
    3.66 +	private static Geometry GMLReader(String gml) throws JAXBException {
    3.67          StringReader reader = new StringReader(gml);
    3.68  		
    3.69          JAXBContext context = JAXBContext.newInstance("org.jvnet.ogc.gml.v_3_1_1.jts");	
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java	Wed Jun 27 20:09:43 2012 +0300
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java	Wed Jun 27 22:28:49 2012 +0300
     4.3 @@ -49,11 +49,9 @@
     4.4  	 */
     4.5  	public static boolean isGeometryValue(Value value) {
     4.6  		if (value instanceof Literal) {
     4.7 -			// TODO: use #isGMLDatatype instead
     4.8  			Literal literal = (Literal) value;
     4.9 -			String datatype = literal.getDatatype() == null ? "":literal.getDatatype().stringValue();
    4.10 -			
    4.11 -			if (GeoConstants.WKT.equals(datatype) || GeoConstants.GML.equals(datatype)) {
    4.12 +
    4.13 +			if (isWKTLiteral(literal) || isGMLLiteral(literal)) {
    4.14  				return true;
    4.15  			}
    4.16  			
     5.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Wed Jun 27 20:09:43 2012 +0300
     5.2 +++ b/resultio/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Wed Jun 27 22:28:49 2012 +0300
     5.3 @@ -209,7 +209,7 @@
     5.4  				
     5.5  				} else { // URI, BlankNode, or Literal other than spatial literal 
     5.6  					if (logger.isDebugEnabled()) {
     5.7 -						logger.debug("[Strabon.KMLWriter] Found URI/BlankNode/Literal: {}", value);
     5.8 +						logger.debug("[Strabon.KMLWriter] Found URI/BlankNode/Literal ({}): {}", value.getClass(), value);
     5.9  					}
    5.10  					
    5.11  					// mark that we found sth corresponding to the description
     6.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java	Wed Jun 27 20:09:43 2012 +0300
     6.2 +++ b/resultio/src/main/java/org/openrdf/query/resultio/text/stSPARQLResultsTSVWriter.java	Wed Jun 27 22:28:49 2012 +0300
     6.3 @@ -20,12 +20,12 @@
     6.4  
     6.5  	@Override
     6.6  	protected void writeValue(Value val) throws IOException {
     6.7 -		// catch the spatial case and create a new literal
     6.8 -		// constructing a new literal is the only way if we want to reuse the {@link #writeValue(Value)} method
     6.9  		if (val instanceof GeneralDBPolyhedron) {
    6.10 +			// catch the spatial case and create a new literal
    6.11 +			// constructing a new literal is the only way if we want to reuse the {@link #writeValue(Value)} method
    6.12  			GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) val;
    6.13  			val = new LiteralImpl(dbpolyhedron.getPolyhedronStringRep(), dbpolyhedron.getDatatype());
    6.14 -		} 
    6.15 +		}
    6.16  		
    6.17  		// write value
    6.18  		super.writeValue(val);