Strabon
changeset 914:a83d7023a89b
added class AbstractWKT for generalizing WKT given either in strdf:WKT or geo:wktLiteral. This class shall be used instead of WKTHelper for getting all information about WKT literals (WKT value, datatype, srid) except for the actual geometry that is handled by JTSWrapper as usual
author | Babis Nikolaou <charnik@di.uoa.gr> |
---|---|
date | Sat Mar 23 21:43:04 2013 +0200 (2013-03-23) |
parents | 15947b70dce7 |
children | e08f9275cd93 |
files | evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java Sat Mar 23 21:43:04 2013 +0200 1.3 @@ -0,0 +1,106 @@ 1.4 +/** 1.5 + * This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + * 1.9 + * Copyright (C) 2013, Pyravlos Team 1.10 + * 1.11 + * http://www.strabon.di.uoa.gr/ 1.12 + */ 1.13 +package org.openrdf.query.algebra.evaluation.function.spatial; 1.14 + 1.15 +import java.net.URI; 1.16 + 1.17 + 1.18 +/** 1.19 + * This class generalizes WKT literal values that can be given according 1.20 + * to the specification of stRDF/stSPARQL or GeoSPARQL. Notice that no 1.21 + * actual parsing is carried out, so the representation at this point 1.22 + * might not be valid. 1.23 + * 1.24 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 1.25 + */ 1.26 +public class AbstractWKT { 1.27 + 1.28 + /** 1.29 + * The datatype of this WKT literal 1.30 + * 1.31 + * Should be either {@link GeoConstants.WKT} or {@link GeoConstants.WKTLITERAL} 1.32 + */ 1.33 + private String datatype; 1.34 + 1.35 + /** 1.36 + * true when this WKT is given according to the specification of stRDF/stSPARQL 1.37 + * false when it is given according to GeoSPARQL 1.38 + */ 1.39 + private boolean isstRDFWKT; 1.40 + 1.41 + /** 1.42 + * The actual/standard WKT value as read by JTSWrapper 1.43 + */ 1.44 + private String wkt; 1.45 + 1.46 + /** 1.47 + * The SRID for the represented geometry 1.48 + */ 1.49 + private int srid; 1.50 + 1.51 + public AbstractWKT(String literalValue, String datatype) { 1.52 + this.datatype = datatype; 1.53 + 1.54 + if (GeoConstants.WKT.equals(datatype)) { // stRDF:WKT 1.55 + isstRDFWKT = true; 1.56 + parsestRDFWKT(literalValue); 1.57 + 1.58 + } else if (GeoConstants.WKTLITERAL.equals(datatype)) { // wktLiteral 1.59 + isstRDFWKT = false; 1.60 + parseWKTLITERAL(literalValue); 1.61 + 1.62 + } // naturally, whoever creates AbstractWKT instances, 1.63 + // should have either of the two datatypes, thus we don't check for errors 1.64 + } 1.65 + 1.66 + /** 1.67 + * Parses a WKT literal according to the specification of stRDF/stSPARQL. 1.68 + * The literal value may (not) specify the URI of a spatial reference system. 1.69 + * 1.70 + * @param literalValue 1.71 + */ 1.72 + private void parsestRDFWKT(String literalValue) { 1.73 + // we already have this case in {@link WKTHelper} 1.74 + wkt = WKTHelper.getWithoutSRID(literalValue); 1.75 + srid = WKTHelper.getSRID(literalValue); 1.76 + } 1.77 + 1.78 + private void parseWKTLITERAL(String literalValue) { 1.79 + String wkt = literalValue.trim(); 1.80 + // FIXME: the default value for wktLiteral 1.81 + //srid = ; 1.82 + 1.83 + if (wkt.charAt(0) == '<') {// if a CRS URI is specified 1.84 + int uriIndx = wkt.indexOf('>'); 1.85 + URI crs = URI.create(wkt.substring(1, uriIndx)); 1.86 + 1.87 + // FIXME: get the SRID for crs! HOW?? 1.88 + 1.89 + // trim spaces after URI and get the WKT value 1.90 + wkt = wkt.substring(uriIndx + 1).trim(); 1.91 + } 1.92 + } 1.93 + 1.94 + public String getWKT() { 1.95 + return wkt; 1.96 + } 1.97 + 1.98 + public int getSRID() { 1.99 + return srid; 1.100 + } 1.101 + 1.102 + public String getDatatype() { 1.103 + return datatype; 1.104 + } 1.105 + 1.106 + boolean isstRDFWKT() { 1.107 + return isstRDFWKT; 1.108 + } 1.109 +}
2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Sat Mar 23 21:40:03 2013 +0200 2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java Sat Mar 23 21:43:04 2013 +0200 2.3 @@ -198,7 +198,7 @@ 2.4 } 2.5 2.6 //the new version will actually deal with WKB 2.7 - public void insertWKT(Number id, String label, String datatype,Timestamp start,Timestamp end) throws SQLException, NullPointerException,InterruptedException,IllegalArgumentException 2.8 + public void insertWKT(Number id, String label, String datatype, Timestamp start,Timestamp end) throws SQLException, NullPointerException,InterruptedException,IllegalArgumentException 2.9 { 2.10 try { 2.11 Geometry geom = JTSWrapper.getInstance().WKTread(label);