Strabon
changeset 1341:8a4441fb946e
KMLWriter: Apart from rendering GeoSPARQL/stRDF compliant WKT literals, we may as well want to transform WKT literals encoded as plain RDF literals. This may not be the case for Strabon but it could be for other endpoints (endpoint client uses KMLWriter).
author | Konstantina Bereta <Konstantina.Bereta@di.uoa.gr> |
---|---|
date | Tue May 27 11:56:46 2014 +0300 (2014-05-27) |
parents | c1cebf65ffe3 |
children | 12c3bba2c8a5 |
files | generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java vocab/src/main/java/eu/earthobservatory/constants/WKTConstants.java |
line diff
1.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java Mon May 26 19:36:50 2014 +0300 1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java Tue May 27 11:56:46 2014 +0300 1.3 @@ -15,10 +15,10 @@ 1.4 import org.openrdf.model.Value; 1.5 import org.openrdf.model.datatypes.XMLDateTime; 1.6 import org.openrdf.model.vocabulary.XMLSchema; 1.7 - 1.8 import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 1.9 1.10 import eu.earthobservatory.constants.GeoConstants; 1.11 +import eu.earthobservatory.constants.WKTConstants; 1.12 1.13 1.14 1.15 @@ -71,7 +71,11 @@ 1.16 * @return 1.17 */ 1.18 public static boolean isWKTLiteral(Literal literal) { 1.19 - return isWKTDatatype(literal.getDatatype()); 1.20 + if (literal.getDatatype() == null){ 1.21 + return containsWKTGeometry(literal); 1.22 + } else { 1.23 + return isWKTDatatype(literal.getDatatype()); 1.24 + } 1.25 } 1.26 1.27 /** 1.28 @@ -100,6 +104,20 @@ 1.29 GeoConstants.WKTLITERAL.equals(datatype.stringValue()); 1.30 } 1.31 1.32 + //TODO: seems a bit quick and dirty 1.33 + 1.34 + public static boolean containsWKTGeometry(Literal literal){ 1.35 + return 1.36 + literal.stringValue().contains(WKTConstants.WKTPOINT)|| 1.37 + literal.stringValue().contains(WKTConstants.WKTLINESTRING)|| 1.38 + literal.stringValue().contains(WKTConstants.WKTLINEARRING)|| 1.39 + literal.stringValue().contains(WKTConstants.WKTPOLYGON)|| 1.40 + literal.stringValue().contains(WKTConstants.WKTMULTIPOINT)|| 1.41 + literal.stringValue().contains(WKTConstants.WKTMULTILINESTRING)|| 1.42 + literal.stringValue().contains(WKTConstants.WKTGEOMETRYCOLLECTION)|| 1.43 + literal.stringValue().contains(WKTConstants.WKTMULTIPOLYGON); 1.44 + } 1.45 + 1.46 /** 1.47 * Checks whether the supplied datatype is actually a GML literal. 1.48 *
2.1 --- a/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java Mon May 26 19:36:50 2014 +0300 2.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java Tue May 27 11:56:46 2014 +0300 2.3 @@ -2,8 +2,9 @@ 2.4 * This Source Code Form is subject to the terms of the Mozilla Public License, 2.5 * v. 2.0. If a copy of the MPL was not distributed with this file, You can 2.6 * obtain one at http://mozilla.org/MPL/2.0/. Copyright (C) 2010, 2011, 2012, 2.7 - * Pyravlos Team http://www.strabon.di.uoa.gr/ 2.8 + * 2013, 2014 Pyravlos Team http://www.strabon.di.uoa.gr/ 2.9 */ 2.10 + 2.11 package org.openrdf.query.resultio.sparqlkml; 2.12 2.13 import java.io.ByteArrayOutputStream; 2.14 @@ -53,6 +54,7 @@ 2.15 * @author Manos Karpathiotakis <mk@di.uoa.gr> 2.16 * @author Charalampos Nikolaou <charnik@di.uoa.gr> 2.17 * @author Panayiotis Smeros <psmeros@di.uoa.gr> 2.18 + * @author Konstantina Bereta <konstantina.bereta@di.uoa.gr> 2.19 * 2.20 */ 2.21 public class stSPARQLResultsKMLWriter implements TupleQueryResultWriter { 2.22 @@ -327,11 +329,18 @@ 2.23 String geomRep = spatial.stringValue(); 2.24 2.25 if (XMLGSDatatypeUtil.isWKTLiteral(spatial)) { // WKT 2.26 - AbstractWKT awkt = new AbstractWKT(geomRep, spatial.getDatatype().stringValue()); 2.27 - 2.28 + 2.29 + AbstractWKT awkt = null; 2.30 + if (spatial.getDatatype() == null) { // plain WKT literal 2.31 + awkt = new AbstractWKT(geomRep); 2.32 + } else { // typed WKT literal 2.33 + awkt = new AbstractWKT(geomRep, spatial.getDatatype() 2.34 + .stringValue()); 2.35 + } 2.36 + 2.37 geom = jts.WKTread(awkt.getWKT()); 2.38 srid = awkt.getSRID(); 2.39 - 2.40 + 2.41 } else { // GML 2.42 geom = jts.GMLread(geomRep); 2.43 srid = geom.getSRID();
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/vocab/src/main/java/eu/earthobservatory/constants/WKTConstants.java Tue May 27 11:56:46 2014 +0300 3.3 @@ -0,0 +1,33 @@ 3.4 +/** 3.5 + * This Source Code Form is subject to the terms of the Mozilla Public 3.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 3.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 3.8 + * 3.9 + * Copyright (C) 2014 Pyravlos Team 3.10 + * 3.11 + * http://www.strabon.di.uoa.gr/ 3.12 + */ 3.13 + 3.14 +package eu.earthobservatory.constants; 3.15 + 3.16 +/** 3.17 + * This is class contains constants that represent type of geometries 3.18 + * that can be found in a WKT literal, not necessarily compliant 3.19 + * with GeoSPARQL or strdf. This is to "catch"the cases where 3.20 + * geometries are represented using WKT literals 3.21 + * 3.22 + * @author Konstantina Bereta <konstantina.bereta@di.uoa.gr> 3.23 + */ 3.24 + 3.25 +public class WKTConstants { 3.26 + 3.27 + public static final String WKTPOINT = "POINT"; 3.28 + public static final String WKTLINESTRING = "LINESTRING"; 3.29 + public static final String WKTLINEARRING = "LINEARRING"; 3.30 + public static final String WKTPOLYGON = "POLYGON"; 3.31 + public static final String WKTMULTIPOINT = "MULTIPOINT"; 3.32 + public static final String WKTMULTILINESTRING = "MULTILINESTRING"; 3.33 + public static final String WKTMULTIPOLYGON = "MULTIPOLYGON"; 3.34 + public static final String WKTGEOMETRYCOLLECTION = "GEOMETRYCOLLECTION"; 3.35 + 3.36 +}