Strabon

changeset 1440:9eb039fea93d

GeoJSON writer now takes into account the default precision of the JTS library
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu Oct 30 14:14:33 2014 +0200 (2014-10-30)
parents 363ce8eefcda
children 54679bf9f89b
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java
line diff
     1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java	Wed Oct 29 14:43:04 2014 +0200
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java	Thu Oct 30 14:14:33 2014 +0200
     1.3 @@ -27,6 +27,7 @@
     1.4  import org.slf4j.LoggerFactory;
     1.5  
     1.6  import com.vividsolutions.jts.geom.Geometry;
     1.7 +import com.vividsolutions.jts.geom.PrecisionModel;
     1.8  import com.vividsolutions.jts.io.ParseException;
     1.9  import com.vividsolutions.jts.io.WKBReader;
    1.10  import com.vividsolutions.jts.io.WKBWriter;
    1.11 @@ -75,6 +76,12 @@
    1.12  	 */
    1.13  	private GMLWriter gmlw;
    1.14  	
    1.15 +	/**
    1.16 +	 * Stores the number of decimal places for the
    1.17 +	 * default precision model of JTS. 
    1.18 +	 */
    1.19 +	private int numDecimalPlaces;
    1.20 +
    1.21  	private JTSWrapper() {
    1.22  		// use a private constructor to force call of getInstance method and forbid subclassing
    1.23  		wktr = new WKTReader();
    1.24 @@ -83,6 +90,8 @@
    1.25  		wkbw = new WKBWriter(); // PostGIS
    1.26  //		wkbw = new WKBWriter(2, WKBConstants.wkbXDR); // MonetDB
    1.27  		gmlw = new GMLWriter();
    1.28 +
    1.29 +		numDecimalPlaces = (new PrecisionModel()).getMaximumSignificantDigits();
    1.30  	}
    1.31  	
    1.32  	public static synchronized JTSWrapper getInstance() {
    1.33 @@ -202,4 +211,14 @@
    1.34  	public synchronized String GMLWrite(Geometry geom) {
    1.35  		return gmlw.write(geom);
    1.36  	}
    1.37 +
    1.38 +	/**
    1.39 +	 * Returns the number of decimal places corresponding to the
    1.40 +	 * precision model that is used by default by the JTS library.
    1.41 +	 * 
    1.42 +	 * @return
    1.43 +	 */
    1.44 +	public int getPrecision() {
    1.45 +		return numDecimalPlaces;
    1.46 +	}
    1.47  }
     2.1 --- a/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java	Wed Oct 29 14:43:04 2014 +0200
     2.2 +++ b/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java	Thu Oct 30 14:14:33 2014 +0200
     2.3 @@ -20,6 +20,7 @@
     2.4  import org.geotools.feature.simple.SimpleFeatureBuilder;
     2.5  import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
     2.6  import org.geotools.geojson.feature.FeatureJSON;
     2.7 +import org.geotools.geojson.geom.GeometryJSON;
     2.8  import org.opengis.feature.simple.SimpleFeature;
     2.9  import org.opengis.feature.simple.SimpleFeatureType;
    2.10  import org.openrdf.model.Literal;
    2.11 @@ -101,7 +102,7 @@
    2.12  
    2.13  	@Override
    2.14  	public void startQueryResult(List<String> bindingNames) throws TupleQueryResultHandlerException {
    2.15 -		fjson = new FeatureJSON();
    2.16 +		fjson = new FeatureJSON(new GeometryJSON(jts.getPrecision()));
    2.17  		fjson.setEncodeFeatureCRS(true);
    2.18  	}
    2.19