Strabon
changeset 1296:ee3e1f2fd710 temporals
If a variable is of type strabonExt:color it defines the fill color of the corresponding polygon
author | George Garbis <ggarbis@di.uoa.gr> |
---|---|
date | Mon Nov 18 15:38:18 2013 +0200 (2013-11-18) |
parents | c41e1b102dd3 |
children | 86466b691f5a |
files | .hgignore 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/MiscConstants.java |
line diff
1.1 --- a/.hgignore Sun Oct 20 21:25:28 2013 +0300 1.2 +++ b/.hgignore Mon Nov 18 15:38:18 2013 +0200 1.3 @@ -14,3 +14,4 @@ 1.4 stdout\.log 1.5 endpoint-client/dependency-reduced-pom\.xml 1.6 WEB-INF/faces-config.xml 1.7 +\/bin\/
2.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java Sun Oct 20 21:25:28 2013 +0300 2.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/model/XMLGSDatatypeUtil.java Mon Nov 18 15:38:18 2013 +0200 2.3 @@ -19,6 +19,7 @@ 2.4 import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron; 2.5 2.6 import eu.earthobservatory.constants.GeoConstants; 2.7 +import eu.earthobservatory.constants.MiscConstants; 2.8 import eu.earthobservatory.constants.TemporalConstants; 2.9 2.10 2.11 @@ -120,7 +121,23 @@ 2.12 } 2.13 2.14 /** 2.15 - * Checks whether the supplied datatype is actually a GML literal. 2.16 + * Checks whether the supplied datatype is actually a color literal. 2.17 + * 2.18 + * @param datatype 2.19 + * @return 2.20 + * @author George Garbis <ggarbis@di.uoa.gr> 2.21 + */ 2.22 + public static boolean isColorDatatype(URI datatype) 2.23 + { 2.24 + if(datatype == null) { 2.25 + return false; 2.26 + } 2.27 + 2.28 + return MiscConstants.color.equals(datatype.stringValue()); 2.29 + } 2.30 + 2.31 + /** 2.32 + * Checks whether the supplied datatype is actually a Period literal. 2.33 * 2.34 * @param datatype 2.35 * @return
3.1 --- a/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java Sun Oct 20 21:25:28 2013 +0300 3.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java Mon Nov 18 15:38:18 2013 +0200 3.3 @@ -9,6 +9,7 @@ 3.4 import java.io.ByteArrayOutputStream; 3.5 import java.io.IOException; 3.6 import java.io.OutputStream; 3.7 +import java.util.ArrayList; 3.8 import java.util.Hashtable; 3.9 import java.util.List; 3.10 3.11 @@ -54,6 +55,7 @@ 3.12 * @author Manos Karpathiotakis <mk@di.uoa.gr> 3.13 * @author Charalampos Nikolaou <charnik@di.uoa.gr> 3.14 * @author Panayiotis Smeros <psmeros@di.uoa.gr> 3.15 + * @author George Garbis <ggarbis@di.uoa.gr> 3.16 * 3.17 */ 3.18 public class stSPARQLResultsKMLWriter implements TupleQueryResultWriter { 3.19 @@ -63,6 +65,7 @@ 3.20 private static final String ROOT_TAG = "kml"; 3.21 private static final String NAMESPACE = "http://www.opengis.net/kml/2.2"; 3.22 private static final String RESULT_SET_TAG = "Folder"; 3.23 + private static final String DOCUMENT_TAG = "Document"; 3.24 private static final String PLACEMARK_TAG = "Placemark"; 3.25 private static final String TIMESTAMP_TAG = "TimeStamp"; 3.26 private static final String TIMESPAN_TAG = "TimeSpan"; 3.27 @@ -75,6 +78,9 @@ 3.28 private static final String DATA_TAG = "Data"; 3.29 private static final String VALUE_TAG = "value"; 3.30 private static final String NAME_ATTR = NAME_TAG; 3.31 + 3.32 + private static final String STYLE_TAG = "Style"; 3.33 + private static final String POLY_STYLE_TAG = "PolyStyle"; 3.34 3.35 private static final String TABLE_ROW_BEGIN = "<TR>"; 3.36 private static final String TABLE_ROW_END = "</TR>"; 3.37 @@ -84,6 +90,7 @@ 3.38 private static final String TABLE_DESC_BEGIN = "<![CDATA[<TABLE border=\"1\">"+ NEWLINE; 3.39 private static final String TABLE_DESC_END = "</TABLE>]]>" + NEWLINE; 3.40 3.41 + 3.42 /** 3.43 * The underlying XML formatter. 3.44 */ 3.45 @@ -133,6 +140,11 @@ 3.46 private int depth; 3.47 3.48 /** 3.49 + * List of names of predefined KML styles 3.50 + */ 3.51 + private List<String> styleNames = new ArrayList<String>(4); 3.52 + 3.53 + /** 3.54 * Creates an stSPARQLResultsKMLWriter that encodes the SPARQL results in 3.55 * KML. 3.56 * 3.57 @@ -160,18 +172,56 @@ 3.58 xmlWriter.startDocument(); 3.59 xmlWriter.setAttribute("xmlns", NAMESPACE); 3.60 xmlWriter.startTag(ROOT_TAG); 3.61 + // KML styles can be defined only in a Document element 3.62 + xmlWriter.startTag(DOCUMENT_TAG); 3.63 + 3.64 + // Add predefined KML styles 3.65 + addPolyStyle("green", true, "7700FF00", false); 3.66 + addPolyStyle("yellow", true, "7700FFFF", false); 3.67 + addPolyStyle("orange", true, "7700A5FF", false); 3.68 + addPolyStyle("red", true, "770000FF", false); 3.69 + 3.70 xmlWriter.startTag(RESULT_SET_TAG); 3.71 - 3.72 } catch (IOException e) { 3.73 throw new TupleQueryResultHandlerException(e); 3.74 } 3.75 } 3.76 + 3.77 + /** 3.78 + * Adds a new PolyStyle element to the KML output. 3.79 + * Also adds a new style to the List of style names 'styleNames' 3.80 + * 3.81 + * @param styleName 3.82 + * @param fill 3.83 + * @param color 3.84 + * @param outline 3.85 + * @throws TupleQueryResultHandlerException 3.86 + */ 3.87 + public void addPolyStyle(String styleName, boolean fill, String color, boolean outline) throws TupleQueryResultHandlerException { 3.88 + 3.89 + styleNames.add(styleName); 3.90 + 3.91 + try { 3.92 + xmlWriter.setAttribute("id", styleName); 3.93 + xmlWriter.startTag(STYLE_TAG); 3.94 + xmlWriter.startTag(POLY_STYLE_TAG); 3.95 + xmlWriter.textElement("fill", (fill?1:0)); 3.96 + xmlWriter.textElement("color", color); 3.97 + xmlWriter.textElement("outline", (outline?1:0)); 3.98 + xmlWriter.endTag(POLY_STYLE_TAG); 3.99 + xmlWriter.endTag(STYLE_TAG); 3.100 + } catch (IOException e) { 3.101 + throw new TupleQueryResultHandlerException(e); 3.102 + } 3.103 + 3.104 + } 3.105 3.106 @Override 3.107 public void endQueryResult() throws TupleQueryResultHandlerException { 3.108 try { 3.109 3.110 xmlWriter.endTag(RESULT_SET_TAG); 3.111 + xmlWriter.endTag(DOCUMENT_TAG); 3.112 xmlWriter.endTag(ROOT_TAG); 3.113 xmlWriter.endDocument(); 3.114 baos.close(); 3.115 @@ -204,7 +254,24 @@ 3.116 } 3.117 Literal literal = (Literal) binding.getValue(); 3.118 3.119 - if(XMLGSDatatypeUtil.isCalendarDatatype(literal.getDatatype())){ 3.120 + // if literal is strabonExt:color 3.121 + if (XMLGSDatatypeUtil.isColorDatatype(literal.getDatatype())) { 3.122 + // if literal contains the name of a predefined style 3.123 + if ( styleNames.contains(literal.stringValue()) ) { 3.124 + xmlWriter.textElement("styleUrl", "#"+literal.stringValue()); 3.125 + // literal should contain the hex code of a color. Accordint to 3.126 + // KML format (ABGR) 3.127 + } else { 3.128 + xmlWriter.startTag("Style"); 3.129 + xmlWriter.startTag("PolyStyle"); 3.130 + xmlWriter.textElement("fill", "1"); 3.131 + xmlWriter.textElement("color", literal.stringValue()); 3.132 + xmlWriter.textElement("outline", "0"); 3.133 + xmlWriter.endTag("PolyStyle"); 3.134 + xmlWriter.endTag("Style"); 3.135 + } 3.136 + } 3.137 + else if(XMLGSDatatypeUtil.isCalendarDatatype(literal.getDatatype())){ 3.138 hasTimestamp = true; 3.139 xmlWriter.startTag(TIMESTAMP_TAG); 3.140 xmlWriter.textElement(WHEN_TAG, literal.getLabel()); 3.141 @@ -311,7 +378,7 @@ 3.142 throw new TupleQueryResultHandlerException(e); 3.143 } 3.144 } 3.145 - 3.146 + 3.147 private String getKML(Value value) { 3.148 String kml = ""; 3.149
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/vocab/src/main/java/eu/earthobservatory/constants/MiscConstants.java Mon Nov 18 15:38:18 2013 +0200 4.3 @@ -0,0 +1,17 @@ 4.4 +package eu.earthobservatory.constants; 4.5 + 4.6 +/** 4.7 + * This class is a placeholder for various constants that cannot be attributed 4.8 + * to other categories. Currently, only the datatype strabon:kml is defined here. 4.9 + * 4.10 + * @author George Garbis <ggarbis@di.uoa.gr>*/ 4.11 + 4.12 +public class MiscConstants { 4.13 + 4.14 + /** 4.15 + * The namespace for misc constants 4.16 + */ 4.17 + public static final String miscStrabon = "http://ext.strabon.di.uoa.gr/ontology#"; 4.18 + 4.19 + public static final String color = miscStrabon + "color"; 4.20 +}