Strabon

changeset 630:206d8add2a85

#kmlwriter
Show on map (locahost) with one geometry variable should now work. (DLR queries)

The problem comes when one geometry overlaps with another.
For example:
We have geometry variables X and Y and geometries A, B and C.
The bindings are:
X=A, Y=B
X=A, Y=C

When I go over B, A is also highlighted. When I go over C, A is also highlighted. But what should be highlighted when I go over A?
B? C? Both?

If the answer is B or C we lose a “connection”.
If the answer is both, it is wrong, because A, B and C are not in the same binding set.

Maybe we have to change the way we show the connection among the geometries.
author Panayiotis Smeros <psmeros@di.uoa.gr>
date Tue Oct 09 19:38:44 2012 +0300 (2012-10-09)
parents e6d414360f33
children ce990d2f0155
files resultio/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java
line diff
     1.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Mon Oct 08 22:29:21 2012 +0300
     1.2 +++ b/resultio/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Tue Oct 09 19:38:44 2012 +0300
     1.3 @@ -47,100 +47,88 @@
     1.4   * @author Manos Karpathiotakis <mk@di.uoa.gr>
     1.5   * @author Charalampos Nikolaou <charnik@di.uoa.gr>
     1.6   * @author Panayiotis Smeros <psmeros@di.uoa.gr>
     1.7 - *
     1.8 + * 
     1.9   */
    1.10  public class stSPARQLResultsKMLWriter implements TupleQueryResultWriter
    1.11  {
    1.12  	private static final Logger logger = LoggerFactory.getLogger(org.openrdf.query.resultio.sparqlkml.stSPARQLResultsKMLWriter.class);
    1.13 -	private static final String ROOT_TAG 			= "kml";
    1.14 -	private static final String NAMESPACE 			= "http://www.opengis.net/kml/2.2";
    1.15 -	private static final String RESULT_SET_TAG 		= "Folder";
    1.16 -	private static final String PLACEMARK_TAG 		= "Placemark";
    1.17 -	private static final String NAME_TAG 			= "name";
    1.18 -	private static final String DESC_TAG 			= "description";
    1.19 -	private static final String STYLE_TAG 			= "Style";
    1.20 -	private static final String STYLEMAP_TAG 		= "StyleMap";
    1.21 -	private static final String LINESTYLE_TAG 		= "LineStyle";
    1.22 -	private static final String POLYSTYLE_TAG 		= "PolyStyle";
    1.23 -	private static final String STYLE_ID 			= "resultStyle";
    1.24 -	private static final String TABLE_ROW_BEGIN 	= "<TR>";
    1.25 -	private static final String TABLE_ROW_END 		= "</TR>";
    1.26 -	private static final String TABLE_DATA_BEGIN 	= "<TD>";
    1.27 -	private static final String TABLE_DATA_END 		= "</TD>";
    1.28 -	private static final String NEWLINE 			= "\n";
    1.29 -	private static final String TABLE_DESC_BEGIN 	= "<![CDATA[<TABLE border=\"1\">" + NEWLINE;
    1.30 -	private static final String TABLE_DESC_END 		= "</TABLE>]]>" + NEWLINE;
    1.31 -	private static final String GEOMETRY_NAME 		= "Geometry";
    1.32 -	private static final String MULTIGEOMETRY 		= "MultiGeometry";
    1.33 -	
    1.34 +	private static final String ROOT_TAG = "kml";
    1.35 +	private static final String NAMESPACE = "http://www.opengis.net/kml/2.2";
    1.36 +	private static final String RESULT_SET_TAG = "Folder";
    1.37 +	private static final String PLACEMARK_TAG = "Placemark";
    1.38 +	private static final String NAME_TAG = "name";
    1.39 +	private static final String DESC_TAG = "description";
    1.40 +	private static final String STYLE_TAG = "Style";
    1.41 +	private static final String STYLEMAP_TAG = "StyleMap";
    1.42 +	private static final String LINESTYLE_TAG = "LineStyle";
    1.43 +	private static final String POLYSTYLE_TAG = "PolyStyle";
    1.44 +	private static final String STYLE_ID = "resultStyle";
    1.45 +	private static final String TABLE_ROW_BEGIN = "<TR>";
    1.46 +	private static final String TABLE_ROW_END = "</TR>";
    1.47 +	private static final String TABLE_DATA_BEGIN = "<TD>";
    1.48 +	private static final String TABLE_DATA_END = "</TD>";
    1.49 +	private static final String NEWLINE = "\n";
    1.50 +	private static final String TABLE_DESC_BEGIN = "<![CDATA[<TABLE border=\"1\">" + NEWLINE;
    1.51 +	private static final String TABLE_DESC_END = "</TABLE>]]>" + NEWLINE;
    1.52 +	private static final String GEOMETRY_NAME = "Geometry";
    1.53 +	private static final String MULTIGEOMETRY = "MultiGeometry";
    1.54  	// Styling options
    1.55 -	private static final int numOfStyles 			= 5;
    1.56 -	
    1.57 +	private static final int numOfStyles = 5;
    1.58  	private static final String[][] styles = {
    1.59  		// note that colors are encoded as "aabbggrr" strings where
    1.60 -		// aa=alpha (00 to ff); bb=blue (00 to ff); gg=green (00 to ff); rr=red
    1.61 +		// aa=alpha (00 to ff); bb=blue (00 to ff); gg=green (00 to ff);
    1.62 +		// rr=red
    1.63  		// (00 to ff).
    1.64  		// id, line width, line color, polygon fill, mouse over line width,
    1.65  		// mouse over line color mouse over polygon fill
    1.66 -		{STYLE_ID + "1", "1.5", "7dff0000", "adff0000", "1.5", "7d0000ff", "ad0000ff"}, 
    1.67 -		{STYLE_ID + "2", "1.5", "7d00ff00", "ad00ff00", "1.5", "7d0000ff", "ad0000ff"}, 
    1.68 -		{STYLE_ID + "3", "1.5", "7d550000", "ad550000", "1.5", "7d0000ff", "ad0000ff"}, 
    1.69 -		{STYLE_ID + "4", "1.5", "7d005500", "ad005500", "1.5", "7d0000ff", "ad0000ff"}, 
    1.70 -		{STYLE_ID + "5", "1.5", "7d000055", "ad000055", "1.5", "7d0000ff", "ad0000ff"}};
    1.71 -
    1.72 +	{STYLE_ID + "1", "1.5", "7dff0000", "adff0000", "1.5", "7d0000ff", "ad0000ff"}, {STYLE_ID + "2", "1.5", "7d00ff00", "ad00ff00", "1.5", "7d0000ff", "ad0000ff"}, {STYLE_ID + "3", "1.5", "7d550000", "ad550000", "1.5", "7d0000ff", "ad0000ff"}, {STYLE_ID + "4", "1.5", "7d005500", "ad005500", "1.5", "7d0000ff", "ad0000ff"}, {STYLE_ID + "5", "1.5", "7d000055", "ad000055", "1.5", "7d0000ff", "ad0000ff"}};
    1.73  	/**
    1.74  	 * The underlying XML formatter.
    1.75  	 */
    1.76  	private stSPARQLXMLWriter xmlWriter;
    1.77 -	
    1.78  	/**
    1.79  	 * The number of results seen.
    1.80  	 */
    1.81  	private int nresults;
    1.82 -	
    1.83  	/**
    1.84  	 * The number of geometries seen.
    1.85  	 */
    1.86  	private int ngeometries;
    1.87 -	
    1.88  	/**
    1.89  	 * The JTS wrapper
    1.90  	 */
    1.91  	private JTSWrapper jts;
    1.92 -	
    1.93  	/**
    1.94  	 * Stream for manipulating geometries
    1.95  	 */
    1.96  	private ByteArrayOutputStream baos;
    1.97 -	
    1.98  	/**
    1.99 -	 * Description string holding the projected variables
   1.100 -	 * of the SPARQL query
   1.101 +	 * Description string holding the projected variables of the SPARQL query
   1.102  	 */
   1.103  	private StringBuilder descHeader;
   1.104 -	
   1.105  	/**
   1.106 -	 * Description string holding the values for the
   1.107 -	 * projected variables of the SPARQL query
   1.108 +	 * Description string holding the values for the projected variables of the
   1.109 +	 * SPARQL query
   1.110  	 */
   1.111  	private StringBuilder descData;
   1.112 -	
   1.113  	/**
   1.114  	 * Indentation used in tags that are constructed manually
   1.115  	 */
   1.116  	private int depth;
   1.117  
   1.118  	/**
   1.119 -	 * Creates an stSPARQLResultsKMLWriter that encodes the SPARQL
   1.120 -	 * results in KML.
   1.121 +	 * Creates an stSPARQLResultsKMLWriter that encodes the SPARQL results in
   1.122 +	 * KML.
   1.123  	 * 
   1.124  	 * @param out
   1.125  	 */
   1.126 -	public stSPARQLResultsKMLWriter(OutputStream out) {
   1.127 -		this (new stSPARQLXMLWriter(out));
   1.128 +	public stSPARQLResultsKMLWriter(OutputStream out)
   1.129 +	{
   1.130 +		this(new stSPARQLXMLWriter(out));
   1.131  	}
   1.132  
   1.133 -	public stSPARQLResultsKMLWriter(stSPARQLXMLWriter writer) {
   1.134 +	public stSPARQLResultsKMLWriter(stSPARQLXMLWriter writer)
   1.135 +	{
   1.136  		xmlWriter = writer;
   1.137  		xmlWriter.setPrettyPrint(true);
   1.138  		depth = 4;
   1.139 @@ -152,15 +140,17 @@
   1.140  		ngeometries = 0;
   1.141  	}
   1.142  
   1.143 -	@Override
   1.144 -	public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException {
   1.145 -		try {
   1.146 +	@Override public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException
   1.147 +	{
   1.148 +		try
   1.149 +		{
   1.150  			xmlWriter.startDocument();
   1.151  			xmlWriter.setAttribute("xmlns", NAMESPACE);
   1.152  			xmlWriter.startTag(ROOT_TAG);
   1.153  			xmlWriter.startTag(RESULT_SET_TAG);
   1.154  			// add default styles
   1.155 -			for (String[] style: styles) {
   1.156 +			for(String[] style: styles)
   1.157 +			{
   1.158  				String id = style[0];
   1.159  				String lineWidth = style[1];
   1.160  				String lineColor = style[2];
   1.161 @@ -168,7 +158,7 @@
   1.162  				String mouseOverLineWidth = style[4];
   1.163  				String mouseOverLineColor = style[5];
   1.164  				String mouseOverPolygonFill = style[6];
   1.165 -				//append normal style
   1.166 +				// append normal style
   1.167  				xmlWriter.setAttribute("id", "normal_" + id);
   1.168  				xmlWriter.startTag(STYLE_TAG);
   1.169  				xmlWriter.startTag(LINESTYLE_TAG);
   1.170 @@ -179,7 +169,7 @@
   1.171  				xmlWriter.textElement("color", polygonFill);
   1.172  				xmlWriter.endTag(POLYSTYLE_TAG);
   1.173  				xmlWriter.endTag(STYLE_TAG);
   1.174 -				//append highlight style
   1.175 +				// append highlight style
   1.176  				xmlWriter.setAttribute("id", "highlight_" + id);
   1.177  				xmlWriter.startTag(STYLE_TAG);
   1.178  				xmlWriter.startTag(LINESTYLE_TAG);
   1.179 @@ -190,7 +180,7 @@
   1.180  				xmlWriter.textElement("color", mouseOverPolygonFill);
   1.181  				xmlWriter.endTag(POLYSTYLE_TAG);
   1.182  				xmlWriter.endTag(STYLE_TAG);
   1.183 -				//define map style combining the above styles
   1.184 +				// define map style combining the above styles
   1.185  				xmlWriter.setAttribute("id", id);
   1.186  				xmlWriter.startTag(STYLEMAP_TAG);
   1.187  				xmlWriter.startTag("Pair");
   1.188 @@ -204,226 +194,252 @@
   1.189  				xmlWriter.endTag(STYLEMAP_TAG);
   1.190  			}
   1.191  			// end of default style definition
   1.192 -			
   1.193 -		} catch (IOException e) {
   1.194 +		}
   1.195 +		catch(IOException e)
   1.196 +		{
   1.197  			throw new TupleQueryResultHandlerException(e);
   1.198  		}
   1.199  	}
   1.200  
   1.201 -	@Override
   1.202 -	public void endQueryResult() throws TupleQueryResultHandlerException {
   1.203 -		try {
   1.204 +	@Override public void endQueryResult() throws TupleQueryResultHandlerException
   1.205 +	{
   1.206 +		try
   1.207 +		{
   1.208  			xmlWriter.endTag(RESULT_SET_TAG);
   1.209  			xmlWriter.endTag(ROOT_TAG);
   1.210  			xmlWriter.endDocument();
   1.211  			baos.close();
   1.212 -			
   1.213 -			if (ngeometries < nresults) {
   1.214 +			if(ngeometries < nresults)
   1.215 +			{
   1.216  				logger.warn("[Strabon.KMLWriter] No spatial binding found in the result. KML requires that at least one binding maps to a geometry.", nresults);
   1.217  			}
   1.218 -		} catch (IOException e) {
   1.219 +		}
   1.220 +		catch(IOException e)
   1.221 +		{
   1.222  			throw new TupleQueryResultHandlerException(e);
   1.223  		}
   1.224  	}
   1.225  
   1.226 -	@Override
   1.227 -	public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException {
   1.228 -		try {
   1.229 +	@Override public void handleSolution(BindingSet bindingSet) throws TupleQueryResultHandlerException
   1.230 +	{
   1.231 +		try
   1.232 +		{
   1.233 +			int numOfGeometries=0;
   1.234  			// true if there are bindings that do not correspond to geometries
   1.235  			boolean hasDesc = false;
   1.236 -			
   1.237  			// increase result size
   1.238  			nresults++;
   1.239 -			
   1.240  			// create description table and header
   1.241  			indent(descHeader, depth);
   1.242  			descHeader.append(TABLE_DESC_BEGIN);
   1.243  			indent(descHeader, depth);
   1.244 -			
   1.245 -			List<String> polygons = new ArrayList<String>();
   1.246 -			
   1.247 +			List<String> geometries = new ArrayList<String>();
   1.248  			// parse binding set
   1.249 -			for (Binding binding: bindingSet) {
   1.250 +			for(Binding binding: bindingSet)
   1.251 +			{
   1.252  				Value value = binding.getValue();
   1.253  				// check for geometry value
   1.254 -				if (XMLGSDatatypeUtil.isGeometryValue(value)) {
   1.255 +				if(XMLGSDatatypeUtil.isGeometryValue(value))
   1.256 +				{
   1.257 +					numOfGeometries++;
   1.258  					ngeometries++;
   1.259 -					if (logger.isDebugEnabled()) {
   1.260 +					if(logger.isDebugEnabled())
   1.261 +					{
   1.262  						logger.debug("[Strabon] Found geometry: {}", value);
   1.263  					}
   1.264 -					polygons.add(getPolygon(value));
   1.265 -					
   1.266 -				} else { // URI, BlankNode, or Literal other than spatial literal
   1.267 -					if (logger.isDebugEnabled()) {
   1.268 +					geometries.add(getGeometry(value));
   1.269 +				}
   1.270 +				else
   1.271 +				{ // URI, BlankNode, or Literal other than spatial
   1.272 +					// literal
   1.273 +					if(logger.isDebugEnabled())
   1.274 +					{
   1.275  						logger.debug("[Strabon.KMLWriter] Found URI/BlankNode/Literal ({}): {}", value.getClass(), value);
   1.276  					}
   1.277 -					
   1.278  					// mark that we found sth corresponding to the description
   1.279  					hasDesc = true;
   1.280 -					
   1.281  					// write description
   1.282  					writeDesc(binding);
   1.283  				}
   1.284  			}
   1.285 -			
   1.286 -			// write each polygon in separate placemarks
   1.287 -			for (String polygon : polygons) {
   1.288 -				xmlWriter.startTag(PLACEMARK_TAG);			
   1.289 -				xmlWriter.textElement("styleUrl", "#" + styles[polygons.indexOf(polygon)%(numOfStyles-2)][0]);
   1.290 -
   1.291 -				xmlWriter.startTag(MULTIGEOMETRY);
   1.292 -				xmlWriter.unescapedText(polygon);
   1.293 -				xmlWriter.endTag(MULTIGEOMETRY);
   1.294 -				
   1.295 -				xmlWriter.endTag(PLACEMARK_TAG);
   1.296 +			if(numOfGeometries > 1)
   1.297 +			{
   1.298 +				// write each polygon in separate placemarks
   1.299 +				for(String geometry: geometries)
   1.300 +				{
   1.301 +					xmlWriter.startTag(PLACEMARK_TAG);
   1.302 +					xmlWriter.textElement(NAME_TAG, GEOMETRY_NAME);
   1.303 +					xmlWriter.textElement("styleUrl", "#" + styles[geometries.indexOf(geometry) % (numOfStyles - 2)][0]);
   1.304 +					xmlWriter.startTag(MULTIGEOMETRY);
   1.305 +					xmlWriter.unescapedText(geometry);
   1.306 +					xmlWriter.endTag(MULTIGEOMETRY);
   1.307 +					xmlWriter.endTag(PLACEMARK_TAG);
   1.308 +				}
   1.309  			}
   1.310 -			
   1.311 -			//also write them in the same placemarks
   1.312 -			
   1.313 +			// also write them in the same placemarks
   1.314  			xmlWriter.startTag(PLACEMARK_TAG);
   1.315  			xmlWriter.textElement(NAME_TAG, GEOMETRY_NAME);
   1.316 -			xmlWriter.textElement("styleUrl", "#" + styles[(numOfStyles-1)][0]);
   1.317 -			
   1.318 +			xmlWriter.textElement("styleUrl", "#" + styles[(numOfStyles - 1)][0]);
   1.319  			xmlWriter.startTag(MULTIGEOMETRY);
   1.320 -			for(String polygon : polygons) {
   1.321 -				xmlWriter.unescapedText(polygon);
   1.322 +			for(String geometry: geometries)
   1.323 +			{
   1.324 +				xmlWriter.unescapedText(geometry);
   1.325  			}
   1.326  			xmlWriter.endTag(MULTIGEOMETRY);
   1.327 -			
   1.328  			// we have found and constructed a description for this result.
   1.329  			// Write it down.
   1.330 -			if (hasDesc) {
   1.331 +			if(hasDesc)
   1.332 +			{
   1.333  				// end the placeholder for the description data
   1.334  				indent(descData, depth);
   1.335 -				
   1.336  				// append to the table header the actual content from
   1.337  				// the bindings
   1.338  				descHeader.append(descData);
   1.339 -				
   1.340  				// close the table for the description
   1.341  				descHeader.append(NEWLINE);
   1.342  				indent(descHeader, depth);
   1.343  				descHeader.append(TABLE_DESC_END);
   1.344 -				
   1.345  				// begin the "description" tag
   1.346  				xmlWriter.startTag(DESC_TAG);
   1.347 -				
   1.348  				// write the actual description
   1.349  				xmlWriter.unescapedText(descHeader.toString());
   1.350 -				
   1.351  				// end the "description" tag
   1.352  				xmlWriter.endTag(DESC_TAG);
   1.353  			}
   1.354  			// clear description string builders
   1.355  			descHeader.setLength(0);
   1.356  			descData.setLength(0);
   1.357 -
   1.358  			xmlWriter.endTag(PLACEMARK_TAG);
   1.359 -			
   1.360 -		} catch (IOException e) {
   1.361 +		}
   1.362 +		catch(IOException e)
   1.363 +		{
   1.364  			throw new TupleQueryResultHandlerException(e);
   1.365  		}
   1.366  	}
   1.367  
   1.368 -	private String getPolygon(Value value) {
   1.369 -		String polygon = "";
   1.370 +	private String getGeometry(Value value)
   1.371 +	{
   1.372 +		String geometry = "";
   1.373  		QName geometryType = null;
   1.374 -		
   1.375  		// the underlying geometry in value
   1.376  		Geometry geom = null;
   1.377 -		
   1.378  		// the underlying SRID of the geometry
   1.379  		int srid = -1;
   1.380 -		
   1.381  		// get the KML encoder
   1.382  		Encoder encoder = null;
   1.383 -		
   1.384 -		try {
   1.385 +		try
   1.386 +		{
   1.387  			encoder = new Encoder(new KMLConfiguration());
   1.388  			encoder.setIndenting(true);
   1.389 -			
   1.390 -			if (value instanceof GeneralDBPolyhedron) {
   1.391 +			if(value instanceof GeneralDBPolyhedron)
   1.392 +			{
   1.393  				GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) value;
   1.394  				geom = dbpolyhedron.getPolyhedron().getGeometry();
   1.395  				srid = dbpolyhedron.getPolyhedron().getGeometry().getSRID();
   1.396 -				
   1.397 -			} else { // spatial literal
   1.398 +			}
   1.399 +			else
   1.400 +			{ // spatial literal
   1.401  				Literal spatial = (Literal) value;
   1.402  				String geomRep = spatial.stringValue();
   1.403 -				
   1.404 -				if (XMLGSDatatypeUtil.isWKTLiteral(spatial)) { // WKT
   1.405 +				if(XMLGSDatatypeUtil.isWKTLiteral(spatial))
   1.406 +				{ // WKT
   1.407  					geom = jts.WKTread(WKTHelper.getWithoutSRID(geomRep));
   1.408  					srid = WKTHelper.getSRID(geomRep);
   1.409 -				} else { // GML
   1.410 +				}
   1.411 +				else
   1.412 +				{ // GML
   1.413  					geom = jts.GMLread(geomRep);
   1.414  					srid = geom.getSRID();
   1.415  				}
   1.416  			}
   1.417 -
   1.418  			// transform the geometry to {@link GeoConstants#defaultSRID}
   1.419  			geom = jts.transform(geom, srid, GeoConstants.defaultSRID);
   1.420 -			if (geom instanceof Point) {
   1.421 +			if(geom instanceof Point)
   1.422 +			{
   1.423  				geometryType = KML.Point;
   1.424 -				
   1.425 -			} else if (geom instanceof Polygon) {
   1.426 +			}
   1.427 +			else if(geom instanceof Polygon)
   1.428 +			{
   1.429  				geometryType = KML.Polygon;
   1.430 -				
   1.431 -			} else if (geom instanceof LineString) {
   1.432 +			}
   1.433 +			else if(geom instanceof LineString)
   1.434 +			{
   1.435  				geometryType = KML.LineString;
   1.436 -				
   1.437 -			} else if (geom instanceof MultiPoint) {
   1.438 -				geometryType = KML.MultiGeometry;
   1.439 -				
   1.440 -			} else if (geom instanceof MultiLineString) {
   1.441 -				geometryType = KML.MultiGeometry;
   1.442 -				
   1.443 -			} else if (geom instanceof MultiPolygon) {
   1.444 -				geometryType = KML.MultiGeometry;
   1.445 -				
   1.446 -			} else if (geom instanceof GeometryCollection) {
   1.447 +			}
   1.448 +			else if(geom instanceof MultiPoint)
   1.449 +			{
   1.450  				geometryType = KML.MultiGeometry;
   1.451  			}
   1.452 -			
   1.453 -			if (geometryType == null) {
   1.454 +			else if(geom instanceof MultiLineString)
   1.455 +			{
   1.456 +				geometryType = KML.MultiGeometry;
   1.457 +			}
   1.458 +			else if(geom instanceof MultiPolygon)
   1.459 +			{
   1.460 +				geometryType = KML.MultiGeometry;
   1.461 +			}
   1.462 +			else if(geom instanceof GeometryCollection)
   1.463 +			{
   1.464 +				geometryType = KML.MultiGeometry;
   1.465 +			}
   1.466 +			if(geometryType == null)
   1.467 +			{
   1.468  				logger.warn("[Strabon.KMLWriter] Found unknown geometry type.");
   1.469 -				
   1.470 -			} else {
   1.471 +			}
   1.472 +			else
   1.473 +			{
   1.474  				encoder.encode(geom, geometryType, baos);
   1.475 -				polygon = baos.toString().substring(38).replaceAll(" xmlns:kml=\"http://earth.google.com/kml/2.1\"", "").replaceAll("kml:", "");
   1.476 -				
   1.477 -				// get the polygon from the kml
   1.478 -				//FIXME: test
   1.479 -				//polygon = polygon.substring(polygon.indexOf("<Polygon>"), polygon.indexOf("</Polygon>")+10);
   1.480 -				if (geom instanceof Point) {
   1.481 -					polygon = polygon.substring(polygon.indexOf("<Point>"), polygon.indexOf("</Point>")+8);
   1.482 -				} else if (geom instanceof Polygon) {
   1.483 -					polygon = polygon.substring(polygon.indexOf("<Polygon>"), polygon.indexOf("</Polygon>")+10);
   1.484 -				} else if (geom instanceof LineString) {
   1.485 -					polygon = polygon.substring(polygon.indexOf("<LineString>"), polygon.indexOf("</LineString>")+13);
   1.486 -				} else if (geom instanceof MultiPoint) {
   1.487 -					polygon = polygon.substring(polygon.indexOf("<MultiPoint>"), polygon.indexOf("</MultiPoint>")+13);
   1.488 -				} else if (geom instanceof MultiLineString) {
   1.489 -					polygon = polygon.substring(polygon.indexOf("<MultiLineString>"), polygon.indexOf("</MultiLineString>")+18);
   1.490 -				} else if (geom instanceof MultiPolygon) {
   1.491 -					polygon = polygon.substring(polygon.indexOf("<MultiPolygon>"), polygon.indexOf("</MultiPolygon>")+15);
   1.492 -				} else if (geom instanceof GeometryCollection) {
   1.493 -					polygon = polygon.substring(polygon.indexOf("<GeometryCollection>"), polygon.indexOf("</GeometryCollection>")+21);
   1.494 +				geometry = baos.toString().substring(38).replaceAll(" xmlns:kml=\"http://earth.google.com/kml/2.1\"", "").replaceAll("kml:", "");
   1.495 +
   1.496 +				if(geometryType == KML.MultiGeometry)
   1.497 +				{
   1.498 +					geometry = geometry.substring(geometry.indexOf("<MultiGeometry>") + 15, geometry.indexOf("</MultiGeometry>"));
   1.499  				}
   1.500 -				//FIXME: test end 
   1.501 +/*				if(geom instanceof Point)
   1.502 +				{
   1.503 +					geometry = geometry.substring(geometry.indexOf("<Point>"), geometry.indexOf("</Point>") + 8);
   1.504 +				}
   1.505 +				else if(geom instanceof Polygon)
   1.506 +				{
   1.507 +					geometry = geometry.substring(geometry.indexOf("<Polygon>"), geometry.indexOf("</Polygon>") + 10);
   1.508 +				}
   1.509 +				else if(geom instanceof LineString)
   1.510 +				{
   1.511 +					geometry = geometry.substring(geometry.indexOf("<LineString>"), geometry.indexOf("</LineString>") + 13);
   1.512 +				}
   1.513 +				else if(geom instanceof MultiPoint)
   1.514 +				{
   1.515 +					geometry = geometry.substring(geometry.indexOf("<MultiPoint>"), geometry.indexOf("</MultiPoint>") + 13);
   1.516 +				}
   1.517 +				else if(geom instanceof MultiLineString)
   1.518 +				{
   1.519 +					geometry = geometry.substring(geometry.indexOf("<MultiLineString>"), geometry.indexOf("</MultiLineString>") + 18);
   1.520 +				}
   1.521 +				else if(geom instanceof MultiPolygon)
   1.522 +				{
   1.523 +					geometry = geometry.substring(geometry.indexOf("<MultiPolygon>"), geometry.indexOf("</MultiPolygon>") + 15);
   1.524 +				}
   1.525 +				else if(geom instanceof GeometryCollection)
   1.526 +				{
   1.527 +					geometry = geometry.substring(geometry.indexOf("<GeometryCollection>"), geometry.indexOf("</GeometryCollection>") + 21);
   1.528 +				}
   1.529 +*/				
   1.530  				baos.reset();
   1.531  			}
   1.532 -		} catch (ParseException e) {
   1.533 +		}
   1.534 +		catch(ParseException e)
   1.535 +		{
   1.536  			logger.error("[Strabon.KMLWriter] Parse error exception of geometry: {}", e.getMessage());
   1.537 -			
   1.538 -		} catch (IOException e) {
   1.539 +		}
   1.540 +		catch(IOException e)
   1.541 +		{
   1.542  			logger.error("[Strabon.KMLWriter] IOException during KML encoding of geometry: {}", e.getMessage());
   1.543 -			
   1.544 -		} catch (JAXBException e) {
   1.545 +		}
   1.546 +		catch(JAXBException e)
   1.547 +		{
   1.548  			logger.error("[Strabon.KMLWriter] Exception during GML parsing: {}", e.getMessage());
   1.549 -			
   1.550  		}
   1.551 -		
   1.552 -		return polygon;
   1.553 +		return geometry;
   1.554  	}
   1.555  
   1.556  	/**
   1.557 @@ -431,41 +447,40 @@
   1.558  	 * 
   1.559  	 * @param binding
   1.560  	 */
   1.561 -	private void writeDesc(Binding binding) {
   1.562 +	private void writeDesc(Binding binding)
   1.563 +	{
   1.564  		descData.append(NEWLINE);
   1.565  		indent(descData, depth + 1);
   1.566  		descData.append(TABLE_ROW_BEGIN);
   1.567 -
   1.568  		descData.append(TABLE_DATA_BEGIN);
   1.569  		descData.append(binding.getName());
   1.570  		descData.append(TABLE_DATA_END);
   1.571 -		
   1.572  		descData.append(TABLE_DATA_BEGIN);
   1.573 -		
   1.574 -		if (binding.getValue() instanceof BNode) {
   1.575 +		if(binding.getValue() instanceof BNode)
   1.576 +		{
   1.577  			descData.append("_:");
   1.578  		}
   1.579 -		
   1.580  		descData.append(binding.getValue().stringValue());
   1.581  		descData.append(TABLE_DATA_END);
   1.582 -		
   1.583  		descData.append(TABLE_ROW_END);
   1.584  	}
   1.585  
   1.586 -	@Override
   1.587 -	public TupleQueryResultFormat getTupleQueryResultFormat() {
   1.588 +	@Override public TupleQueryResultFormat getTupleQueryResultFormat()
   1.589 +	{
   1.590  		return stSPARQLQueryResultFormat.KML;
   1.591  	}
   1.592  
   1.593  	/**
   1.594 -	 * Adds indentation to the given string builder according to 
   1.595 -	 * the specified depth.
   1.596 +	 * Adds indentation to the given string builder according to the specified
   1.597 +	 * depth.
   1.598  	 * 
   1.599  	 * @param sb
   1.600  	 * @param depth
   1.601  	 */
   1.602 -	private void indent(StringBuilder sb, int depth) {
   1.603 -		for (int i = 0; i < depth; i++) {
   1.604 +	private void indent(StringBuilder sb, int depth)
   1.605 +	{
   1.606 +		for(int i = 0; i < depth; i++)
   1.607 +		{
   1.608  			sb.append(xmlWriter.getIndentString());
   1.609  		}
   1.610  	}