Strabon

changeset 321:6c115d7795d0

moved the implementation of StrabonPolyhedron.transform() to JTSWrapper and made StrabonPolyhedron.transform() a delegator
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu Jun 21 22:59:17 2012 +0300 (2012-06-21)
parents e36e63a58d63
children 148740c9c8aa
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java
line diff
     1.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java	Thu Jun 21 20:51:55 2012 +0300
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/StrabonPolyhedron.java	Thu Jun 21 22:59:17 2012 +0300
     1.3 @@ -179,36 +179,8 @@
     1.4  		return new StrabonPolyhedron(jts.WKBread((byteArray)));
     1.5  	}
     1.6  
     1.7 -	public static Geometry convertSRID(Geometry A, int sourceSRID, int targetSRID)
     1.8 -	{
     1.9 -
    1.10 -		if(sourceSRID != targetSRID)
    1.11 -		{
    1.12 -			CoordinateReferenceSystem sourceCRS = null;
    1.13 -			CoordinateReferenceSystem targetCRS = null;
    1.14 -			
    1.15 -			MathTransform transform;
    1.16 -			try {
    1.17 -				//EPSG supported currently - is there a way to be more general??
    1.18 -				sourceCRS = CRS.decode("EPSG:"+sourceSRID);
    1.19 -				targetCRS = CRS.decode("EPSG:"+targetSRID);
    1.20 -				transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
    1.21 -
    1.22 -				Geometry x = JTS.transform(A, transform);
    1.23 -				x.setSRID(targetSRID);
    1.24 -				return x;
    1.25 -			} catch (FactoryException e) {
    1.26 -				// TODO Auto-generated catch block
    1.27 -				e.printStackTrace();
    1.28 -			} catch (MismatchedDimensionException e) {
    1.29 -				// TODO Auto-generated catch block
    1.30 -				e.printStackTrace();
    1.31 -			} catch (TransformException e) {
    1.32 -				System.out.println("Transformation is not possible!!");
    1.33 -				e.printStackTrace();
    1.34 -			} 
    1.35 -		}
    1.36 -		return A;
    1.37 +	public static Geometry convertSRID(Geometry A, int sourceSRID, int targetSRID) {
    1.38 +		return JTSWrapper.getInstance().transform(A, sourceSRID, targetSRID);
    1.39  	}
    1.40  
    1.41  	//public StrabonPolyhedron(int partitionAlgorithmIgnored, String constraints) throws Exception {
     2.1 --- a/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java	Thu Jun 21 20:51:55 2012 +0300
     2.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/util/JTSWrapper.java	Thu Jun 21 22:59:17 2012 +0300
     2.3 @@ -3,9 +3,18 @@
     2.4   */
     2.5  package org.openrdf.query.algebra.evaluation.util;
     2.6  
     2.7 +import org.geotools.geometry.jts.JTS;
     2.8 +import org.geotools.referencing.CRS;
     2.9 +import org.opengis.geometry.MismatchedDimensionException;
    2.10 +import org.opengis.referencing.FactoryException;
    2.11 +import org.opengis.referencing.crs.CoordinateReferenceSystem;
    2.12 +import org.opengis.referencing.operation.MathTransform;
    2.13 +import org.opengis.referencing.operation.TransformException;
    2.14 +import org.slf4j.Logger;
    2.15 +import org.slf4j.LoggerFactory;
    2.16 +
    2.17  import com.vividsolutions.jts.geom.Geometry;
    2.18  import com.vividsolutions.jts.io.ParseException;
    2.19 -import com.vividsolutions.jts.io.WKBConstants;
    2.20  import com.vividsolutions.jts.io.WKBReader;
    2.21  import com.vividsolutions.jts.io.WKBWriter;
    2.22  import com.vividsolutions.jts.io.WKTReader;
    2.23 @@ -15,17 +24,36 @@
    2.24   * This class is a singleton and provides access to the readers/writers
    2.25   * of Java Topology Suite. 
    2.26   * 
    2.27 - * @author charnik
    2.28 + * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    2.29   *
    2.30   */
    2.31  public class JTSWrapper {
    2.32 +	
    2.33 +	private static final Logger logger = LoggerFactory.getLogger(org.openrdf.query.algebra.evaluation.util.JTSWrapper.class);
    2.34  
    2.35 -	// single instance of JTSReaders
    2.36 +	/**
    2.37 +	 *  Single instance of JTSReaders
    2.38 +	 */
    2.39  	private static JTSWrapper instance;
    2.40  	
    2.41 +	/**
    2.42 +	 * Reader for WKT
    2.43 +	 */
    2.44  	private WKTReader wktr;
    2.45 +	
    2.46 +	/**
    2.47 +	 * Writer for WKT
    2.48 +	 */
    2.49  	private WKTWriter wktw;
    2.50 +	
    2.51 +	/**
    2.52 +	 * Reader for WKB
    2.53 +	 */
    2.54  	private WKBReader wkbr;
    2.55 +	
    2.56 +	/**
    2.57 +	 * Writer for WKB
    2.58 +	 */
    2.59  	private WKBWriter wkbw;
    2.60  	
    2.61  	private JTSWrapper() {
    2.62 @@ -66,4 +94,47 @@
    2.63  		
    2.64  	}
    2.65  	
    2.66 +	/**
    2.67 +	 * Transforms the given geometry in the sourceSRID to a geometry in the
    2.68 +	 * targetSRID.
    2.69 +	 * 
    2.70 +	 * TODO: Is there any synchronization problem?
    2.71 +	 * 
    2.72 +	 * @param input
    2.73 +	 * @param sourceSRID
    2.74 +	 * @param targetSRID
    2.75 +	 * @return
    2.76 +	 */
    2.77 +	public Geometry transform(Geometry input, int sourceSRID, int targetSRID) {
    2.78 +		// the geometry to return
    2.79 +		Geometry output = input;
    2.80 +		
    2.81 +		if(sourceSRID != targetSRID) {
    2.82 +			CoordinateReferenceSystem sourceCRS = null;
    2.83 +			CoordinateReferenceSystem targetCRS = null;
    2.84 +			
    2.85 +			MathTransform transform;
    2.86 +			try {
    2.87 +				//TODO: EPSG supported currently - is there a way to be more general??
    2.88 +				sourceCRS = CRS.decode("EPSG:" + sourceSRID);
    2.89 +				targetCRS = CRS.decode("EPSG:" + targetSRID);
    2.90 +				transform = CRS.findMathTransform(sourceCRS, targetCRS, true);
    2.91 +
    2.92 +				output = JTS.transform(input, transform);
    2.93 +				output.setSRID(targetSRID);
    2.94 +				
    2.95 +			} catch (FactoryException e) {
    2.96 +				logger.error("[Strabon.JTSWrapper] Got FactoryException during transformation.", e);
    2.97 +				
    2.98 +			} catch (MismatchedDimensionException e) {
    2.99 +				logger.error("[Strabon.JTSWrapper] Got MismatchedDimensionExtension during transformation.", e);
   2.100 +				
   2.101 +			} catch (TransformException e) {
   2.102 +				logger.error("[Strabon.JTSWrapper] Transformation from SRID {} to SRID {} is not possible.", sourceSRID, targetSRID);
   2.103 +				
   2.104 +			}
   2.105 +		}
   2.106 +		
   2.107 +		return output;
   2.108 +	}
   2.109  }