Revision 21993

View differences:

branches/v2_0_0_prep/libraries/libFMap_data/src/org/gvsig/fmap/data/vectorial/expressionevaluator/functions/GeomFromText.java
1 1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22 22

  
23 23
/*
24
* AUTHORS (In addition to CIT):
25
* 2008 IVER T.I. S.A.   {{Task}}
26
*/
27
 
24
 * AUTHORS (In addition to CIT):
25
 * 2008 IVER T.I. S.A.   {{Task}}
26
 */
27

  
28 28
package org.gvsig.fmap.data.vectorial.expressionevaluator.functions;
29 29

  
30 30
import org.gvsig.fmap.geom.Geometry;
31 31
import org.gvsig.fmap.geom.operation.GeometryOperationException;
32 32
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
33
import org.gvsig.fmap.geom.operation.fromwkb.FromWKB;
34 33
import org.gvsig.fmap.geom.operation.fromwkt.FromWKT;
35 34
import org.gvsig.fmap.geom.operation.fromwkt.FromWKTGeometryOperationContext;
36 35
import org.gvsig.fmap.geom.primitive.NullGeometry;
......
39 38
import org.medfoster.sqljep.ParseException;
40 39
import org.medfoster.sqljep.function.PostfixCommand;
41 40

  
42
public class GeomFromText extends PostfixCommand {	
41
public class GeomFromText extends PostfixCommand {
43 42

  
44 43
	private static Geometry nullGeometry = new NullGeometry();
45
	
44

  
46 45
	public static final String NAME = "GeomFromText";
47
	
46

  
48 47
	final public int getNumberOfParameters() {
49 48
		return 2;
50 49
	}
51 50

  
52
	/* (non-Javadoc)
53
	 * @see org.medfoster.sqljep.function.PostfixCommand#evaluate(org.medfoster.sqljep.ASTFunNode, org.medfoster.sqljep.JepRuntime)
51
	/*
52
	 * (non-Javadoc)
53
	 * 
54
	 * @see org.medfoster.sqljep.function.PostfixCommand#evaluate(org.medfoster.sqljep.ASTFunNode,
55
	 *      org.medfoster.sqljep.JepRuntime)
54 56
	 */
55 57
	public void evaluate(ASTFunNode node, JepRuntime runtime)
56 58
			throws ParseException {
57 59
		node.childrenAccept(runtime.ev, null);
58
		String text = (String)runtime.stack.pop();
59
		String srs = (String)runtime.stack.pop();
60
		runtime.stack.push(geometryFromText(text,srs));
60
		String text = (String) runtime.stack.pop();
61
		String srs = (String) runtime.stack.pop();
62
		runtime.stack.push(geometryFromText(text, srs));
61 63
	}
62 64

  
63
	private static Object geometryFromText(String text,String srs) throws ParseException {	
65
	private static Object geometryFromText(String text, String srs)
66
			throws ParseException {
64 67
		try {
65
			return nullGeometry.invokeOperation(FromWKT.CODE, new FromWKTGeometryOperationContext(text,srs));
68
			return nullGeometry.invokeOperation(FromWKT.CODE,
69
					new FromWKTGeometryOperationContext(text, srs));
66 70
		} catch (GeometryOperationNotSupportedException e) {
67
			throw new ParseException(NAME,e);
71
			throw new ParseException(NAME, e);
68 72
		} catch (GeometryOperationException e) {
69
			throw new ParseException(NAME,e);
73
			throw new ParseException(NAME, e);
70 74
		}
71 75
	}
72 76

  

Also available in: Unified diff