Strabon

changeset 1155:1f72d6d553bc

Reverted some old changes that were trying to fix the kml-visualization bug. Now this is not a bug. We have sextant!
author Panayiotis Smeros <psmeros@di.uoa.gr>
date Wed May 08 19:18:23 2013 +0300 (2013-05-08)
parents 5a954ddd0a91
children 355ab4e7cf59
files resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java
line diff
     1.1 --- a/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Sat May 04 14:32:22 2013 +0300
     1.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Wed May 08 19:18:23 2013 +0300
     1.3 @@ -9,7 +9,6 @@
     1.4  import java.io.ByteArrayOutputStream;
     1.5  import java.io.IOException;
     1.6  import java.io.OutputStream;
     1.7 -import java.util.ArrayList;
     1.8  import java.util.Hashtable;
     1.9  import java.util.List;
    1.10  
    1.11 @@ -77,9 +76,6 @@
    1.12  	private static final String TABLE_DESC_BEGIN 		= "<![CDATA[<TABLE border=\"1\">"+ NEWLINE;
    1.13  	private static final String TABLE_DESC_END 		= "</TABLE>]]>" + NEWLINE;
    1.14  
    1.15 -	private static final String GEOMETRY_NAME 		= "Geometry";
    1.16 -	private static final String MULTIGEOMETRY 		= "MultiGeometry";
    1.17 -
    1.18  	/**
    1.19  	 * The underlying XML formatter.
    1.20  	 */
    1.21 @@ -91,9 +87,9 @@
    1.22  	private int nresults;
    1.23  
    1.24  	/**
    1.25 -	 * The number of geometries seen.
    1.26 +	 * True if results have at least one geometry.
    1.27  	 */
    1.28 -	private int ngeometries;
    1.29 +	private Boolean hasGeometry;
    1.30  
    1.31  	/**
    1.32  	 * The JTS wrapper
    1.33 @@ -140,7 +136,7 @@
    1.34  		descHeader = new StringBuilder();
    1.35  		descData = new StringBuilder();
    1.36  		nresults = 0;
    1.37 -		ngeometries = 0;
    1.38 +		hasGeometry=false;
    1.39  	}
    1.40  
    1.41  	@Override
    1.42 @@ -165,7 +161,7 @@
    1.43  			xmlWriter.endDocument();
    1.44  			baos.close();
    1.45  			
    1.46 -			if (ngeometries < nresults) {
    1.47 +			if (!hasGeometry) {
    1.48  				logger.warn("[Strabon.KMLWriter] No spatial binding found in the result. KML requires that at least one binding maps to a geometry.", nresults);
    1.49  			}
    1.50  			
    1.51 @@ -177,22 +173,15 @@
    1.52  	@Override
    1.53  	public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
    1.54  		try {
    1.55 -			int numOfGeometries = 0;
    1.56 -
    1.57  			// true if there are bindings that do not correspond to geometries
    1.58  			boolean hasDesc = false;
    1.59 -
    1.60 -			// increase result size
    1.61 -			nresults++;
    1.62 -
    1.63 -			// create description table and header
    1.64 -			indent(descHeader, depth);
    1.65 -			descHeader.append(TABLE_DESC_BEGIN);
    1.66 -			indent(descHeader, depth);
    1.67  			
    1.68 -			List<String> geometries = new ArrayList<String>();
    1.69  			Hashtable<String, String> extData = new Hashtable<String, String>();
    1.70  
    1.71 +			// write placemark tag
    1.72 +			xmlWriter.startTag(PLACEMARK_TAG);
    1.73 +			xmlWriter.textElement(NAME_TAG, "Result" + nresults);
    1.74 +			
    1.75  			// parse binding set
    1.76  			for (Binding binding : bindingSet) {
    1.77  
    1.78 @@ -200,13 +189,13 @@
    1.79  				
    1.80  				// check for geometry value
    1.81  				if (XMLGSDatatypeUtil.isGeometryValue(value)) {
    1.82 -					numOfGeometries++;
    1.83 -					ngeometries++;
    1.84 +					hasGeometry=true;
    1.85 +
    1.86  					if (logger.isDebugEnabled()) {
    1.87  						logger.debug("[Strabon] Found geometry: {}", value);
    1.88  					}
    1.89  					
    1.90 -					geometries.add(getGeometry(value));
    1.91 +					xmlWriter.unescapedText(getKML(value));
    1.92  					
    1.93  				} else { // URI, BlankNode, or Literal other than spatial literal
    1.94  					if (logger.isDebugEnabled()) {
    1.95 @@ -224,34 +213,15 @@
    1.96  				}
    1.97  			}
    1.98  			
    1.99 -			if (numOfGeometries > 1) {
   1.100 -				// write each polygon in separate placemarks
   1.101 -				for (String geometry : geometries) {
   1.102 -					xmlWriter.startTag(PLACEMARK_TAG);
   1.103 -					xmlWriter.textElement(NAME_TAG, GEOMETRY_NAME);
   1.104 -					xmlWriter.startTag(MULTIGEOMETRY);
   1.105 -					xmlWriter.unescapedText(geometry);
   1.106 -					xmlWriter.endTag(MULTIGEOMETRY);
   1.107 -					xmlWriter.endTag(PLACEMARK_TAG);
   1.108 -				}
   1.109 -			}
   1.110 -			
   1.111 -			// also write them in the same placemarks
   1.112 -			xmlWriter.startTag(PLACEMARK_TAG);
   1.113 -			xmlWriter.textElement(NAME_TAG, GEOMETRY_NAME);
   1.114 -			xmlWriter.startTag(MULTIGEOMETRY);
   1.115 -			
   1.116 -			for (String geometry : geometries) {
   1.117 -				xmlWriter.unescapedText(geometry);
   1.118 -			}
   1.119 -			
   1.120 -			xmlWriter.endTag(MULTIGEOMETRY);
   1.121  			
   1.122  			// we have found and constructed a description for this result.
   1.123  			// Write it down.
   1.124  			if (hasDesc) {
   1.125 -				// end the placeholder for the description data
   1.126 -				indent(descData, depth);
   1.127 +				
   1.128 +				// create description table and header
   1.129 +				indent(descHeader, depth);
   1.130 +				descHeader.append(TABLE_DESC_BEGIN);
   1.131 +				indent(descHeader, depth);
   1.132  				
   1.133  				// append to the table header the actual content from
   1.134  				// the bindings
   1.135 @@ -290,14 +260,17 @@
   1.136  			// clear description string builders
   1.137  			descHeader.setLength(0);
   1.138  			descData.setLength(0);
   1.139 +		
   1.140 +			// increase result size
   1.141 +			nresults++;
   1.142  			
   1.143  		} catch (IOException e) {
   1.144  			throw new TupleQueryResultHandlerException(e);
   1.145  		}
   1.146  	}
   1.147  
   1.148 -	private String getGeometry(Value value) {
   1.149 -		String geometry = "";
   1.150 +	private String getKML(Value value) {
   1.151 +		String kml = "";
   1.152  		
   1.153  		QName geometryType = null;
   1.154  		
   1.155 @@ -366,34 +339,8 @@
   1.156  				
   1.157  			} else {
   1.158  				encoder.encode(geom, geometryType, baos);
   1.159 -				geometry = baos.toString().substring(38).replaceAll(" xmlns:kml=\"http://earth.google.com/kml/2.1\"", "").replaceAll("kml:", "");
   1.160 +				kml = baos.toString().substring(38).replaceAll(" xmlns:kml=\"http://earth.google.com/kml/2.1\"", "").replaceAll("kml:", "");
   1.161  
   1.162 -				/*
   1.163 -				if (geometryType == KML.MultiGeometry) {
   1.164 -					geometry = geometry.substring(geometry.indexOf("<MultiGeometry>") + 15,	geometry.indexOf("</MultiGeometry>"));
   1.165 -				}
   1.166 -				 * if(geom instanceof Point) { geometry =
   1.167 -				 * geometry.substring(geometry.indexOf("<Point>"),
   1.168 -				 * geometry.indexOf("</Point>") + 8); } else if(geom instanceof
   1.169 -				 * Polygon) { geometry =
   1.170 -				 * geometry.substring(geometry.indexOf("<Polygon>"),
   1.171 -				 * geometry.indexOf("</Polygon>") + 10); } else if(geom
   1.172 -				 * instanceof LineString) { geometry =
   1.173 -				 * geometry.substring(geometry.indexOf("<LineString>"),
   1.174 -				 * geometry.indexOf("</LineString>") + 13); } else if(geom
   1.175 -				 * instanceof MultiPoint) { geometry =
   1.176 -				 * geometry.substring(geometry.indexOf("<MultiPoint>"),
   1.177 -				 * geometry.indexOf("</MultiPoint>") + 13); } else if(geom
   1.178 -				 * instanceof MultiLineString) { geometry =
   1.179 -				 * geometry.substring(geometry.indexOf("<MultiLineString>"),
   1.180 -				 * geometry.indexOf("</MultiLineString>") + 18); } else if(geom
   1.181 -				 * instanceof MultiPolygon) { geometry =
   1.182 -				 * geometry.substring(geometry.indexOf("<MultiPolygon>"),
   1.183 -				 * geometry.indexOf("</MultiPolygon>") + 15); } else if(geom
   1.184 -				 * instanceof GeometryCollection) { geometry =
   1.185 -				 * geometry.substring(geometry.indexOf("<GeometryCollection>"),
   1.186 -				 * geometry.indexOf("</GeometryCollection>") + 21); }
   1.187 -				 */
   1.188  				baos.reset();
   1.189  			}
   1.190  		} catch (ParseException e) {
   1.191 @@ -406,7 +353,7 @@
   1.192  			logger.error("[Strabon.KMLWriter] Exception during GML parsing: {}", e.getMessage());
   1.193  		}
   1.194  		
   1.195 -		return geometry;
   1.196 +		return kml;
   1.197  	}
   1.198  
   1.199  	/**