Revision 35263
tags/v2_0_0_Build_2026/libEvaluator_SQLJEP/src/org/gvsig/tools/evaluator/sqljep/SQLJEPEvaluator.java | ||
---|---|---|
1 |
package org.gvsig.tools.evaluator.sqljep; |
|
2 |
|
|
3 |
import java.util.Map; |
|
4 |
import java.util.Map.Entry; |
|
5 |
|
|
6 |
import org.gvsig.tools.evaluator.Evaluator; |
|
7 |
import org.gvsig.tools.evaluator.EvaluatorData; |
|
8 |
import org.gvsig.tools.evaluator.EvaluatorFieldValue; |
|
9 |
import org.gvsig.tools.evaluator.EvaluatorFieldsInfo; |
|
10 |
import org.medfoster.sqljep.BaseJEP; |
|
11 |
import org.medfoster.sqljep.ParseException; |
|
12 |
|
|
13 |
public class SQLJEPEvaluator extends BaseJEP implements Evaluator { |
|
14 |
|
|
15 |
private String expresion; |
|
16 |
private EvaluatorData data; |
|
17 |
private boolean not_parsed; |
|
18 |
|
|
19 |
public SQLJEPEvaluator(String expresion) { |
|
20 |
super(expresion); |
|
21 |
this.expresion = expresion; |
|
22 |
this.data = null; |
|
23 |
not_parsed = true; |
|
24 |
} |
|
25 |
|
|
26 |
public String getName() { |
|
27 |
return "SQLJEP(" + expresion + ")"; |
|
28 |
} |
|
29 |
|
|
30 |
public String getSQL() { |
|
31 |
return expresion; |
|
32 |
} |
|
33 |
|
|
34 |
public String getDescription() { |
|
35 |
return null; |
|
36 |
} |
|
37 |
|
|
38 |
public EvaluatorFieldValue[] getFieldValues(String name) { |
|
39 |
return null; |
|
40 |
} |
|
41 |
|
|
42 |
public Object evaluate(EvaluatorData data) { |
|
43 |
this.data = data; |
|
44 |
Object value = null; |
|
45 |
try { |
|
46 |
if (not_parsed) { |
|
47 |
this.parseExpression(); |
|
48 |
not_parsed = false; |
|
49 |
} |
|
50 |
value = this.getValue(); |
|
51 |
} catch (ParseException e) { |
|
52 |
// TODO Auto-generated catch block |
|
53 |
e.printStackTrace(); |
|
54 |
} |
|
55 |
this.data = null; |
|
56 |
return value; |
|
57 |
} |
|
58 |
|
|
59 |
public int findColumn(String name) { |
|
60 |
return -1; |
|
61 |
} |
|
62 |
|
|
63 |
public Comparable getColumnObject(int arg0) throws ParseException { |
|
64 |
return null; |
|
65 |
} |
|
66 |
|
|
67 |
public Entry getVariable(String name) throws ParseException { |
|
68 |
return new MyEntry(name); |
|
69 |
} |
|
70 |
|
|
71 |
private class MyEntry implements Map.Entry { |
|
72 |
private String key; |
|
73 |
|
|
74 |
public MyEntry(String key) { |
|
75 |
this.key = key; |
|
76 |
} |
|
77 |
|
|
78 |
public Object getKey() { |
|
79 |
return this.key; |
|
80 |
} |
|
81 |
|
|
82 |
public Object getValue() { |
|
83 |
if (data.hasDataValue(key)) { |
|
84 |
return data.getDataValue(key); |
|
85 |
} |
|
86 |
return data.getDataValue(key); |
|
87 |
} |
|
88 |
|
|
89 |
public Object setValue(Object arg0) { |
|
90 |
return null; |
|
91 |
} |
|
92 |
|
|
93 |
} |
|
94 |
|
|
95 |
public EvaluatorFieldsInfo getFieldsInfo() { |
|
96 |
// TODO Auto-generated method stub |
|
97 |
return null; |
|
98 |
} |
|
99 |
} |
|
0 | 100 |
tags/v2_0_0_Build_2026/libEvaluator_SQLJEP/src/org/gvsig/tools/evaluator/sqljep/SQLJEPLibrary.java | ||
---|---|---|
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 |
*/ |
|
22 |
package org.gvsig.tools.evaluator.sqljep; |
|
23 |
|
|
24 |
import org.medfoster.sqljep.BaseJEP; |
|
25 |
import org.medfoster.sqljep.function.ToDate; |
|
26 |
|
|
27 |
import org.gvsig.fmap.geom.GeometryLibrary; |
|
28 |
import org.gvsig.tools.ToolsLibrary; |
|
29 |
import org.gvsig.tools.evaluator.sqljep.function.Boundary; |
|
30 |
import org.gvsig.tools.evaluator.sqljep.function.Equals; |
|
31 |
import org.gvsig.tools.evaluator.sqljep.function.GeomFromText; |
|
32 |
import org.gvsig.tools.evaluator.sqljep.function.Intersects; |
|
33 |
import org.gvsig.tools.evaluator.sqljep.function.Overlaps; |
|
34 |
import org.gvsig.tools.library.AbstractLibrary; |
|
35 |
import org.gvsig.tools.library.LibraryException; |
|
36 |
|
|
37 |
public class SQLJEPLibrary extends AbstractLibrary { |
|
38 |
|
|
39 |
@Override |
|
40 |
public void doRegistration() { |
|
41 |
registerAsServiceOf(ToolsLibrary.class); |
|
42 |
require(GeometryLibrary.class); |
|
43 |
} |
|
44 |
|
|
45 |
@Override |
|
46 |
protected void doInitialize() throws LibraryException { |
|
47 |
} |
|
48 |
|
|
49 |
@Override |
|
50 |
protected void doPostInitialize() throws LibraryException { |
|
51 |
BaseJEP.addFunction(Equals.NAME, new Equals()); |
|
52 |
BaseJEP.addFunction(GeomFromText.NAME, new GeomFromText()); |
|
53 |
BaseJEP.addFunction(Intersects.NAME, new Intersects()); |
|
54 |
BaseJEP.addFunction(Overlaps.NAME, new Overlaps()); |
|
55 |
BaseJEP.addFunction(Boundary.NAME, new Boundary()); |
|
56 |
BaseJEP.addFunction("to_timestamp", new ToDate()); |
|
57 |
} |
|
58 |
} |
|
0 | 59 |
tags/v2_0_0_Build_2026/libEvaluator_SQLJEP/src/org/gvsig/tools/evaluator/sqljep/function/Equals.java | ||
---|---|---|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
package org.gvsig.tools.evaluator.sqljep.function; |
|
32 |
|
|
33 |
import org.gvsig.fmap.geom.Geometry; |
|
34 |
import org.medfoster.sqljep.ASTFunNode; |
|
35 |
import org.medfoster.sqljep.JepRuntime; |
|
36 |
import org.medfoster.sqljep.ParseException; |
|
37 |
import org.medfoster.sqljep.function.PostfixCommand; |
|
38 |
|
|
39 |
/** |
|
40 |
* @author jmvivo |
|
41 |
* |
|
42 |
*/ |
|
43 |
public class Equals extends PostfixCommand { |
|
44 |
|
|
45 |
public static final String NAME = "equals"; |
|
46 |
|
|
47 |
final public int getNumberOfParameters() { |
|
48 |
return 2; |
|
49 |
} |
|
50 |
/* (non-Javadoc) |
|
51 |
* @see org.medfoster.sqljep.function.PostfixCommand#evaluate(org.medfoster.sqljep.ASTFunNode, org.medfoster.sqljep.JepRuntime) |
|
52 |
*/ |
|
53 |
public void evaluate(ASTFunNode node, JepRuntime runtime) |
|
54 |
throws ParseException { |
|
55 |
node.childrenAccept(runtime.ev, null); |
|
56 |
Comparable param2 = (Comparable)runtime.stack.pop(); |
|
57 |
Comparable param1 = (Comparable)runtime.stack.pop(); |
|
58 |
if (param1 == null || param2 == null) { |
|
59 |
runtime.stack.push(Boolean.FALSE); |
|
60 |
} else if ((param1 instanceof Geometry) |
|
61 |
&& (param2 instanceof Geometry)) { |
|
62 |
runtime.stack.push(new Boolean(isEquals((Geometry)param1, (Geometry)param2))); |
|
63 |
} else{ |
|
64 |
runtime.stack.push(new Boolean(param1.equals(param2))); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
private static boolean isEquals(Geometry g1, Geometry g2) throws ParseException { |
|
69 |
return (g1.equals(g2)); |
|
70 |
} |
|
71 |
|
|
72 |
} |
|
73 |
|
|
0 | 74 |
tags/v2_0_0_Build_2026/libEvaluator_SQLJEP/src/org/gvsig/tools/evaluator/sqljep/function/Overlaps.java | ||
---|---|---|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.tools.evaluator.sqljep.function; |
|
29 |
|
|
30 |
import org.gvsig.fmap.geom.Geometry; |
|
31 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
32 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
33 |
import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext; |
|
34 |
import org.medfoster.sqljep.ASTFunNode; |
|
35 |
import org.medfoster.sqljep.JepRuntime; |
|
36 |
import org.medfoster.sqljep.ParseException; |
|
37 |
import org.medfoster.sqljep.function.PostfixCommand; |
|
38 |
|
|
39 |
public class Overlaps extends PostfixCommand { |
|
40 |
|
|
41 |
public static final String NAME = "overlaps"; |
|
42 |
|
|
43 |
final public int getNumberOfParameters() { |
|
44 |
return 2; |
|
45 |
} |
|
46 |
|
|
47 |
/* (non-Javadoc) |
|
48 |
* @see org.medfoster.sqljep.function.PostfixCommand#evaluate(org.medfoster.sqljep.ASTFunNode, org.medfoster.sqljep.JepRuntime) |
|
49 |
*/ |
|
50 |
public void evaluate(ASTFunNode node, JepRuntime runtime) |
|
51 |
throws ParseException { |
|
52 |
node.childrenAccept(runtime.ev, null); |
|
53 |
Geometry geom1 = (Geometry)runtime.stack.pop(); |
|
54 |
Geometry geom2 = (Geometry)runtime.stack.pop(); |
|
55 |
runtime.stack.push(overlaps(geom1, geom2)); |
|
56 |
} |
|
57 |
|
|
58 |
private static Boolean overlaps(Geometry geom1, Geometry geom2) throws ParseException { |
|
59 |
try { |
|
60 |
return (Boolean) geom1.invokeOperation( |
|
61 |
org.gvsig.fmap.geom.operation.relationship.Overlaps.CODE, |
|
62 |
new DefaultRelationshipGeometryOperationContext(geom2)); |
|
63 |
} catch (GeometryOperationNotSupportedException e) { |
|
64 |
throw new ParseException(NAME, e); |
|
65 |
} catch (GeometryOperationException e) { |
|
66 |
throw new ParseException(NAME, e); |
|
67 |
} |
|
68 |
} |
|
69 |
|
|
70 |
} |
|
0 | 71 |
tags/v2_0_0_Build_2026/libEvaluator_SQLJEP/src/org/gvsig/tools/evaluator/sqljep/function/GeomFromText.java | ||
---|---|---|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.tools.evaluator.sqljep.function; |
|
29 |
|
|
30 |
import org.gvsig.fmap.geom.Geometry; |
|
31 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
32 |
import org.gvsig.fmap.geom.GeometryManager; |
|
33 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
|
34 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
35 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
36 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
37 |
import org.gvsig.fmap.geom.operation.fromwkt.FromWKT; |
|
38 |
import org.gvsig.fmap.geom.operation.fromwkt.FromWKTGeometryOperationContext; |
|
39 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
|
40 |
import org.medfoster.sqljep.ASTFunNode; |
|
41 |
import org.medfoster.sqljep.JepRuntime; |
|
42 |
import org.medfoster.sqljep.ParseException; |
|
43 |
import org.medfoster.sqljep.function.PostfixCommand; |
|
44 |
import org.slf4j.Logger; |
|
45 |
import org.slf4j.LoggerFactory; |
|
46 |
|
|
47 |
public class GeomFromText extends PostfixCommand { |
|
48 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
49 |
private static final Logger logger = LoggerFactory.getLogger(GeomFromText.class); |
|
50 |
|
|
51 |
private static Geometry nullGeometry = null; |
|
52 |
private static Object lock = new Object(); |
|
53 |
|
|
54 |
public static final String NAME = "GeomFromText"; |
|
55 |
private static String lastTextGeometry=""; |
|
56 |
private static String lastSRS=""; |
|
57 |
private static Geometry lastGeometry=null; |
|
58 |
|
|
59 |
final public int getNumberOfParameters() { |
|
60 |
return 2; |
|
61 |
} |
|
62 |
|
|
63 |
public GeomFromText() { |
|
64 |
super(); |
|
65 |
} |
|
66 |
|
|
67 |
/* |
|
68 |
* (non-Javadoc) |
|
69 |
* |
|
70 |
* @see org.medfoster.sqljep.function.PostfixCommand#evaluate(org.medfoster.sqljep.ASTFunNode, |
|
71 |
* org.medfoster.sqljep.JepRuntime) |
|
72 |
*/ |
|
73 |
public void evaluate(ASTFunNode node, JepRuntime runtime) |
|
74 |
throws ParseException { |
|
75 |
node.childrenAccept(runtime.ev, null); |
|
76 |
String srs = (String) runtime.stack.pop(); |
|
77 |
String text = (String) runtime.stack.pop(); |
|
78 |
runtime.stack.push(geometryFromText(text, srs)); |
|
79 |
} |
|
80 |
|
|
81 |
private static Geometry geometryFromText(String text, String srs) |
|
82 |
throws ParseException { |
|
83 |
if (!lastTextGeometry.equals(text) || !lastSRS.equals(srs)) { |
|
84 |
try { |
|
85 |
lastGeometry = (Geometry) nullGeometry.invokeOperation( |
|
86 |
FromWKT.CODE, |
|
87 |
new FromWKTGeometryOperationContext(text,srs) |
|
88 |
); |
|
89 |
} catch (GeometryOperationNotSupportedException e) { |
|
90 |
throw new ParseException(NAME, e); |
|
91 |
} catch (GeometryOperationException e) { |
|
92 |
throw new ParseException(NAME, e); |
|
93 |
} |
|
94 |
lastTextGeometry = text; |
|
95 |
lastSRS = srs; |
|
96 |
} |
|
97 |
return lastGeometry; |
|
98 |
} |
|
99 |
|
|
100 |
private static Geometry getNullGeometry() { |
|
101 |
synchronized (lock) { |
|
102 |
if (nullGeometry == null) { |
|
103 |
try { |
|
104 |
nullGeometry = geomManager.createNullGeometry(SUBTYPES.GEOM2D); |
|
105 |
} catch (CreateGeometryException e) { |
|
106 |
logger.error("Error creating a null geometry", e); |
|
107 |
} |
|
108 |
} |
|
109 |
} |
|
110 |
return nullGeometry; |
|
111 |
} |
|
112 |
|
|
113 |
} |
|
0 | 114 |
tags/v2_0_0_Build_2026/libEvaluator_SQLJEP/src/org/gvsig/tools/evaluator/sqljep/function/Boundary.java | ||
---|---|---|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
/** |
|
29 |
* |
|
30 |
*/ |
|
31 |
package org.gvsig.tools.evaluator.sqljep.function; |
|
32 |
|
|
33 |
import org.gvsig.fmap.geom.Geometry; |
|
34 |
import org.medfoster.sqljep.ASTFunNode; |
|
35 |
import org.medfoster.sqljep.JepRuntime; |
|
36 |
import org.medfoster.sqljep.ParseException; |
|
37 |
import org.medfoster.sqljep.function.PostfixCommand; |
|
38 |
|
|
39 |
/** |
|
40 |
* @author jmvivo |
|
41 |
* |
|
42 |
*/ |
|
43 |
public class Boundary extends PostfixCommand { |
|
44 |
|
|
45 |
public static final String NAME = "boundary"; |
|
46 |
|
|
47 |
final public int getNumberOfParameters() { |
|
48 |
return 1; |
|
49 |
} |
|
50 |
/* (non-Javadoc) |
|
51 |
* @see org.medfoster.sqljep.function.PostfixCommand#evaluate(org.medfoster.sqljep.ASTFunNode, org.medfoster.sqljep.JepRuntime) |
|
52 |
*/ |
|
53 |
public void evaluate(ASTFunNode node, JepRuntime runtime) |
|
54 |
throws ParseException { |
|
55 |
node.childrenAccept(runtime.ev, null); |
|
56 |
Comparable param1 = (Comparable)runtime.stack.pop(); |
|
57 |
if (param1 == null) { |
|
58 |
runtime.stack.push(null); |
|
59 |
} else{ |
|
60 |
runtime.stack.push(Boundary.boundary((Geometry) param1)); |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
private static Geometry boundary(Geometry g) |
|
65 |
throws ParseException { |
|
66 |
return g.getEnvelope().getGeometry(); |
|
67 |
} |
|
68 |
|
|
69 |
} |
|
70 |
|
|
0 | 71 |
tags/v2_0_0_Build_2026/libEvaluator_SQLJEP/src/org/gvsig/tools/evaluator/sqljep/function/Intersects.java | ||
---|---|---|
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 |
*/ |
|
22 |
|
|
23 |
/* |
|
24 |
* AUTHORS (In addition to CIT): |
|
25 |
* 2008 IVER T.I. S.A. {{Task}} |
|
26 |
*/ |
|
27 |
|
|
28 |
package org.gvsig.tools.evaluator.sqljep.function; |
|
29 |
|
|
30 |
import org.gvsig.fmap.geom.Geometry; |
|
31 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
|
32 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
|
33 |
import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext; |
|
34 |
import org.medfoster.sqljep.ASTFunNode; |
|
35 |
import org.medfoster.sqljep.JepRuntime; |
|
36 |
import org.medfoster.sqljep.ParseException; |
|
37 |
import org.medfoster.sqljep.function.PostfixCommand; |
|
38 |
|
|
39 |
public class Intersects extends PostfixCommand { |
|
40 |
|
|
41 |
public static final String NAME = "intersects"; |
|
42 |
|
|
43 |
final public int getNumberOfParameters() { |
|
44 |
return 2; |
|
45 |
} |
|
46 |
|
|
47 |
/* (non-Javadoc) |
|
48 |
* @see org.medfoster.sqljep.function.PostfixCommand#evaluate(org.medfoster.sqljep.ASTFunNode, org.medfoster.sqljep.JepRuntime) |
|
49 |
*/ |
|
50 |
public void evaluate(ASTFunNode node, JepRuntime runtime) |
|
51 |
throws ParseException { |
|
52 |
node.childrenAccept(runtime.ev, null); |
|
53 |
Geometry geom1 = (Geometry)runtime.stack.pop(); |
|
54 |
Geometry geom2 = (Geometry)runtime.stack.pop(); |
|
55 |
runtime.stack.push(intersects(geom1, geom2)); |
|
56 |
} |
|
57 |
|
|
58 |
private static Boolean intersects(Geometry geom1, Geometry geom2) |
|
59 |
throws ParseException { |
|
60 |
try { |
|
61 |
// if (!geom1.getBounds2D().intersects(geom2.getBounds2D())){ |
|
62 |
// return new Boolean(false); |
|
63 |
// } |
|
64 |
return (Boolean) geom1.invokeOperation( |
|
65 |
org.gvsig.fmap.geom.operation.relationship.Intersects.CODE, |
|
66 |
new DefaultRelationshipGeometryOperationContext(geom2)); |
|
67 |
} catch (GeometryOperationNotSupportedException e) { |
|
68 |
throw new ParseException(NAME, e); |
|
69 |
} catch (GeometryOperationException e) { |
|
70 |
throw new ParseException(NAME, e); |
|
71 |
} |
|
72 |
} |
|
73 |
|
|
74 |
} |
|
0 | 75 |
tags/v2_0_0_Build_2026/libEvaluator_SQLJEP/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="UTF-8"?> |
|
2 |
|
|
3 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
|
4 |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 |
|
5 |
http://maven.apache.org/maven-v4_0_0.xsd"> |
|
6 |
<parent> |
|
7 |
<artifactId>gvsig-base-library-pom</artifactId> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<version>2.0-SNAPSHOT</version> |
|
10 |
</parent> |
|
11 |
<distributionManagement> |
|
12 |
<site> |
|
13 |
<id>gvsig-repository</id> |
|
14 |
<url>${site-repository}/</url> |
|
15 |
</site> |
|
16 |
</distributionManagement> |
|
17 |
|
|
18 |
<modelVersion>4.0.0</modelVersion> |
|
19 |
<groupId>org.gvsig</groupId> |
|
20 |
<artifactId>org.gvsig.tools.evaluator.sqljep</artifactId> |
|
21 |
<name>libEvaluator_SQLJEP</name> |
|
22 |
<version>2.0-SNAPSHOT</version> |
|
23 |
<url>http://gvsig.org</url> |
|
24 |
<properties> |
|
25 |
<build-dir>${basedir}/../build</build-dir> |
|
26 |
<eclipse.project.name>libEvaluator_SQLJEP</eclipse.project.name> |
|
27 |
</properties> |
|
28 |
<dependencies> |
|
29 |
<dependency> |
|
30 |
<groupId>org.gvsig</groupId> |
|
31 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
32 |
<scope>compile</scope> |
|
33 |
</dependency> |
|
34 |
<dependency> |
|
35 |
<groupId>org.gvsig</groupId> |
|
36 |
<artifactId>org.gvsig.fmap.geometry</artifactId> |
|
37 |
<scope>compile</scope> |
|
38 |
</dependency> |
|
39 |
<dependency> |
|
40 |
<groupId>org.gvsig</groupId> |
|
41 |
<artifactId>org.gvsig.fmap.geometry</artifactId> |
|
42 |
<classifier>operation</classifier> |
|
43 |
<scope>compile</scope> |
|
44 |
</dependency> |
|
45 |
<dependency> |
|
46 |
<groupId>org.slf4j</groupId> |
|
47 |
<artifactId>slf4j-api</artifactId> |
|
48 |
<scope>compile</scope> |
|
49 |
</dependency> |
|
50 |
<dependency> |
|
51 |
<groupId>net.sf</groupId> |
|
52 |
<artifactId>sqljep</artifactId> |
|
53 |
<scope>compile</scope> |
|
54 |
</dependency> |
|
55 |
</dependencies> |
|
56 |
<build> |
|
57 |
<sourceDirectory>src</sourceDirectory> |
|
58 |
<testSourceDirectory>src-test</testSourceDirectory> |
|
59 |
<resources> |
|
60 |
<resource> |
|
61 |
<directory>${basedir}/resources</directory> |
|
62 |
</resource> |
|
63 |
</resources> |
|
64 |
<plugins> |
|
65 |
<!-- TODO: MAKE TESTS WORK AND REMOVE THIS OPTION --> |
|
66 |
<plugin> |
|
67 |
<groupId>org.apache.maven.plugins</groupId> |
|
68 |
<artifactId>maven-surefire-plugin</artifactId> |
|
69 |
<configuration> |
|
70 |
<skipTests>true</skipTests> |
|
71 |
</configuration> |
|
72 |
</plugin> |
|
73 |
</plugins> |
|
74 |
</build> |
|
75 |
</project> |
|
0 | 76 |
tags/v2_0_0_Build_2026/libEvaluator_SQLJEP/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.tools.evaluator.sqljep.SQLJEPLibrary |
|
0 | 2 |
Also available in: Unified diff