Revision 44741
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/function/spatial/STTransformFunction.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.impl.function.spatial; |
|
2 |
|
|
3 |
import org.apache.commons.lang3.Range; |
|
4 |
import org.cresques.cts.ICoordTrans; |
|
5 |
import org.cresques.cts.IProjection; |
|
6 |
import org.gvsig.expressionevaluator.ExpressionRuntimeException; |
|
7 |
import org.gvsig.expressionevaluator.Interpreter; |
|
8 |
import org.gvsig.expressionevaluator.spi.AbstractGeometryFunction; |
|
9 |
import org.gvsig.fmap.crs.CRSFactory; |
|
10 |
import org.gvsig.fmap.geom.Geometry; |
|
11 |
import org.gvsig.tools.dataTypes.DataTypeUtils; |
|
12 |
|
|
13 |
public class STTransformFunction extends AbstractGeometryFunction { |
|
14 |
|
|
15 |
public STTransformFunction() { |
|
16 |
super("OGC", "ST_Transform", Range.between(2,3)); |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
public boolean allowConstantFolding() { |
|
21 |
return true; |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
public Object call(Interpreter interpreter, Object[] args) throws Exception { |
|
26 |
IProjection to_proj = null; |
|
27 |
IProjection from_proj = null; |
|
28 |
Integer to_srid = null; |
|
29 |
Geometry geom = getGeom(args, 0); |
|
30 |
switch(args.length) { |
|
31 |
case 2: |
|
32 |
to_srid = DataTypeUtils.toInteger(getObject(args, 1),null); |
|
33 |
if( to_srid==null ) { |
|
34 |
to_proj = CRSFactory.getCRS(getStr(args, 1)); |
|
35 |
} else { |
|
36 |
to_proj = CRSFactory.getCRS("EPSG:"+to_srid); |
|
37 |
} |
|
38 |
from_proj = geom.getProjection(); |
|
39 |
break; |
|
40 |
|
|
41 |
case 3: |
|
42 |
to_srid = DataTypeUtils.toInteger(getObject(args, 2),null); |
|
43 |
if( to_srid==null ) { |
|
44 |
to_proj = CRSFactory.getCRS(getStr(args, 2)); |
|
45 |
} else { |
|
46 |
to_proj = CRSFactory.getCRS("EPSG:"+to_srid); |
|
47 |
} |
|
48 |
from_proj = CRSFactory.getCRS(getStr(args, 1)); |
|
49 |
break; |
|
50 |
|
|
51 |
default: |
|
52 |
throw new ExpressionRuntimeException("Incorrect number of arguments."); |
|
53 |
} |
|
54 |
ICoordTrans ct = from_proj.getCT(to_proj); |
|
55 |
Geometry r = geom.cloneGeometry(); |
|
56 |
r.reProject(ct); |
|
57 |
return r; |
|
58 |
} |
|
59 |
|
|
60 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/symboltable/OGCSymbolTable.java | ||
---|---|---|
35 | 35 |
import org.gvsig.expressionevaluator.impl.function.spatial.STSetSRIDFunction; |
36 | 36 |
import org.gvsig.expressionevaluator.impl.function.spatial.STStartPointFunction; |
37 | 37 |
import org.gvsig.expressionevaluator.impl.function.spatial.STTouchesFunction; |
38 |
import org.gvsig.expressionevaluator.impl.function.spatial.STTransformFunction; |
|
38 | 39 |
import org.gvsig.expressionevaluator.impl.function.spatial.STUnionFunction; |
39 | 40 |
import org.gvsig.expressionevaluator.impl.function.spatial.STWithinFunction; |
40 | 41 |
import org.gvsig.expressionevaluator.impl.function.spatial.STXFunction; |
... | ... | |
97 | 98 |
this.addFunction(new STPointFunction()); |
98 | 99 |
this.addFunction(new STMakePointFunction()); |
99 | 100 |
this.addFunction(new STForce2DFunction()); |
101 |
this.addFunction(new STTransformFunction()); |
|
100 | 102 |
|
101 | 103 |
this.addFunction(new AndAndOperator()); |
102 | 104 |
} |
Also available in: Unified diff