svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.tools.evaluator.sqljep / src / main / java / org / gvsig / tools / evaluator / sqljep / function / GeomFromText.java @ 40560
History | View | Annotate | Download (3.09 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2008 IVER T.I. S.A. {{Task}}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.tools.evaluator.sqljep.function; |
30 |
|
31 |
import org.gvsig.fmap.geom.Geometry; |
32 |
import org.gvsig.fmap.geom.GeometryException; |
33 |
import org.gvsig.fmap.geom.GeometryLocator; |
34 |
import org.gvsig.fmap.geom.GeometryManager; |
35 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
36 |
import org.gvsig.tools.locator.LocatorException; |
37 |
import org.medfoster.sqljep.ASTFunNode; |
38 |
import org.medfoster.sqljep.JepRuntime; |
39 |
import org.medfoster.sqljep.ParseException; |
40 |
import org.medfoster.sqljep.function.PostfixCommand; |
41 |
import org.slf4j.Logger; |
42 |
import org.slf4j.LoggerFactory; |
43 |
|
44 |
public class GeomFromText extends PostfixCommand { |
45 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
46 |
private static final Logger logger = LoggerFactory.getLogger(GeomFromText.class); |
47 |
|
48 |
private static Geometry nullGeometry = null; |
49 |
private static Object lock = new Object(); |
50 |
|
51 |
public static final String NAME = "GeomFromText"; |
52 |
private static String lastTextGeometry=""; |
53 |
private static String lastSRS=""; |
54 |
private static Geometry lastGeometry=null; |
55 |
|
56 |
final public int getNumberOfParameters() { |
57 |
return 2; |
58 |
} |
59 |
|
60 |
public GeomFromText() {
|
61 |
super();
|
62 |
} |
63 |
|
64 |
/*
|
65 |
* (non-Javadoc)
|
66 |
*
|
67 |
* @see org.medfoster.sqljep.function.PostfixCommand#evaluate(org.medfoster.sqljep.ASTFunNode,
|
68 |
* org.medfoster.sqljep.JepRuntime)
|
69 |
*/
|
70 |
public void evaluate(ASTFunNode node, JepRuntime runtime) |
71 |
throws ParseException { |
72 |
node.childrenAccept(runtime.ev, null);
|
73 |
String srs = (String) runtime.stack.pop(); |
74 |
String text = (String) runtime.stack.pop(); |
75 |
runtime.stack.push(geometryFromText(text, srs)); |
76 |
} |
77 |
|
78 |
private static Geometry geometryFromText(String text, String srs) |
79 |
throws ParseException { |
80 |
if (!lastTextGeometry.equals(text) || !lastSRS.equals(srs)) {
|
81 |
try {
|
82 |
lastGeometry = geomManager.createFrom(text, srs); |
83 |
} catch (CreateGeometryException e) {
|
84 |
throw new ParseException(NAME, e); |
85 |
} catch (LocatorException e) {
|
86 |
throw new ParseException(NAME, e); |
87 |
} catch (GeometryException e) {
|
88 |
throw new ParseException(NAME, e); |
89 |
} |
90 |
lastTextGeometry = text; |
91 |
lastSRS = srs; |
92 |
} |
93 |
return lastGeometry;
|
94 |
} |
95 |
} |