Strabon

changeset 322:148740c9c8aa

introduced WKTHelper for common operations on WKT strings
author Babis Nikolaou <charnik@di.uoa.gr>
date Thu Jun 21 23:40:18 2012 +0300 (2012-06-21)
parents 6c115d7795d0
children 1c07378b4160
files evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/evaluation/src/main/java/org/openrdf/query/algebra/evaluation/function/spatial/WKTHelper.java	Thu Jun 21 23:40:18 2012 +0300
     1.3 @@ -0,0 +1,64 @@
     1.4 +package org.openrdf.query.algebra.evaluation.function.spatial;
     1.5 +
     1.6 +import org.slf4j.Logger;
     1.7 +import org.slf4j.LoggerFactory;
     1.8 +
     1.9 +
    1.10 +/**
    1.11 + * 
    1.12 + * @author Charalampos Nikolaou <charnik@di.uoa.gr>
    1.13 + *
    1.14 + */
    1.15 +public class WKTHelper {
    1.16 +
    1.17 +	private static Logger logger = LoggerFactory.getLogger(org.openrdf.query.algebra.evaluation.function.spatial.WKTHelper.class);
    1.18 +	
    1.19 +	private static String SRID_DELIM 	= ";";
    1.20 +	private static String CUT_DELIM 	= "/";
    1.21 +	
    1.22 +	/**
    1.23 +	 * Returns the given WKT without the SRID (if any).
    1.24 +	 * 
    1.25 +	 * @param wkt
    1.26 +	 * @return
    1.27 +	 */
    1.28 +	public static String getWithoutSRID(String wkt) {
    1.29 +		if (wkt == null) return wkt;
    1.30 +		
    1.31 +		int pos = wkt.indexOf(SRID_DELIM);
    1.32 +		if (pos != -1) {
    1.33 +			return wkt.substring(0, pos);
    1.34 +			
    1.35 +		} else {
    1.36 +			return wkt;
    1.37 +		}
    1.38 +	}
    1.39 +	
    1.40 +	/**
    1.41 +	 * Returns the SRID of the given WKT (if any). If the WKT
    1.42 +	 * does not contain any, then the default is returned (specified in
    1.43 +	 * org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron.defaultSRID).
    1.44 +	 * 
    1.45 +	 * @param wkt
    1.46 +	 * @return
    1.47 +	 */
    1.48 +	public static Integer getSRID(String wkt) {
    1.49 +		int srid = StrabonPolyhedron.defaultSRID;
    1.50 +		
    1.51 +		if (wkt == null) return srid;
    1.52 +		
    1.53 +		int pos = wkt.indexOf(SRID_DELIM);
    1.54 +		if (pos != -1) {
    1.55 +			try {
    1.56 +				srid = Integer.parseInt(wkt.substring(wkt.lastIndexOf(CUT_DELIM) + 1));
    1.57 +				
    1.58 +			} catch (NumberFormatException e) {
    1.59 +				logger.warn("[Strabon.WKTHelper] Was expecting an integer. The URL of the SRID was {}. Continuing with the default SRID, {}", wkt.substring(pos + 1), srid);
    1.60 +				
    1.61 +			}
    1.62 +		}
    1.63 +		
    1.64 +		return srid;
    1.65 +
    1.66 +	}
    1.67 +}