Strabon

changeset 354:f5cfc1483751

fixed identification of spatial values in GeoJSON
author Babis Nikolaou <charnik@di.uoa.gr>
date Mon Jun 25 19:28:19 2012 +0300 (2012-06-25)
parents 855f4232fefe
children ae895563802f
files resultio/src/main/java/org/openrdf/query/resultio/sparqljson/stSPARQLResultsGeoJSONWriter.java
line diff
     1.1 --- a/resultio/src/main/java/org/openrdf/query/resultio/sparqljson/stSPARQLResultsGeoJSONWriter.java	Mon Jun 25 18:32:44 2012 +0300
     1.2 +++ b/resultio/src/main/java/org/openrdf/query/resultio/sparqljson/stSPARQLResultsGeoJSONWriter.java	Mon Jun 25 19:28:19 2012 +0300
     1.3 @@ -19,12 +19,13 @@
     1.4  import org.openrdf.query.Binding;
     1.5  import org.openrdf.query.BindingSet;
     1.6  import org.openrdf.query.TupleQueryResultHandlerException;
     1.7 -import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron;
     1.8  import org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper;
     1.9  import org.openrdf.query.algebra.evaluation.util.JTSWrapper;
    1.10  import org.openrdf.query.resultio.TupleQueryResultFormat;
    1.11  import org.openrdf.query.resultio.TupleQueryResultWriter;
    1.12  import org.openrdf.query.resultio.stSPARQLQueryResultFormat;
    1.13 +import org.openrdf.sail.generaldb.model.GeneralDBPolyhedron;
    1.14 +import org.openrdf.sail.generaldb.model.XMLGSDatatypeUtil;
    1.15  import org.slf4j.Logger;
    1.16  import org.slf4j.LoggerFactory;
    1.17  
    1.18 @@ -131,30 +132,28 @@
    1.19  			// parse binding set
    1.20  			for (Binding binding : bindingSet) {
    1.21  				Value value = binding.getValue();
    1.22 -				if (value instanceof Literal) {
    1.23 -					Literal litValue = (Literal) value;
    1.24 -
    1.25 -					// it's a spatial literal
    1.26 -					if (litValue.getDatatype().stringValue().equals(StrabonPolyhedron.ogcGeometry)) {
    1.27 -						// TODO Check for GML (when added to StrabonPolyhedron)
    1.28 +				
    1.29 +				if (XMLGSDatatypeUtil.isGeometryValue(value)) {
    1.30 +					// it's a spatial value
    1.31 +					if (logger.isDebugEnabled()) {
    1.32 +						logger.debug("[Strabon.GeoJSON] Found geometry: {}", value);
    1.33 +					}
    1.34 +					
    1.35 +					nfeatures++;
    1.36 +					
    1.37 +					// we need the geometry and the SRID 
    1.38 +					Geometry geom = null;
    1.39 +					int srid = -1;
    1.40 +					
    1.41 +					if (value instanceof GeneralDBPolyhedron) {
    1.42 +						GeneralDBPolyhedron dbpolyhedron = (GeneralDBPolyhedron) value;
    1.43  						
    1.44 -						nfeatures++;
    1.45 +						geom = dbpolyhedron.getPolyhedron().getGeometry();
    1.46 +						srid = dbpolyhedron.getPolyhedron().getGeometry().getSRID();
    1.47  						
    1.48 -						if (logger.isDebugEnabled()) {
    1.49 -							logger.debug("[Strabon] Found geometry: {}", litValue);
    1.50 -						}
    1.51 +					} else { // spatial literal WKT or GML
    1.52  						
    1.53 -						// get the geometry and SRID
    1.54 -						Geometry geom = null;
    1.55 -						int srid = -1;
    1.56 -						
    1.57 -						// TODO add dependency to pom.xml for GeneralDBPolyhedron 
    1.58 -						// Regardless of our geometry's input, we need its SRID
    1.59 -//						if (unparsedGeometry instanceof GeneralDBPolyhedron) {
    1.60 -//							geom = ((GeneralDBPolyhedron) value).getPolyhedron().getGeometry();
    1.61 -//							srid = ((GeneralDBPolyhedron) value).getPolyhedron().getGeometry().getSRID();
    1.62 -//							
    1.63 -//						} else { // WKT
    1.64 +						if (XMLGSDatatypeUtil.isWKTLiteral((Literal) value)) {// WKT
    1.65  							// get the WKT as it is present in the result
    1.66  							String wkt = value.stringValue();
    1.67  							
    1.68 @@ -163,35 +162,27 @@
    1.69  							
    1.70  							// get its SRID
    1.71  							srid = WKTHelper.getSRID(wkt);
    1.72 -								
    1.73 -							// TODO: GML support to be added
    1.74 -						//}
    1.75 -					
    1.76 -						SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder();
    1.77 -						sftb.setName("Feature_" + nresults + "_" + nfeatures);
    1.78 -						sftb.setCRS(CRS.decode("EPSG:" + srid));
    1.79 -						sftb.setSRS("EPSG:" + srid);
    1.80 -						sftb.add("geometry", Geometry.class);
    1.81 -						
    1.82 -						// add the feature in the list of features
    1.83 -						features.add(sftb);
    1.84 -						
    1.85 -						// add the geometry of the feature in the list of geometries
    1.86 -						geometries.add(geom);
    1.87 -						
    1.88 -					
    1.89 -					} else { // Literal other than geometry
    1.90 -						if (logger.isDebugEnabled()) {
    1.91 -							logger.debug("[Strabon.GeoJSONWriter] Found Literal: {}", value);
    1.92 +							
    1.93 +						} else { // TODO GML
    1.94 +							logger.warn("[Strabon.GeoJSON] GML is not supported yet.");
    1.95  						}
    1.96 -
    1.97 -						properties.add(binding.getName());
    1.98 -						values.add(value);
    1.99  					}
   1.100  					
   1.101 -				} else { // URI or BlankNode
   1.102 +					SimpleFeatureTypeBuilder sftb = new SimpleFeatureTypeBuilder();
   1.103 +					sftb.setName("Feature_" + nresults + "_" + nfeatures);
   1.104 +					sftb.setCRS(CRS.decode("EPSG:" + srid));
   1.105 +					sftb.setSRS("EPSG:" + srid);
   1.106 +					sftb.add("geometry", Geometry.class);
   1.107 +					
   1.108 +					// add the feature in the list of features
   1.109 +					features.add(sftb);
   1.110 +					
   1.111 +					// add the geometry of the feature in the list of geometries
   1.112 +					geometries.add(geom);
   1.113 +					
   1.114 +				} else { // URI, BlankNode, or Literal other than geometry
   1.115  					if (logger.isDebugEnabled()) {
   1.116 -						logger.debug("[Strabon.GeoJSONWriter] Found URI/BlankNode: {}", value);
   1.117 +						logger.debug("[Strabon.GeoJSON] Found resource: {}", value);
   1.118  					}
   1.119  					
   1.120  					properties.add(binding.getName());