Strabon

changeset 1378:5278d51fba75

changed default SRID of PostGIS to 84000 (CRS84); changed/updated default CRSs for strdf:WKT and geo:wktLiteral (both of the use CRS84); further, Geotools do not reverse longitude/latitude, so we use the official EPSG:4326 ordering, that is, Lat/Long
author Babis Nikolaou <charnik@di.uoa.gr>
date Wed Sep 17 10:35:43 2014 +0300 (2014-09-17)
parents 457324e89533
children 433bcbcee139
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java postgis/src/main/java/org/openrdf/sail/postgis/PostGISSqlTable.java resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java
line diff
     1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java	Wed Sep 17 10:27:59 2014 +0300
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/AbstractWKT.java	Wed Sep 17 10:35:43 2014 +0300
     1.3 @@ -132,7 +132,7 @@
     1.4  	
     1.5  	private void parseWKTLITERAL(String literalValue) {
     1.6  		wkt = literalValue.trim();
     1.7 -		srid = GeoConstants.WGS84_LON_LAT_SRID;
     1.8 +		srid = GeoConstants.default_GeoSPARQL_SRID;
     1.9  		
    1.10  		if (wkt.length() == 0) { // empty geometry
    1.11  			wkt = EMPTY_GEOM;
    1.12 @@ -144,9 +144,8 @@
    1.13  			// FIXME: handle invalid URIs
    1.14  			URI crs = URI.create(wkt.substring(1, uriIndx));
    1.15  			
    1.16 -			// FIXME: get the SRID for crs properly. HOW??
    1.17 -			if (GeoConstants.WGS84_LON_LAT.equals(crs.toString())) {
    1.18 -				srid = GeoConstants.WGS84_LON_LAT_SRID;
    1.19 +			if (GeoConstants.WGS84_LONG_LAT.equals(crs.toString())) {
    1.20 +				srid = GeoConstants.WGS84_LONG_LAT_SRID;
    1.21  				
    1.22  			} else { // parse it to get the srid
    1.23  				// FIXME: this code assumes an EPSG URI
    1.24 @@ -171,7 +170,7 @@
    1.25  		return datatype;
    1.26  	}
    1.27  	
    1.28 -	boolean isstRDFWKT() {
    1.29 +	public boolean isstRDFWKT() {
    1.30  		return isstRDFWKT;
    1.31  	}
    1.32  	
    1.33 @@ -185,7 +184,7 @@
    1.34  	 * @return
    1.35  	 */
    1.36  	protected int getEPSG_SRID(String wkt) {
    1.37 -		int srid = GeoConstants.default_GeoSPARQL_SRID;
    1.38 +		int srid = GeoConstants.defaultSRID;
    1.39  		
    1.40  		try {
    1.41  			srid = Integer.parseInt(wkt.substring(wkt.lastIndexOf('/') + 1).replace(">", ""));
     2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java	Wed Sep 17 10:27:59 2014 +0300
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java	Wed Sep 17 10:35:43 2014 +0300
     2.3 @@ -49,14 +49,13 @@
     2.4  	
     2.5  	/**
     2.6  	 * Returns the SRID of the given WKT (if any). If the WKT
     2.7 -	 * does not contain any, then the default is returned (specified in
     2.8 -	 * org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron.defaultSRID).
     2.9 +	 * does not contain any, then the default is returned.
    2.10  	 * 
    2.11  	 * @param wkt
    2.12  	 * @return
    2.13  	 */
    2.14  	public static Integer getSRID(String wkt) {
    2.15 -		int srid = GeoConstants.defaultSRID;
    2.16 +		int srid = GeoConstants.default_stRDF_SRID;
    2.17  		
    2.18  		if (wkt == null) return srid;
    2.19  		
    2.20 @@ -72,6 +71,5 @@
    2.21  		}
    2.22  		
    2.23  		return srid;
    2.24 -
    2.25  	}
    2.26  }
     3.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java	Wed Sep 17 10:27:59 2014 +0300
     3.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java	Wed Sep 17 10:35:43 2014 +0300
     3.3 @@ -17,8 +17,10 @@
     3.4  
     3.5  import org.geotools.geometry.jts.JTS;
     3.6  import org.geotools.referencing.CRS;
     3.7 +import org.geotools.referencing.crs.DefaultGeographicCRS;
     3.8  import org.opengis.geometry.MismatchedDimensionException;
     3.9  import org.opengis.referencing.FactoryException;
    3.10 +import org.opengis.referencing.NoSuchAuthorityCodeException;
    3.11  import org.opengis.referencing.crs.CoordinateReferenceSystem;
    3.12  import org.opengis.referencing.operation.MathTransform;
    3.13  import org.opengis.referencing.operation.TransformException;
    3.14 @@ -33,6 +35,8 @@
    3.15  import com.vividsolutions.jts.io.WKTWriter;
    3.16  import com.vividsolutions.jts.io.gml2.GMLReader;
    3.17  
    3.18 +import eu.earthobservatory.constants.GeoConstants;
    3.19 +
    3.20  /**
    3.21   * This class is a singleton and provides access to the readers/writers
    3.22   * of Java Topology Suite. 
    3.23 @@ -85,6 +89,16 @@
    3.24  		return instance;
    3.25  	}
    3.26  	
    3.27 +	protected CoordinateReferenceSystem getCRS(int srid) throws NoSuchAuthorityCodeException, FactoryException {
    3.28 +		if (srid == GeoConstants.WGS84_LONG_LAT_SRID) {
    3.29 +			return DefaultGeographicCRS.WGS84;
    3.30 +			
    3.31 +		} else { // otherwise lookup for EPSG code
    3.32 +			// TODO: is there a way to be more general (than EPSG)?
    3.33 +			return CRS.decode("EPSG:" + srid);
    3.34 +		}
    3.35 +	}
    3.36 +	
    3.37  	public synchronized Geometry WKTread(String wkt) throws ParseException {
    3.38  		Geometry geometry = wktr.read(wkt);
    3.39  		
    3.40 @@ -130,15 +144,14 @@
    3.41  		// the geometry to return
    3.42  		Geometry output = input;
    3.43  		
    3.44 -		if(sourceSRID != targetSRID) {
    3.45 +		if (sourceSRID != targetSRID) {
    3.46  			CoordinateReferenceSystem sourceCRS = null;
    3.47  			CoordinateReferenceSystem targetCRS = null;
    3.48  			
    3.49  			MathTransform transform;
    3.50  			try {
    3.51 -				//TODO: EPSG supported currently - is there a way to be more general??
    3.52 -				sourceCRS = CRS.decode("EPSG:" + sourceSRID);
    3.53 -				targetCRS = CRS.decode("EPSG:" + targetSRID);
    3.54 +				sourceCRS = getCRS(sourceSRID);
    3.55 +				targetCRS = getCRS(targetSRID);
    3.56  				transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
    3.57  
    3.58  				output = JTS.transform(input, transform);
    3.59 @@ -157,7 +170,7 @@
    3.60  		}
    3.61  		
    3.62  		return output;
    3.63 -	}		
    3.64 +	}
    3.65  	
    3.66  	/**
    3.67  	 * Parses and returns a {@link Geometry} object constructed from the given GML representation.
     4.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java	Wed Sep 17 10:27:59 2014 +0300
     4.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/schema/LiteralTable.java	Wed Sep 17 10:35:43 2014 +0300
     4.3 @@ -215,7 +215,7 @@
     4.4  			
     4.5  			AbstractWKT awkt = new AbstractWKT(label, datatype);
     4.6  			Geometry geom = JTS.WKTread(awkt.getWKT());
     4.7 -			int srid = awkt.getDB_SRID();
     4.8 +			int srid = awkt.getSRID();
     4.9  			
    4.10  			geoSpatialTable.insert(id, srid, /*start,end,*/ JTS.WKBwrite(geom));
    4.11  			
     5.1 --- a/postgis/src/main/java/org/openrdf/sail/postgis/PostGISSqlTable.java	Wed Sep 17 10:27:59 2014 +0300
     5.2 +++ b/postgis/src/main/java/org/openrdf/sail/postgis/PostGISSqlTable.java	Wed Sep 17 10:35:43 2014 +0300
     5.3 @@ -9,15 +9,18 @@
     5.4  
     5.5  import org.openrdf.sail.generaldb.GeneralDBSqlTable;
     5.6  
     5.7 +import eu.earthobservatory.constants.GeoConstants;
     5.8 +
     5.9  /**
    5.10   * Converts table names to lower-case and include the analyse optimisation.
    5.11   * 
    5.12 - * @author James Leigh
    5.13 + * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    5.14 + * @author Manos Karpathiotakis <mk@di.uoa.gr>
    5.15   * 
    5.16   */
    5.17  public class PostGISSqlTable extends GeneralDBSqlTable {
    5.18  
    5.19 -	public static final int DEFAULT_SRID = 4326;
    5.20 +	public static final int DEFAULT_SRID = GeoConstants.WGS84_LONG_LAT_SRID;
    5.21  	
    5.22  	public PostGISSqlTable(String name) {
    5.23  		super(name.toLowerCase());
     6.1 --- a/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java	Wed Sep 17 10:27:59 2014 +0300
     6.2 +++ b/resultio-spatial/sparqlgeojson/src/main/java/org/openrdf/query/resultio/sparqlgeojson/stSPARQLResultsGeoJSONWriter.java	Wed Sep 17 10:35:43 2014 +0300
     6.3 @@ -20,7 +20,6 @@
     6.4  import org.geotools.feature.simple.SimpleFeatureBuilder;
     6.5  import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
     6.6  import org.geotools.geojson.feature.FeatureJSON;
     6.7 -import org.geotools.referencing.CRS;
     6.8  import org.opengis.feature.simple.SimpleFeature;
     6.9  import org.opengis.feature.simple.SimpleFeatureType;
    6.10  import org.openrdf.model.Literal;
     7.1 --- a/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Wed Sep 17 10:27:59 2014 +0300
     7.2 +++ b/resultio-spatial/sparqlkml/src/main/java/org/openrdf/query/resultio/sparqlkml/stSPARQLResultsKMLWriter.java	Wed Sep 17 10:35:43 2014 +0300
     7.3 @@ -16,7 +16,6 @@
     7.4  import javax.xml.bind.JAXBException;
     7.5  import javax.xml.namespace.QName;
     7.6  
     7.7 -import org.apache.xerces.xni.grammars.XMLGrammarDescription;
     7.8  import org.geotools.kml.KML;
     7.9  import org.geotools.kml.KMLConfiguration;
    7.10  import org.geotools.xml.Encoder;
    7.11 @@ -26,7 +25,6 @@
    7.12  import org.openrdf.query.Binding;
    7.13  import org.openrdf.query.BindingSet;
    7.14  import org.openrdf.query.TupleQueryResultHandlerException;
    7.15 -import org.openrdf.query.algebra.IsLiteral;
    7.16  import org.openrdf.query.algebra.evaluation.function.spatial.AbstractWKT;
    7.17  import org.openrdf.query.algebra.evaluation.util.JTSWrapper;
    7.18  import org.openrdf.query.resultio.TupleQueryResultFormat;
    7.19 @@ -198,7 +196,6 @@
    7.20  		try {
    7.21  			// true if there are bindings that do not correspond to geometries
    7.22  			boolean hasDesc = false;
    7.23 -			String timeValue;
    7.24  			
    7.25  			Hashtable<String, String> extData = new Hashtable<String, String>();
    7.26  
    7.27 @@ -357,8 +354,8 @@
    7.28  				}
    7.29  			}
    7.30  			
    7.31 -			// transform the geometry to {@link GeoConstants#defaultSRID}
    7.32 -			geom = jts.transform(geom, srid, GeoConstants.defaultSRID);
    7.33 +			// transform the geometry to {@link GeoConstants#WGS84_LONG_LAT_SRID}
    7.34 +			geom = jts.transform(geom, srid, GeoConstants.WGS84_LONG_LAT_SRID);
    7.35  			
    7.36  			if (geom instanceof Point) {
    7.37  				geometryType = KML.Point;
     8.1 --- a/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed Sep 17 10:27:59 2014 +0300
     8.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/generaldb/Strabon.java	Wed Sep 17 10:35:43 2014 +0300
     8.3 @@ -18,6 +18,7 @@
     8.4  import java.sql.SQLException;
     8.5  import java.util.ArrayList;
     8.6  
     8.7 +import org.geotools.factory.Hints;
     8.8  import org.openrdf.model.URI;
     8.9  import org.openrdf.model.ValueFactory;
    8.10  import org.openrdf.query.BindingSet;
    8.11 @@ -114,8 +115,8 @@
    8.12  		//Setting up store
    8.13  
    8.14  		//Used for the conversions taking place involving JTS + WGS84 (4326)
    8.15 -		//Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
    8.16 -		System.setProperty("org.geotools.referencing.forceXY", "true");
    8.17 +		Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.FALSE);
    8.18 +		//System.setProperty("org.geotools.referencing.forceXY", "true");
    8.19  		
    8.20  		//our repository
    8.21  		repo = new GeneralDBSailRepository(db_store);
     9.1 --- a/vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java	Wed Sep 17 10:27:59 2014 +0300
     9.2 +++ b/vocab/src/main/java/eu/earthobservatory/constants/GeoConstants.java	Wed Sep 17 10:35:43 2014 +0300
     9.3 @@ -164,34 +164,42 @@
     9.4  	/**
     9.5  	 * WGS 84 latitude-longitude (EPSG:4326)
     9.6  	 */
     9.7 -	public static final String WGS84_LAT_LON	= "http://www.opengis.net/def/crs/EPSG/0/4326";
     9.8 +	public static final String WGS84_LAT_LONG	= "http://www.opengis.net/def/crs/EPSG/0/4326";
     9.9  	
    9.10  	/**
    9.11  	 * WGS 84 longitude-latitude
    9.12 -	 * (used as the default CRS for GeoSPARQL geometries)
    9.13  	 */
    9.14 -	public static final String WGS84_LON_LAT	= "http://www.opengis.net/def/crs/OGC/1.3/CRS84";
    9.15 +	public static final String WGS84_LONG_LAT	= "http://www.opengis.net/def/crs/OGC/1.3/CRS84";
    9.16  
    9.17  	/**
    9.18  	 * EPSG:4326
    9.19  	 */
    9.20 -	public static final Integer WGS84_LAT_LON_SRID = 4326;
    9.21 +	public static final Integer WGS84_LAT_LONG_SRID = 4326;
    9.22  	
    9.23  	/**
    9.24 -	 * EPSG:3857 (not sure whether this is correct for WGS84_LON_LAT)
    9.25 -	 * http://spatialreference.org/ref/sr-org/7483/
    9.26 +	 * The SRID for WGS84 long/lat does not exist, because no such CRS
    9.27 +	 * exist in the EPSG database. Geotools return the same code, i.e.,
    9.28 +	 * EPSG:4326, but this is wrong to have here. Therefore, we use a
    9.29 +	 * custom SRID inspired by the devil, and thus, it is our custom and
    9.30 +	 * internal code for referencing the LONG/LAT version of EPSG:4326 
    9.31 +	 * (i.e., WGS84 lat/long).
    9.32  	 */
    9.33 -	public static final Integer WGS84_LON_LAT_SRID = 3857;
    9.34 +	public static final Integer WGS84_LONG_LAT_SRID = 84000;
    9.35  
    9.36  	/**
    9.37 -	 * Default SRID (WGS84 latitude-longitude)
    9.38 +	 * Default stRDF/stSPARQL SRID (WGS84 latitude-longitude)
    9.39  	 */
    9.40 -	public static final Integer defaultSRID 	= WGS84_LAT_LON_SRID;
    9.41 +	public static final Integer default_stRDF_SRID = WGS84_LONG_LAT_SRID;
    9.42  	
    9.43  	/**
    9.44  	 * Default GeoSPARQL SRID (WGS84 longitude-latitude)
    9.45  	 */
    9.46 -	public static final Integer default_GeoSPARQL_SRID 	= WGS84_LON_LAT_SRID;
    9.47 +	public static final Integer default_GeoSPARQL_SRID 	= WGS84_LONG_LAT_SRID;
    9.48 +	
    9.49 +	/**
    9.50 +	 * Default SRID (WGS84 longitude/latitude)
    9.51 +	 */
    9.52 +	public static final Integer defaultSRID 	= WGS84_LONG_LAT_SRID;
    9.53  	
    9.54  	/**																		*
    9.55  	 *  						Extended functions 							*