Revision 46365
tags/org.gvsig.desktop-2.0.369/license.txt | ||
---|---|---|
1 |
gvSIG. Desktop Geographic Information System. |
|
2 |
|
|
3 |
Copyright (C) 2007-2020 gvSIG Association. |
|
4 |
|
|
5 |
This program is free software; you can redistribute it and/or |
|
6 |
modify it under the terms of the GNU General Public License |
|
7 |
as published by the Free Software Foundation; either version 3 |
|
8 |
of the License, or (at your option) any later version. |
|
9 |
|
|
10 |
This program is distributed in the hope that it will be useful, |
|
11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
GNU General Public License for more details. |
|
14 |
|
|
15 |
You should have received a copy of the GNU General Public License |
|
16 |
along with this program. If not, see <https://www.gnu.org/licenses/>. |
|
17 |
|
|
18 |
For any additional information, do not hesitate to contact us |
|
19 |
at info AT gvsig.com, or visit our website www.gvsig.com. |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<parent> |
|
4 |
<groupId>org.gvsig</groupId> |
|
5 |
<artifactId>org.gvsig.expressionevaluator.geometry</artifactId> |
|
6 |
<version>2.0.369</version> |
|
7 |
</parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.expressionevaluator.geometry.lib</artifactId> |
|
10 |
<packaging>pom</packaging> |
|
11 |
<modules> |
|
12 |
<module>org.gvsig.expressionevaluator.geometry.lib.api</module> |
|
13 |
<module>org.gvsig.expressionevaluator.geometry.lib.impl</module> |
|
14 |
</modules> |
|
15 |
</project> |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.api/src/main/java/org/gvsig/expressionevaluator/GeometryExpressionBuilder.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator; |
|
2 |
|
|
3 |
/** |
|
4 |
* |
|
5 |
* @author jjdelcerro |
|
6 |
*/ |
|
7 |
public interface GeometryExpressionBuilder |
|
8 |
extends ExpressionBuilder, GeometryExpressionBuilderHelper { |
|
9 |
|
|
10 |
} |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.api/src/main/java/org/gvsig/expressionevaluator/GeometryExpressionBuilderHelper.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator; |
|
2 |
|
|
3 |
import org.cresques.cts.IProjection; |
|
4 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Constant; |
|
5 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter; |
|
6 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
|
8 |
import org.gvsig.fmap.geom.Geometry; |
|
9 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
10 |
|
|
11 |
public interface GeometryExpressionBuilderHelper { |
|
12 |
|
|
13 |
public static final String FUNCTION_ST_SRID = "ST_SRID"; |
|
14 |
public static final String FUNCTION_ST_ASTEXT = "ST_AsText"; |
|
15 |
public static final String FUNCTION_ST_ASBINARY = "ST_AsBinary"; |
|
16 |
public static final String FUNCTION_ST_ASEWKB = "ST_AsEWKB"; |
|
17 |
public static final String FUNCTION_ST_ENVELOPE = "ST_Envelope"; |
|
18 |
public static final String FUNCTION_ST_GEOMFROMTEXT = "ST_GeomFromText"; |
|
19 |
public static final String FUNCTION_ST_GEOMFROMWKB = "ST_GeomFromWKB"; |
|
20 |
public static final String FUNCTION_ST_GEOMFROMEWKB = "ST_GeomFromEWKB"; |
|
21 |
public static final String FUNCTION_ST_SIMPLIFY = "ST_Simplify"; |
|
22 |
public static final String FUNCTION_ST_EQUALS = "ST_Equals"; |
|
23 |
public static final String FUNCTION_ST_INTERSECTS = "ST_Intersects"; |
|
24 |
public static final String FUNCTION_ST_CONTAINS = "ST_Contains"; |
|
25 |
public static final String FUNCTION_ST_DISJOINT = "ST_Disjoint"; |
|
26 |
public static final String FUNCTION_ST_CROSSES = "ST_Crosses"; |
|
27 |
public static final String FUNCTION_ST_ISCLOSED = "ST_IsClosed"; |
|
28 |
public static final String FUNCTION_ST_OVERLAPS = "ST_Overlaps"; |
|
29 |
public static final String FUNCTION_ST_TOUCHES = "ST_Touches"; |
|
30 |
public static final String FUNCTION_ST_WITHIN = "ST_Within"; |
|
31 |
public static final String FUNCTION_ST_SETSRID = "ST_SetSRID"; |
|
32 |
public static final String FUNCTION_ST_POINT = "ST_Point"; |
|
33 |
public static final String FUNCTION_ST_MAKEPOINT = "ST_MakePoint"; |
|
34 |
public static final String FUNCTION_ST_UNIONAGGREGATE = "ST_UnionAggregate"; |
|
35 |
public static final String FUNCTION_ST_EXTENTAGGREGATE = "ST_ExtentAggregate"; |
|
36 |
public static final String FUNCTION_ST_FORCE2D = "ST_Force2D"; |
|
37 |
|
|
38 |
public static final int PARAMETER_TYPE_GEOMETRY = 2; |
|
39 |
|
|
40 |
public enum GeometrySupportType { |
|
41 |
WKT, |
|
42 |
WKB, |
|
43 |
EWKB, |
|
44 |
NATIVE |
|
45 |
} |
|
46 |
|
|
47 |
public interface GeometryParameter extends Parameter { |
|
48 |
@Override |
|
49 |
public GeometryParameter as_constant(); |
|
50 |
@Override |
|
51 |
public GeometryParameter as_variable(); |
|
52 |
public GeometryParameter as_geometry_variable(); |
|
53 |
@Override |
|
54 |
public GeometryParameter value(Object value); |
|
55 |
|
|
56 |
@Override |
|
57 |
public GeometryParameter name(String value); |
|
58 |
|
|
59 |
public GeometryParameter srs(IProjection srs); |
|
60 |
|
|
61 |
public GeometryParameter srs(Value srs); |
|
62 |
|
|
63 |
public Value srs(); |
|
64 |
public Geometry geometry(); |
|
65 |
public boolean is_geometry_variable(); |
|
66 |
} |
|
67 |
|
|
68 |
public ExpressionBuilder builder(); |
|
69 |
|
|
70 |
public GeometrySupportType geometry_support_type(); |
|
71 |
|
|
72 |
public GeometryExpressionBuilderHelper geometry_support_type(GeometrySupportType geometrySupportType); |
|
73 |
|
|
74 |
public Object srs_id(IProjection projection); |
|
75 |
|
|
76 |
public GeometryParameter parameter(Object value); |
|
77 |
|
|
78 |
public GeometryParameter parameter(String name); |
|
79 |
|
|
80 |
public GeometryParameter parameter(); |
|
81 |
|
|
82 |
public Constant geometry(Geometry geom, IProjection srs); |
|
83 |
|
|
84 |
public Constant geometry(Geometry geom); |
|
85 |
|
|
86 |
public Constant envelope(Envelope envelope, IProjection srs); |
|
87 |
|
|
88 |
public Constant envelope(Envelope envelope); |
|
89 |
|
|
90 |
public Constant srs(IProjection srs); |
|
91 |
|
|
92 |
public Function as_geometry(Value value); |
|
93 |
|
|
94 |
public Function ST_Area(Value geom); |
|
95 |
|
|
96 |
public Function ST_AsBinary(Value geom); |
|
97 |
|
|
98 |
public Function ST_AsEWKB(Value geom); |
|
99 |
|
|
100 |
public Function ST_AsText(Value geom); |
|
101 |
|
|
102 |
public Function ST_Buffer(Value geom); |
|
103 |
|
|
104 |
public Function ST_Buffer(Value geom, Value dist); |
|
105 |
|
|
106 |
public Function ST_Centroid(Value geom); |
|
107 |
|
|
108 |
public Function ST_Contains(Value geom1, Value geom2); |
|
109 |
|
|
110 |
public Function ST_CoveredBy(Value geom1, Value geom2); |
|
111 |
|
|
112 |
public Function ST_Covers(Value geom1, Value geom2); |
|
113 |
|
|
114 |
public Function ST_Crosses(Value geom1, Value geom2); |
|
115 |
|
|
116 |
public Function ST_Diference(Value geom1, Value geom2); |
|
117 |
|
|
118 |
public Function ST_Dimension(Value geom1); |
|
119 |
|
|
120 |
public Function ST_Disjoint(Value geom1, Value geom2); |
|
121 |
|
|
122 |
public Function ST_Distance(Value geom1, Value geom2); |
|
123 |
|
|
124 |
public Function ST_EndPoint(Value geom1); |
|
125 |
|
|
126 |
public Function ST_Envelope(Value geom); |
|
127 |
|
|
128 |
public Function ST_Equals(Value geom1, Value geom2); |
|
129 |
|
|
130 |
public Function ST_GeomFromText(Value geom, Value crs); |
|
131 |
|
|
132 |
public Function ST_GeomFromWKB(Value geom, Value crs); |
|
133 |
|
|
134 |
public Function ST_GeomFromEWKB(Value geom, Value crs); |
|
135 |
|
|
136 |
public Function ST_Intersection(Value geom1, Value geom2); |
|
137 |
|
|
138 |
public Function ST_Intersects(Value geom1, Value geom2); |
|
139 |
|
|
140 |
public Function ST_IsClosed(Value geom); |
|
141 |
|
|
142 |
public Function ST_IsSimple(Value geom); |
|
143 |
|
|
144 |
public Function ST_IsValid(Value geom); |
|
145 |
|
|
146 |
public Function ST_Force2D(Value geom); |
|
147 |
|
|
148 |
public Function ST_NumGeometries(Value geom); |
|
149 |
|
|
150 |
public Function ST_NumPoints(Value geom); |
|
151 |
|
|
152 |
public Function ST_Overlaps(Value geom1, Value geom2); |
|
153 |
|
|
154 |
public Function ST_Perimeter(Value geom); |
|
155 |
|
|
156 |
public Function ST_Point(Value x, Value y); |
|
157 |
|
|
158 |
public Function ST_MakePoint(Value x, Value y); |
|
159 |
|
|
160 |
public Function ST_MakePoint(Value x, Value y, Value z); |
|
161 |
|
|
162 |
public Function ST_MakePoint(Value x, Value y, Value z, Value m); |
|
163 |
|
|
164 |
public Function ST_PointN(Value geom, Value n); |
|
165 |
|
|
166 |
public Function ST_SRID(Value geom); |
|
167 |
|
|
168 |
public Function ST_SetSRID(Value geom, Value srid); |
|
169 |
|
|
170 |
public Function ST_StartPoint(Value geom); |
|
171 |
|
|
172 |
public Function ST_Simplify(Value geom, Value tolerance); |
|
173 |
|
|
174 |
public Function ST_Touches(Value geom1, Value geom2); |
|
175 |
|
|
176 |
public Function ST_Union(Value geom1, Value geom2); |
|
177 |
|
|
178 |
public Function ST_Within(Value geom1, Value geom2); |
|
179 |
|
|
180 |
public Function ST_X(Value geom); |
|
181 |
|
|
182 |
public Function ST_Y(Value geom); |
|
183 |
|
|
184 |
public Function ST_Z(Value geom); |
|
185 |
|
|
186 |
public Function ST_UnionAggregate(Value geom); |
|
187 |
|
|
188 |
public Function ST_ExtentAggregate(Value geom); |
|
189 |
|
|
190 |
} |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.api/src/main/java/org/gvsig/expressionevaluator/GeometryExpressionEvaluatorLocator.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator; |
|
2 |
|
|
3 |
import org.gvsig.tools.locator.AbstractLocator; |
|
4 |
import org.gvsig.tools.locator.LocatorException; |
|
5 |
|
|
6 |
|
|
7 |
public class GeometryExpressionEvaluatorLocator extends AbstractLocator { |
|
8 |
|
|
9 |
private static final String LOCATOR_NAME = "GeometryExpressionEvaluatorLocator"; |
|
10 |
|
|
11 |
public static final String MANAGER_NAME = "GeometryExpressionEvaluatorManager"; |
|
12 |
|
|
13 |
private static final String MANAGER_DESCRIPTION = "GeometryExpressionEvaluator of gvSIG"; |
|
14 |
|
|
15 |
/** |
|
16 |
* Unique instance. |
|
17 |
*/ |
|
18 |
private static final GeometryExpressionEvaluatorLocator INSTANCE = new GeometryExpressionEvaluatorLocator(); |
|
19 |
|
|
20 |
/** |
|
21 |
* Return the singleton instance. |
|
22 |
* |
|
23 |
* @return the singleton instance |
|
24 |
*/ |
|
25 |
public static GeometryExpressionEvaluatorLocator getInstance() { |
|
26 |
return INSTANCE; |
|
27 |
} |
|
28 |
|
|
29 |
/** |
|
30 |
* Returns the Locator name. |
|
31 |
* |
|
32 |
* @return String containing the locator name. |
|
33 |
*/ |
|
34 |
@Override |
|
35 |
public String getLocatorName() { |
|
36 |
return LOCATOR_NAME; |
|
37 |
} |
|
38 |
|
|
39 |
public static GeometryExpressionEvaluatorManager getManager() throws LocatorException { |
|
40 |
return (GeometryExpressionEvaluatorManager) getInstance().get(MANAGER_NAME); |
|
41 |
} |
|
42 |
|
|
43 |
public static GeometryExpressionEvaluatorManager getGeometryExpressionEvaluatorManager() throws LocatorException { |
|
44 |
return getManager(); |
|
45 |
} |
|
46 |
|
|
47 |
public static void registerManager(Class clazz) { |
|
48 |
getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz); |
|
49 |
} |
|
50 |
|
|
51 |
public static void registerDefaultManager(Class clazz) { |
|
52 |
getInstance().registerDefault(MANAGER_NAME, MANAGER_DESCRIPTION, clazz); |
|
53 |
} |
|
54 |
|
|
55 |
} |
|
0 | 56 |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.api/src/main/java/org/gvsig/expressionevaluator/GeometryExpressionEvaluatorLibrary.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator; |
|
2 |
|
|
3 |
import org.cresques.ProjectionLibrary; |
|
4 |
import org.gvsig.fmap.geom.GeometryLibrary; |
|
5 |
import org.gvsig.tools.ToolsLibrary; |
|
6 |
import org.gvsig.tools.ToolsLocator; |
|
7 |
import org.gvsig.tools.dataTypes.DataTypesManager; |
|
8 |
import org.gvsig.tools.library.AbstractLibrary; |
|
9 |
import org.gvsig.tools.library.LibraryException; |
|
10 |
|
|
11 |
public class GeometryExpressionEvaluatorLibrary extends AbstractLibrary { |
|
12 |
|
|
13 |
@Override |
|
14 |
public void doRegistration() { |
|
15 |
registerAsAPI(GeometryExpressionEvaluatorLibrary.class); |
|
16 |
require(ToolsLibrary.class); |
|
17 |
require(ProjectionLibrary.class); |
|
18 |
require(GeometryLibrary.class); |
|
19 |
require(ExpressionEvaluatorLibrary.class); |
|
20 |
} |
|
21 |
|
|
22 |
@Override |
|
23 |
protected void doInitialize() throws LibraryException { |
|
24 |
} |
|
25 |
|
|
26 |
@Override |
|
27 |
protected void doPostInitialize() throws LibraryException { |
|
28 |
// DataTypesManager dataTypesManager = ToolsLocator.getDataTypesManager(); |
|
29 |
// dataTypesManager.addtype(DataTypes.EXPRESSION, "Expression", "Expression", |
|
30 |
// Expression.class, null); |
|
31 |
|
|
32 |
} |
|
33 |
} |
|
34 |
|
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.api/src/main/java/org/gvsig/expressionevaluator/GeometryExpressionEvaluatorManager.java | ||
---|---|---|
1 |
|
|
2 |
package org.gvsig.expressionevaluator; |
|
3 |
|
|
4 |
|
|
5 |
public interface GeometryExpressionEvaluatorManager { |
|
6 |
|
|
7 |
public GeometryExpressionBuilder createExpressionBuilder(); |
|
8 |
|
|
9 |
|
|
10 |
} |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.api/src/main/java/org/gvsig/expressionevaluator/spi/AbstractGeometryFunction.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator.spi; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.InputStream; |
|
5 |
import java.net.URI; |
|
6 |
import java.net.URISyntaxException; |
|
7 |
import java.net.URL; |
|
8 |
import java.time.LocalDateTime; |
|
9 |
import java.time.ZoneId; |
|
10 |
import java.time.temporal.TemporalAccessor; |
|
11 |
import java.util.ArrayList; |
|
12 |
import java.util.Date; |
|
13 |
import java.util.List; |
|
14 |
import java.util.Locale; |
|
15 |
import java.util.Objects; |
|
16 |
import org.apache.commons.io.IOUtils; |
|
17 |
import org.apache.commons.lang3.BooleanUtils; |
|
18 |
import org.apache.commons.lang3.Range; |
|
19 |
import org.apache.commons.lang3.StringUtils; |
|
20 |
import org.apache.commons.math.util.MathUtils; |
|
21 |
import org.gvsig.expressionevaluator.Code; |
|
22 |
import org.gvsig.expressionevaluator.Codes; |
|
23 |
import org.gvsig.expressionevaluator.Function; |
|
24 |
import org.gvsig.expressionevaluator.I18N; |
|
25 |
import org.gvsig.expressionevaluator.Interpreter; |
|
26 |
import org.gvsig.fmap.geom.Geometry; |
|
27 |
import org.gvsig.fmap.geom.primitive.Point; |
|
28 |
import org.json.JSONArray; |
|
29 |
import org.json.JSONObject; |
|
30 |
|
|
31 |
@SuppressWarnings("UseSpecificCatch") |
|
32 |
public abstract class AbstractGeometryFunction |
|
33 |
extends AbstractFunction |
|
34 |
implements Function |
|
35 |
{ |
|
36 |
|
|
37 |
protected AbstractGeometryFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType, boolean sqlCompatible) { |
|
38 |
super(group, name, argc, description, template, descriptionArgs, returnType, sqlCompatible); |
|
39 |
} |
|
40 |
|
|
41 |
protected AbstractGeometryFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs, String returnType) { |
|
42 |
this(group, name, argc, description, template, descriptionArgs, returnType, false); |
|
43 |
} |
|
44 |
|
|
45 |
protected AbstractGeometryFunction(String group, String name, Range argc, String description, String template, String[] descriptionArgs) { |
|
46 |
this(group, name, argc, description, template, null, null); |
|
47 |
} |
|
48 |
|
|
49 |
protected AbstractGeometryFunction(String group, String name, Range argc, String description, String template) { |
|
50 |
this(group, name, argc, description, template, null, null); |
|
51 |
} |
|
52 |
|
|
53 |
protected AbstractGeometryFunction(String group, String name, Range argc) { |
|
54 |
this(group, name, argc, null, null, null, null); |
|
55 |
} |
|
56 |
|
|
57 |
|
|
58 |
protected Geometry getGeom(Object[] args, int n) { |
|
59 |
return this.getGeom(args, n, false); |
|
60 |
} |
|
61 |
|
|
62 |
protected Geometry getGeom(Object[] args, int n, boolean allowNull) { |
|
63 |
if( args.length < n ) { |
|
64 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
|
65 |
} |
|
66 |
Object value = args[n]; |
|
67 |
if( value == null ) { |
|
68 |
if( allowNull ) { |
|
69 |
return null; |
|
70 |
} |
|
71 |
throw new IllegalArgumentException(I18N.Illegal_null_value_for_argument_XargnX_of_XIdentifierX_function(name(), n)); |
|
72 |
} |
|
73 |
if( !(value instanceof Geometry) ) { |
|
74 |
String type = value.getClass().getCanonicalName(); |
|
75 |
throw new IllegalArgumentException( |
|
76 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
77 |
I18N.Expected_XexpectedX_and_found_XfoundX("Geometry",type) |
|
78 |
); |
|
79 |
} |
|
80 |
return (Geometry)value; |
|
81 |
} |
|
82 |
|
|
83 |
protected Point getPoint(Object[] args, int n) { |
|
84 |
if( args.length < n ) { |
|
85 |
throw new IllegalArgumentException(I18N.Required_argument_XargnX_and_only_found_XargcX_in_call_to_XIdentifierX(name(), args.length, n)); |
|
86 |
} |
|
87 |
Object value = args[n]; |
|
88 |
if( value == null ) { |
|
89 |
return null; |
|
90 |
} |
|
91 |
if( !(value instanceof Point) ) { |
|
92 |
String type = value.getClass().getCanonicalName(); |
|
93 |
throw new IllegalArgumentException( |
|
94 |
I18N.The_type_of_the_argument_XargnX_for_the_XIdentifierX_function_is_incorrect(name(), n) + " " + |
|
95 |
I18N.Expected_XexpectedX_and_found_XfoundX("Point",type) |
|
96 |
); |
|
97 |
} |
|
98 |
return (Point)value; |
|
99 |
} |
|
100 |
|
|
101 |
} |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.api/src/main/java/org/gvsig/expressionevaluator/GeometryExpressionUtils.java | ||
---|---|---|
1 |
package org.gvsig.expressionevaluator; |
|
2 |
|
|
3 |
/** |
|
4 |
* |
|
5 |
* @author jjdelcerro |
|
6 |
*/ |
|
7 |
public class GeometryExpressionUtils { |
|
8 |
|
|
9 |
|
|
10 |
public static GeometryExpressionBuilder createExpressionBuilder() { |
|
11 |
GeometryExpressionEvaluatorManager manager = GeometryExpressionEvaluatorLocator.getManager(); |
|
12 |
return manager.createExpressionBuilder(); |
|
13 |
} |
|
14 |
|
|
15 |
} |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library | ||
---|---|---|
1 |
org.gvsig.expressionevaluator.GeometryExpressionEvaluatorLibrary |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.api/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<groupId>org.gvsig</groupId> |
|
4 |
<artifactId>org.gvsig.expressionevaluator.geometry.lib.api</artifactId> |
|
5 |
<name>${project.artifactId}</name> |
|
6 |
<parent> |
|
7 |
<groupId>org.gvsig</groupId> |
|
8 |
<artifactId>org.gvsig.expressionevaluator.geometry.lib</artifactId> |
|
9 |
<version>2.0.369</version> |
|
10 |
</parent> |
|
11 |
|
|
12 |
<build> |
|
13 |
<plugins> |
|
14 |
<plugin> |
|
15 |
<groupId>org.apache.maven.plugins</groupId> |
|
16 |
<artifactId>maven-jar-plugin</artifactId> |
|
17 |
<configuration> |
|
18 |
</configuration> |
|
19 |
<executions> |
|
20 |
<!-- Generates a jar file only with the test classes --> |
|
21 |
<execution> |
|
22 |
<goals> |
|
23 |
<goal>test-jar</goal> |
|
24 |
</goals> |
|
25 |
</execution> |
|
26 |
</executions> |
|
27 |
</plugin> |
|
28 |
</plugins> |
|
29 |
</build> |
|
30 |
|
|
31 |
<dependencies> |
|
32 |
<dependency> |
|
33 |
<groupId>org.gvsig</groupId> |
|
34 |
<artifactId>org.gvsig.expressionevaluator.lib.api</artifactId> |
|
35 |
<scope>compile</scope> |
|
36 |
</dependency> |
|
37 |
<dependency> |
|
38 |
<groupId>org.gvsig</groupId> |
|
39 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
40 |
<scope>compile</scope> |
|
41 |
</dependency> |
|
42 |
|
|
43 |
<dependency> |
|
44 |
<groupId>org.gvsig</groupId> |
|
45 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
46 |
<scope>compile</scope> |
|
47 |
</dependency> |
|
48 |
<dependency> |
|
49 |
<groupId>org.gvsig</groupId> |
|
50 |
<artifactId>org.gvsig.proj.lib.api</artifactId> |
|
51 |
<scope>compile</scope> |
|
52 |
</dependency> |
|
53 |
|
|
54 |
<dependency> |
|
55 |
<groupId>org.apache.commons</groupId> |
|
56 |
<artifactId>commons-math</artifactId> |
|
57 |
<scope>compile</scope> |
|
58 |
</dependency> |
|
59 |
<dependency> |
|
60 |
<groupId>org.json</groupId> |
|
61 |
<artifactId>json</artifactId> |
|
62 |
<scope>compile</scope> |
|
63 |
</dependency> |
|
64 |
</dependencies> |
|
65 |
</project> |
|
0 | 66 |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.impl/pom.xml | ||
---|---|---|
1 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
|
2 |
<modelVersion>4.0.0</modelVersion> |
|
3 |
<artifactId>org.gvsig.expressionevaluator.geometry.lib.impl</artifactId> |
|
4 |
<name>${project.artifactId}</name> |
|
5 |
<parent> |
|
6 |
<groupId>org.gvsig</groupId> |
|
7 |
<artifactId>org.gvsig.expressionevaluator.geometry.lib</artifactId> |
|
8 |
<version>2.0.369</version> |
|
9 |
</parent> |
|
10 |
<groupId>org.gvsig</groupId> |
|
11 |
<dependencies> |
|
12 |
<dependency> |
|
13 |
<groupId>org.gvsig</groupId> |
|
14 |
<artifactId>org.gvsig.expressionevaluator.lib.api</artifactId> |
|
15 |
<scope>compile</scope> |
|
16 |
</dependency> |
|
17 |
<dependency> |
|
18 |
<groupId>org.gvsig</groupId> |
|
19 |
<artifactId>org.gvsig.expressionevaluator.geometry.lib.api</artifactId> |
|
20 |
<scope>compile</scope> |
|
21 |
</dependency> |
|
22 |
<dependency> |
|
23 |
<groupId>org.gvsig</groupId> |
|
24 |
<artifactId>org.gvsig.expressionevaluator.lib.impl</artifactId> |
|
25 |
<scope>compile</scope> |
|
26 |
</dependency> |
|
27 |
|
|
28 |
<dependency> |
|
29 |
<groupId>org.gvsig</groupId> |
|
30 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
31 |
<scope>compile</scope> |
|
32 |
</dependency> |
|
33 |
<dependency> |
|
34 |
<groupId>org.gvsig</groupId> |
|
35 |
<artifactId>org.gvsig.proj.lib.api</artifactId> |
|
36 |
<scope>compile</scope> |
|
37 |
</dependency> |
|
38 |
|
|
39 |
<dependency> |
|
40 |
<groupId>org.json</groupId> |
|
41 |
<artifactId>json</artifactId> |
|
42 |
<scope>compile</scope> |
|
43 |
</dependency> |
|
44 |
<dependency> |
|
45 |
<groupId>commons-codec</groupId> |
|
46 |
<artifactId>commons-codec</artifactId> |
|
47 |
<scope>compile</scope> |
|
48 |
</dependency> |
|
49 |
<dependency> |
|
50 |
<groupId>org.apache.commons</groupId> |
|
51 |
<artifactId>commons-text</artifactId> |
|
52 |
<scope>compile</scope> |
|
53 |
</dependency> |
|
54 |
|
|
55 |
<dependency> |
|
56 |
<groupId>org.gvsig</groupId> |
|
57 |
<artifactId>${org.gvsig.fmap.geometry.impl}</artifactId> |
|
58 |
<scope>test</scope> |
|
59 |
</dependency> |
|
60 |
<dependency> |
|
61 |
<groupId>org.gvsig</groupId> |
|
62 |
<artifactId>${org.gvsig.proj.lib.impl}</artifactId> |
|
63 |
<scope>test</scope> |
|
64 |
</dependency> |
|
65 |
|
|
66 |
<!-- |
|
67 |
<dependency> |
|
68 |
<groupId>org.gvsig</groupId> |
|
69 |
<artifactId>org.gvsig.timesupport.lib.impl</artifactId> |
|
70 |
<scope>test</scope> |
|
71 |
</dependency> |
|
72 |
<dependency> |
|
73 |
<groupId>org.gvsig</groupId> |
|
74 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
75 |
<scope>test</scope> |
|
76 |
</dependency> |
|
77 |
<dependency> |
|
78 |
<groupId>org.gvsig</groupId> |
|
79 |
<artifactId>org.gvsig.tools.swing.impl</artifactId> |
|
80 |
<scope>test</scope> |
|
81 |
</dependency> |
|
82 |
<dependency> |
|
83 |
<groupId>org.gvsig</groupId> |
|
84 |
<artifactId>org.gvsig.tools.swing.api</artifactId> |
|
85 |
<scope>test</scope> |
|
86 |
</dependency> |
|
87 |
--> |
|
88 |
<dependency> |
|
89 |
<groupId>org.gvsig</groupId> |
|
90 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
91 |
<scope>compile</scope> |
|
92 |
</dependency> |
|
93 |
</dependencies> |
|
94 |
|
|
95 |
<build> |
|
96 |
<plugins> |
|
97 |
|
|
98 |
<!-- Skip test execution ? --> |
|
99 |
<!-- Ignore test execution failure ? --> |
|
100 |
<plugin> |
|
101 |
<groupId>org.apache.maven.plugins</groupId> |
|
102 |
<artifactId>maven-surefire-plugin</artifactId> |
|
103 |
<configuration> |
|
104 |
<skipTests>false</skipTests> |
|
105 |
<testFailureIgnore>false</testFailureIgnore> |
|
106 |
</configuration> |
|
107 |
</plugin> |
|
108 |
|
|
109 |
<!-- Skip test compilation ? --> |
|
110 |
<plugin> |
|
111 |
<groupId>org.apache.maven.plugins</groupId> |
|
112 |
<artifactId>maven-compiler-plugin</artifactId> |
|
113 |
<executions> |
|
114 |
<execution> |
|
115 |
<id>default-testCompile</id> |
|
116 |
<phase>process-test-sources</phase> |
|
117 |
<goals> |
|
118 |
<goal>testCompile</goal> |
|
119 |
</goals> |
|
120 |
<configuration> |
|
121 |
<skip>false</skip> |
|
122 |
</configuration> |
|
123 |
</execution> |
|
124 |
</executions> |
|
125 |
</plugin> |
|
126 |
|
|
127 |
|
|
128 |
</plugins> |
|
129 |
</build> |
|
130 |
|
|
131 |
</project> |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestCodeToValue.java | ||
---|---|---|
1 |
package org.gvsig.expresionevaluator.impl; |
|
2 |
|
|
3 |
import junit.framework.TestCase; |
|
4 |
import org.cresques.cts.IProjection; |
|
5 |
import org.gvsig.expressionevaluator.Code; |
|
6 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
8 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
9 |
import org.gvsig.expressionevaluator.GeometryExpressionUtils; |
|
10 |
import org.gvsig.expressionevaluator.LexicalAnalyzer; |
|
11 |
import org.gvsig.fmap.crs.CRSFactory; |
|
12 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
13 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
14 |
import org.gvsig.fmap.geom.primitive.Point; |
|
15 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
16 |
|
|
17 |
public class TestCodeToValue extends TestCase { |
|
18 |
|
|
19 |
public TestCodeToValue(String testName) { |
|
20 |
super(testName); |
|
21 |
} |
|
22 |
|
|
23 |
@Override |
|
24 |
protected void setUp() throws Exception { |
|
25 |
super.setUp(); |
|
26 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
27 |
} |
|
28 |
|
|
29 |
@Override |
|
30 |
protected void tearDown() throws Exception { |
|
31 |
super.tearDown(); |
|
32 |
} |
|
33 |
|
|
34 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
35 |
// public void testHello() {} |
|
36 |
|
|
37 |
protected LexicalAnalyzer createLexicalAnalyzer() { |
|
38 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
39 |
LexicalAnalyzer lexer = manager.createLexicalAnalyzer(); |
|
40 |
return lexer; |
|
41 |
} |
|
42 |
|
|
43 |
protected org.gvsig.expressionevaluator.Compiler createCompiler() { |
|
44 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
45 |
org.gvsig.expressionevaluator.Compiler compiler = manager.createCompiler(); |
|
46 |
compiler.setLexicalAnalyzer(createLexicalAnalyzer()); |
|
47 |
return compiler; |
|
48 |
} |
|
49 |
|
|
50 |
public Code compileExpression(String source) { |
|
51 |
org.gvsig.expressionevaluator.Compiler compiler = createCompiler(); |
|
52 |
Code code = compiler.compileExpression(source); |
|
53 |
return code; |
|
54 |
} |
|
55 |
|
|
56 |
public void test3() throws CreateGeometryException { |
|
57 |
GeometryExpressionBuilder builder = GeometryExpressionUtils.createExpressionBuilder(); |
|
58 |
|
|
59 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
60 |
Point point = GeometryUtils.createPoint(10, 20); |
|
61 |
|
|
62 |
builder.set( |
|
63 |
builder.ST_Intersects( |
|
64 |
builder.geometry(point,proj), |
|
65 |
builder.variable("the_geom") |
|
66 |
) |
|
67 |
); |
|
68 |
Code code = compileExpression(builder.toString()); |
|
69 |
assertEquals( |
|
70 |
"ST_Intersects(ST_GeomFromWKB(DECODE('000000000140240000000000004034000000000000', 'hex'), 4326), \"the_geom\")", |
|
71 |
code.toValue().toString() |
|
72 |
); |
|
73 |
} |
|
74 |
|
|
75 |
public void test4() throws CreateGeometryException { |
|
76 |
GeometryExpressionBuilder builder = GeometryExpressionUtils.createExpressionBuilder(); |
|
77 |
|
|
78 |
IProjection proj = CRSFactory.getCRS("EPSG:4326"); |
|
79 |
Point point = GeometryUtils.createPoint(10, 20); |
|
80 |
|
|
81 |
builder.set( |
|
82 |
builder.function("ST_Intersects2", |
|
83 |
builder.geometry(point,proj), |
|
84 |
builder.variable("the_geom") |
|
85 |
) |
|
86 |
); |
|
87 |
Code code = compileExpression(builder.toString()); |
|
88 |
assertEquals( |
|
89 |
"ST_Intersects2(ST_GeomFromWKB(DECODE('000000000140240000000000004034000000000000', 'hex'), 4326), \"the_geom\")", |
|
90 |
code.toValue().toString() |
|
91 |
); |
|
92 |
} |
|
93 |
|
|
94 |
} |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestCompiler.java | ||
---|---|---|
1 |
package org.gvsig.expresionevaluator.impl; |
|
2 |
|
|
3 |
import junit.framework.TestCase; |
|
4 |
import org.gvsig.expressionevaluator.LexicalAnalyzer; |
|
5 |
import org.gvsig.expressionevaluator.Compiler; |
|
6 |
import org.gvsig.expressionevaluator.Code; |
|
7 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorLocator; |
|
8 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
9 |
import org.gvsig.expressionevaluator.ExpressionSyntaxException; |
|
10 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
11 |
|
|
12 |
|
|
13 |
public class TestCompiler extends TestCase { |
|
14 |
|
|
15 |
public TestCompiler(String testName) { |
|
16 |
super(testName); |
|
17 |
} |
|
18 |
|
|
19 |
@Override |
|
20 |
protected void setUp() throws Exception { |
|
21 |
super.setUp(); |
|
22 |
new DefaultLibrariesInitializer().fullInitialize(); |
|
23 |
} |
|
24 |
|
|
25 |
@Override |
|
26 |
protected void tearDown() throws Exception { |
|
27 |
super.tearDown(); |
|
28 |
} |
|
29 |
|
|
30 |
// TODO add test methods here. The name must begin with 'test'. For example: |
|
31 |
// public void testHello() {} |
|
32 |
|
|
33 |
|
|
34 |
protected LexicalAnalyzer createLexicalAnalyzer() { |
|
35 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
36 |
LexicalAnalyzer lexer = manager.createLexicalAnalyzer(); |
|
37 |
return lexer; |
|
38 |
} |
|
39 |
|
|
40 |
protected org.gvsig.expressionevaluator.Compiler createCompiler() { |
|
41 |
ExpressionEvaluatorManager manager = ExpressionEvaluatorLocator.getManager(); |
|
42 |
Compiler compiler = manager.createCompiler(); |
|
43 |
compiler.setLexicalAnalyzer(createLexicalAnalyzer()); |
|
44 |
return compiler; |
|
45 |
} |
|
46 |
|
|
47 |
public void testIdentifier1() { |
|
48 |
String source = "precio"; |
|
49 |
|
|
50 |
Compiler compiler = createCompiler(); |
|
51 |
Code code = compiler.compileExpression(source); |
|
52 |
assertEquals("\"precio\"", code.toString()); |
|
53 |
} |
|
54 |
|
|
55 |
public void testIdentifier2() { |
|
56 |
Compiler compiler = createCompiler(); |
|
57 |
compiler.getLexicalAnalyzer().setUseBracketsForIdentifiers(true); |
|
58 |
|
|
59 |
String source = "[precio]"; |
|
60 |
|
|
61 |
Code code = compiler.compileExpression(source); |
|
62 |
assertEquals("\"precio\"", code.toString()); |
|
63 |
} |
|
64 |
|
|
65 |
public void testIdentifier3() { |
|
66 |
Compiler compiler = createCompiler(); |
|
67 |
|
|
68 |
String source = "\"precio\""; |
|
69 |
|
|
70 |
Code code = compiler.compileExpression(source); |
|
71 |
assertEquals("\"precio\"", code.toString()); |
|
72 |
} |
|
73 |
|
|
74 |
|
|
75 |
public void testTrue() { |
|
76 |
String source = "true"; |
|
77 |
|
|
78 |
Compiler compiler = createCompiler(); |
|
79 |
Code code = compiler.compileExpression(source); |
|
80 |
assertEquals("TRUE", code.toString()); |
|
81 |
} |
|
82 |
|
|
83 |
public void testFalse() { |
|
84 |
String source = "false"; |
|
85 |
|
|
86 |
Compiler compiler = createCompiler(); |
|
87 |
Code code = compiler.compileExpression(source); |
|
88 |
assertEquals("FALSE", code.toString()); |
|
89 |
} |
|
90 |
|
|
91 |
public void testNull() { |
|
92 |
String source = "null"; |
|
93 |
|
|
94 |
Compiler compiler = createCompiler(); |
|
95 |
Code code = compiler.compileExpression(source); |
|
96 |
assertEquals("NULL", code.toString()); |
|
97 |
} |
|
98 |
|
|
99 |
public void testIsNull() { |
|
100 |
String source = "10 is null"; |
|
101 |
|
|
102 |
Compiler compiler = createCompiler(); |
|
103 |
Code code = compiler.compileExpression(source); |
|
104 |
assertEquals("(10 IS NULL)", code.toString()); |
|
105 |
} |
|
106 |
|
|
107 |
public void testIsNotNull() { |
|
108 |
String source = "10 is not null"; |
|
109 |
|
|
110 |
Compiler compiler = createCompiler(); |
|
111 |
Code code = compiler.compileExpression(source); |
|
112 |
assertEquals("NOT((10 IS NULL))", code.toString()); |
|
113 |
} |
|
114 |
|
|
115 |
public void testNotTrue() { |
|
116 |
String source = "not true"; |
|
117 |
|
|
118 |
Compiler compiler = createCompiler(); |
|
119 |
Code code = compiler.compileExpression(source); |
|
120 |
assertEquals("NOT(TRUE)", code.toString()); |
|
121 |
} |
|
122 |
|
|
123 |
public void testInteger() { |
|
124 |
String source = "23"; |
|
125 |
|
|
126 |
Compiler compiler = createCompiler(); |
|
127 |
Code code = compiler.compileExpression(source); |
|
128 |
assertEquals("23", code.toString()); |
|
129 |
} |
|
130 |
|
|
131 |
public void operator(String operatorName) { |
|
132 |
String source = "precio " + operatorName + " 23"; |
|
133 |
|
|
134 |
Compiler compiler = createCompiler(); |
|
135 |
Code code = compiler.compileExpression(source); |
|
136 |
assertEquals("(\"precio\" "+ operatorName + " 23)", code.toString()); |
|
137 |
} |
|
138 |
public void testOperatorMod() { |
|
139 |
String source = "precio % 23"; |
|
140 |
Compiler compiler = createCompiler(); |
|
141 |
Code code = compiler.compileExpression(source); |
|
142 |
assertEquals("MOD(\"precio\", 23)", code.toString()); |
|
143 |
} |
|
144 |
|
|
145 |
public void testOperators() { |
|
146 |
|
|
147 |
operator("="); |
|
148 |
operator("<>"); |
|
149 |
operator(">"); |
|
150 |
operator(">="); |
|
151 |
operator("<"); |
|
152 |
operator("<="); |
|
153 |
operator("LIKE"); |
|
154 |
operator("ILIKE"); |
|
155 |
operator("||"); |
|
156 |
operator("+"); |
|
157 |
operator("-"); |
|
158 |
operator("*"); |
|
159 |
operator("OR"); |
|
160 |
operator("AND"); |
|
161 |
operator("IS"); |
|
162 |
|
|
163 |
operator("~"); |
|
164 |
} |
|
165 |
|
|
166 |
public void testAddMul() { |
|
167 |
String source = "precio + 10 * 2 + 20 + 30"; |
|
168 |
|
|
169 |
Compiler compiler = createCompiler(); |
|
170 |
|
|
171 |
Code code = compiler.compileExpression(source); |
|
172 |
assertEquals("(((\"precio\" + (10 * 2)) + 20) + 30)", code.toString()); |
|
173 |
} |
|
174 |
|
|
175 |
public void testAddMulPar() { |
|
176 |
String source = "(precio + 10) * 2 + 20 + 30"; |
|
177 |
|
|
178 |
Compiler compiler = createCompiler(); |
|
179 |
|
|
180 |
Code code = compiler.compileExpression(source); |
|
181 |
assertEquals("((((\"precio\" + 10) * 2) + 20) + 30)", code.toString()); |
|
182 |
} |
|
183 |
|
|
184 |
public void testAbs() { |
|
185 |
String source = "precio + abs(10)"; |
|
186 |
|
|
187 |
Compiler compiler = createCompiler(); |
|
188 |
|
|
189 |
Code code = compiler.compileExpression(source); |
|
190 |
assertEquals("(\"precio\" + abs(10))", code.toString()); |
|
191 |
} |
|
192 |
|
|
193 |
public void testAbs2() { |
|
194 |
String source = "precio + abs(-10)"; |
|
195 |
|
|
196 |
Compiler compiler = createCompiler(); |
|
197 |
|
|
198 |
Code code = compiler.compileExpression(source); |
|
199 |
assertEquals("(\"precio\" + abs(-10))", code.toString()); |
|
200 |
} |
|
201 |
|
|
202 |
public void testPI() { |
|
203 |
String source = "precio + PI()"; |
|
204 |
|
|
205 |
Compiler compiler = createCompiler(); |
|
206 |
|
|
207 |
Code code = compiler.compileExpression(source); |
|
208 |
assertEquals("(\"precio\" + PI())", code.toString()); |
|
209 |
} |
|
210 |
|
|
211 |
public void testCeil() { |
|
212 |
String source = "precio + CEIL(PI())"; |
|
213 |
|
|
214 |
Compiler compiler = createCompiler(); |
|
215 |
|
|
216 |
Code code = compiler.compileExpression(source); |
|
217 |
assertEquals("(\"precio\" + CEIL(PI()))", code.toString()); |
|
218 |
} |
|
219 |
|
|
220 |
public void testGetitem1() { |
|
221 |
String source = "LIST('uno','dos','tres')[1]" ; |
|
222 |
|
|
223 |
Compiler compiler = createCompiler(); |
|
224 |
|
|
225 |
Code code = compiler.compileExpression(source); |
|
226 |
assertEquals("GETITEM(LIST('uno', 'dos', 'tres'), 1)", code.toString()); |
|
227 |
} |
|
228 |
|
|
229 |
public void testConcat() { |
|
230 |
String source = "CONCAT(precio,' euros')"; |
|
231 |
|
|
232 |
Compiler compiler = createCompiler(); |
|
233 |
|
|
234 |
Code code = compiler.compileExpression(source); |
|
235 |
assertEquals("CONCAT(\"precio\", ' euros')", code.toString()); |
|
236 |
} |
|
237 |
|
|
238 |
public void test1() { |
|
239 |
String source = "NOMBRE03 = 'Torre d''En Besora (la)'"; |
|
240 |
|
|
241 |
Compiler compiler = createCompiler(); |
|
242 |
|
|
243 |
Code code = compiler.compileExpression(source); |
|
244 |
assertEquals("(\"NOMBRE03\" = 'Torre d''En Besora (la)')", code.toString()); |
|
245 |
} |
|
246 |
|
|
247 |
public void test2() { |
|
248 |
Compiler compiler = createCompiler(); |
|
249 |
compiler.getLexicalAnalyzer().setUseBracketsForIdentifiers(true); |
|
250 |
|
|
251 |
String source = "[1990] = 0.168873933773767"; |
|
252 |
|
|
253 |
Code code = compiler.compileExpression(source); |
|
254 |
assertEquals("(\"1990\" = 0.168873933773767)", code.toString()); |
|
255 |
} |
|
256 |
|
|
257 |
public void test2fields() { |
|
258 |
Compiler compiler = createCompiler(); |
|
259 |
compiler.getLexicalAnalyzer().setUseBracketsForIdentifiers(true); |
|
260 |
|
|
261 |
String source = "[1990] = [precio]"; |
|
262 |
|
|
263 |
Code code = compiler.compileExpression(source); |
|
264 |
assertEquals("(\"1990\" = \"precio\")", code.toString()); |
|
265 |
} |
|
266 |
|
|
267 |
|
|
268 |
public void testInvokeFunction1() { |
|
269 |
String source = "ST_Area(GEOMETRY)"; |
|
270 |
|
|
271 |
Compiler compiler = createCompiler(); |
|
272 |
|
|
273 |
Code code = compiler.compileExpression(source); |
|
274 |
assertEquals("ST_Area(\"GEOMETRY\")", code.toString()); |
|
275 |
} |
|
276 |
|
|
277 |
public void testInvokeMethod1() { |
|
278 |
String source = "'hola'.length()"; |
|
279 |
|
|
280 |
Compiler compiler = createCompiler(); |
|
281 |
|
|
282 |
Code code = compiler.compileExpression(source); |
|
283 |
assertEquals("'hola'.length()", code.toString()); |
|
284 |
} |
|
285 |
|
|
286 |
public void testInvokeMethod1b() { |
|
287 |
String source = "'hola'->length()"; |
|
288 |
|
|
289 |
Compiler compiler = createCompiler(); |
|
290 |
|
|
291 |
Code code = compiler.compileExpression(source); |
|
292 |
assertEquals("'hola'.length()", code.toString()); |
|
293 |
} |
|
294 |
|
|
295 |
|
|
296 |
public void testInvokeMethod2() { |
|
297 |
String source = "'hola'.indexOf('l') "; |
|
298 |
|
|
299 |
Compiler compiler = createCompiler(); |
|
300 |
|
|
301 |
Code code = compiler.compileExpression(source); |
|
302 |
assertEquals("'hola'.indexOf('l')", code.toString()); |
|
303 |
} |
|
304 |
|
|
305 |
public void testSyntaxError1() { |
|
306 |
Compiler compiler = createCompiler(); |
|
307 |
String source; |
|
308 |
|
|
309 |
source = "3 + (2*)"; |
|
310 |
try { |
|
311 |
compiler.compileExpression(source); |
|
312 |
assertTrue("A syntax exception should have been thrown compiling '"+source+"'.", false); |
|
313 |
} catch(ExpressionSyntaxException ex) { |
|
314 |
// Ok |
|
315 |
} |
|
316 |
source = "3 + 2*"; |
|
317 |
try { |
|
318 |
compiler.compileExpression(source); |
|
319 |
assertTrue("A syntax exception should have been thrown compiling '"+source+"'.", false); |
|
320 |
} catch(ExpressionSyntaxException ex) { |
|
321 |
// Ok |
|
322 |
} |
|
323 |
source = "3 + (2*2))"; |
|
324 |
try { |
|
325 |
compiler.compileExpression(source); |
|
326 |
assertTrue("A syntax exception should have been thrown compiling '"+source+"'.", false); |
|
327 |
} catch(ExpressionSyntaxException ex) { |
|
328 |
// Ok |
|
329 |
} |
|
330 |
source = "3 and or 2"; |
|
331 |
try { |
|
332 |
compiler.compileExpression(source); |
|
333 |
assertTrue("A syntax exception should have been thrown compiling '"+source+"'.", false); |
|
334 |
} catch(ExpressionSyntaxException ex) { |
|
335 |
// Ok |
|
336 |
} |
|
337 |
source = "3*/2"; |
|
338 |
try { |
|
339 |
compiler.compileExpression(source); |
|
340 |
assertTrue("A syntax exception should have been thrown compiling '"+source+"'.", false); |
|
341 |
} catch(ExpressionSyntaxException ex) { |
|
342 |
// Ok |
|
343 |
} |
|
344 |
} |
|
345 |
|
|
346 |
public void testInvokeFunction2paramters1() { |
|
347 |
String source = "LEFT('NOMBRE', 2)"; |
|
348 |
|
|
349 |
Compiler compiler = createCompiler(); |
|
350 |
|
|
351 |
Code code = compiler.compileExpression(source); |
|
352 |
assertEquals("LEFT('NOMBRE', 2)", code.toString()); |
|
353 |
} |
|
354 |
|
|
355 |
public void testInvokeFunction2paramters2() { |
|
356 |
String source = "LEFT('NOMBRE',2)"; |
|
357 |
|
|
358 |
Compiler compiler = createCompiler(); |
|
359 |
|
|
360 |
Code code = compiler.compileExpression(source); |
|
361 |
assertEquals("LEFT('NOMBRE', 2)", code.toString()); |
|
362 |
} |
|
363 |
|
|
364 |
public void testInvokeFunction3paramters1() { |
|
365 |
String source = "MID('NOMBRE', 2, 2)"; |
|
366 |
|
|
367 |
Compiler compiler = createCompiler(); |
|
368 |
|
|
369 |
Code code = compiler.compileExpression(source); |
|
370 |
assertEquals("MID('NOMBRE', 2, 2)", code.toString()); |
|
371 |
} |
|
372 |
|
|
373 |
public void testInvokeFunction3paramters2() { |
|
374 |
String source = "MID('NOMBRE', 2,2)"; |
|
375 |
|
|
376 |
Compiler compiler = createCompiler(); |
|
377 |
|
|
378 |
Code code = compiler.compileExpression(source); |
|
379 |
assertEquals("MID('NOMBRE', 2, 2)", code.toString()); |
|
380 |
} |
|
381 |
|
|
382 |
public void testDecimal1() { |
|
383 |
String source = "23.1"; |
|
384 |
|
|
385 |
Compiler compiler = createCompiler(); |
|
386 |
Code code = compiler.compileExpression(source); |
|
387 |
assertEquals("23.1", code.toString()); |
|
388 |
} |
|
389 |
|
|
390 |
public void testDecimal2() { |
|
391 |
String source = "23,1"; |
|
392 |
|
|
393 |
Compiler compiler = createCompiler(); |
|
394 |
try { |
|
395 |
Code code = compiler.compileExpression(source); |
|
396 |
fail("I expected 23,1 to be erroneous."); |
|
397 |
} catch(ExpressionSyntaxException ex) { |
|
398 |
// This is OK. |
|
399 |
} |
|
400 |
} |
|
401 |
public void testDecimal3() { |
|
402 |
String source = "1.23E4"; |
|
403 |
|
|
404 |
Compiler compiler = createCompiler(); |
|
405 |
Code code = compiler.compileExpression(source); |
|
406 |
assertEquals("12300", code.toString()); |
|
407 |
} |
|
408 |
|
|
409 |
public void testDecimal4() { |
|
410 |
String source = "1.23E-2"; |
|
411 |
|
|
412 |
Compiler compiler = createCompiler(); |
|
413 |
Code code = compiler.compileExpression(source); |
|
414 |
assertEquals("0.0123", code.toString()); |
|
415 |
} |
|
416 |
|
|
417 |
public void testDecimal5() { |
|
418 |
String source = "1.23E-4"; |
|
419 |
|
|
420 |
Compiler compiler = createCompiler(); |
|
421 |
Code code = compiler.compileExpression(source); |
|
422 |
assertEquals("0.000123", code.toString()); |
|
423 |
} |
|
424 |
|
|
425 |
public void testDecimal6() { |
|
426 |
String source = "-23.1"; |
|
427 |
|
|
428 |
Compiler compiler = createCompiler(); |
|
429 |
Code code = compiler.compileExpression(source); |
|
430 |
assertEquals("-23.1", code.toString()); |
|
431 |
} |
|
432 |
|
|
433 |
public void testDecimal7() { |
|
434 |
String source = "-1.23E-2"; |
|
435 |
|
|
436 |
Compiler compiler = createCompiler(); |
|
437 |
Code code = compiler.compileExpression(source); |
|
438 |
assertEquals("-0.0123", code.toString()); |
|
439 |
} |
|
440 |
|
|
441 |
public void testDecimal8() { |
|
442 |
String source = "-1.23E-4"; |
|
443 |
|
|
444 |
Compiler compiler = createCompiler(); |
|
445 |
Code code = compiler.compileExpression(source); |
|
446 |
assertEquals("-0.000123", code.toString()); |
|
447 |
} |
|
448 |
|
|
449 |
|
|
450 |
} |
tags/org.gvsig.desktop-2.0.369/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.geometry/org.gvsig.expressionevaluator.geometry.lib/org.gvsig.expressionevaluator.geometry.lib.impl/src/test/java/org/gvsig/expresionevaluator/impl/TestExpressionBuilderFormatter.java | ||
---|---|---|
1 |
package org.gvsig.expresionevaluator.impl; |
|
2 |
|
|
3 |
import java.text.MessageFormat; |
|
4 |
import java.util.ArrayList; |
|
5 |
import java.util.List; |
|
6 |
import junit.framework.TestCase; |
|
7 |
import org.apache.commons.lang3.ArrayUtils; |
|
8 |
import org.apache.commons.lang3.StringUtils; |
|
9 |
import org.apache.commons.lang3.tuple.Pair; |
|
10 |
import org.cresques.cts.IProjection; |
|
11 |
import org.gvsig.expressionevaluator.Formatter; |
|
12 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
|
13 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Constant; |
|
14 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
|
15 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_CONSTANT; |
|
16 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_VARIABLE; |
|
17 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Parameter; |
|
18 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
|
19 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Variable; |
|
20 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilder; |
|
21 |
import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.GeometrySupportType; |
|
22 |
import org.gvsig.expressionevaluator.GeometryExpressionUtils; |
|
23 |
import org.gvsig.fmap.crs.CRSFactory; |
|
24 |
import org.gvsig.fmap.geom.Geometry; |
|
25 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
26 |
import org.gvsig.fmap.geom.GeometryManager; |
|
27 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
28 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
29 |
import org.gvsig.fmap.geom.primitive.Point; |
|
30 |
import org.gvsig.tools.library.impl.DefaultLibrariesInitializer; |
|
31 |
|
|
32 |
public class TestExpressionBuilderFormatter extends TestCase { |
|
33 |
|
|
34 |
private static class MyFormatter implements Formatter<Value> { |
|
35 |
|
|
36 |
private class Formatter_constant_bytearray implements Formatter<Value> { |
|
37 |
|
|
38 |
@Override |
|
39 |
public boolean canApply(Value value) { |
|
40 |
if( value instanceof Constant ) { |
|
41 |
return ((Constant)value).value() instanceof byte[]; |
|
42 |
} |
|
43 |
return false; |
|
44 |
} |
|
45 |
|
|
46 |
@Override |
|
47 |
public String format(Value constant) { |
|
48 |
return builder.bytearray_x((byte[]) ((Constant)constant).value()); |
|
49 |
} |
|
50 |
} |
|
51 |
|
|
52 |
private class Formatter_constant_geometry implements Formatter<Value> { |
|
53 |
|
|
54 |
@Override |
|
55 |
public boolean canApply(Value value) { |
|
56 |
if( value instanceof Constant ) { |
|
57 |
return ((Constant)value).value() instanceof Geometry; |
|
58 |
} |
|
59 |
return false; |
|
60 |
} |
|
61 |
|
|
62 |
@Override |
|
63 |
public String format(Value constant) { |
|
64 |
Geometry geometry = (Geometry) ((Constant)constant).value(); |
|
65 |
switch (builder.geometry_support_type()) { |
|
66 |
case EWKB: |
|
67 |
return MessageFormat.format( |
|
68 |
"ST_GeomFromEWKB(({0}), ({1}))", |
|
69 |
builder.bytearray_x(GeometryUtils.toEWKB(geometry)), |
|
70 |
String.valueOf(builder.srs_id(geometry.getProjection())) |
|
71 |
); |
|
72 |
case WKB: |
|
73 |
return MessageFormat.format( |
|
74 |
"ST_GeomFromWKB(({0}), ({1}))", |
|
75 |
builder.bytearray_x(GeometryUtils.toWKB(geometry)), |
|
76 |
String.valueOf(builder.srs_id(geometry.getProjection())) |
|
77 |
); |
|
78 |
case WKT: |
|
79 |
default: |
|
80 |
return MessageFormat.format( |
|
81 |
"ST_GeomFromText({0}, ({1}))", |
|
82 |
builder.string(GeometryUtils.toWKT(geometry)), |
|
83 |
String.valueOf(builder.srs_id(geometry.getProjection())) |
|
84 |
); |
|
85 |
} |
|
86 |
} |
|
87 |
} |
|
88 |
|
|
89 |
private class Formatter_ST_intersects implements Formatter<Value> { |
|
90 |
|
|
91 |
@Override |
|
92 |
public boolean canApply(Value value) { |
|
93 |
if( value instanceof Function ) { |
|
94 |
return StringUtils.equalsIgnoreCase("ST_intersects",((Function)value).name()); |
|
95 |
} |
|
96 |
return false; |
|
97 |
} |
|
98 |
|
|
99 |
@Override |
|
100 |
public String format(Value function) { |
|
101 |
List<Value> parameters = ((Function)function).parameters(); |
|
102 |
String p1 = parameters.get(0).toString(formatter()); |
|
103 |
String p2 = parameters.get(1).toString(formatter()); |
|
104 |
String r = MessageFormat.format( |
|
105 |
"( (({0}) && ({1})) AND ST_Intersects(({0}),({1}) ))", |
|
106 |
p1, |
|
107 |
p2 |
|
108 |
); |
|
109 |
return r; |
|
110 |
} |
|
111 |
} |
|
112 |
|
|
113 |
private class Formatter_ST_GeomFromEWKB implements Formatter<Value> { |
|
114 |
|
|
115 |
@Override |
|
116 |
public boolean canApply(Value value) { |
|
117 |
if( value instanceof Function ) { |
|
118 |
return StringUtils.equalsIgnoreCase("ST_GeomFromEWKB",((Function)value).name()); |
|
119 |
} |
|
120 |
return false; |
|
121 |
} |
|
122 |
|
|
123 |
@Override |
|
124 |
public String format(Value function) { |
|
125 |
List<Value> parameters = ((Function)function).parameters(); |
|
126 |
String p1 = parameters.get(0).toString(formatter()); |
|
127 |
String p2 = parameters.get(1).toString(formatter()); |
|
128 |
String r = MessageFormat.format( |
|
129 |
"GeomFromWKB({0}, {1})", |
|
130 |
p1, |
|
131 |
p2 |
|
132 |
); |
|
133 |
return r; |
|
134 |
} |
|
135 |
} |
|
136 |
|
|
137 |
private class Formatter_IFNULL implements Formatter<Value> { |
|
138 |
|
|
139 |
@Override |
|
140 |
public boolean canApply(Value value) { |
|
141 |
if( value instanceof Function ) { |
|
142 |
return StringUtils.equalsIgnoreCase("IFNULL",((Function)value).name()); |
|
143 |
} |
|
144 |
return false; |
|
145 |
} |
|
146 |
|
|
147 |
@Override |
|
148 |
public String format(Value function) { |
|
149 |
List<Value> parameters = ((Function)function).parameters(); |
|
150 |
String p1 = parameters.get(0).toString(formatter()); |
|
151 |
String p2 = parameters.get(1).toString(formatter()); |
|
152 |
String p3 = parameters.get(2).toString(formatter()); |
|
153 |
String r = MessageFormat.format( |
|
154 |
"NVL2({0}, {1}, {2})", |
|
155 |
p1, |
|
156 |
p3, |
|
157 |
p2 |
|
158 |
); |
|
159 |
return r; |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
private class Formatter_ST_AsEWKB implements Formatter<Value> { |
|
164 |
|
|
165 |
@Override |
|
166 |
public boolean canApply(Value value) { |
|
167 |
if( value instanceof Function ) { |
|
168 |
return StringUtils.equalsIgnoreCase("ST_AsEWKB",((Function)value).name()); |
|
169 |
} |
|
170 |
return false; |
|
171 |
} |
|
172 |
|
|
173 |
@Override |
|
174 |
public String format(Value function) { |
|
175 |
List<Value> parameters = ((Function)function).parameters(); |
|
176 |
String p1 = parameters.get(0).toString(formatter()); |
|
177 |
String r = MessageFormat.format( |
|
178 |
"AsWKB(({0}))", |
|
179 |
p1 |
|
180 |
); |
|
181 |
return r; |
|
182 |
} |
|
183 |
} |
|
184 |
|
|
185 |
private class Formatter_NOT_IS_NULL implements Formatter<Value> { |
|
186 |
|
|
187 |
@Override |
|
188 |
public boolean canApply(Value value) { |
|
189 |
if( value instanceof Function ) { |
|
190 |
return StringUtils.equalsIgnoreCase("NOT_IS_NULL",((Function)value).name()); |
|
191 |
} |
|
192 |
return false; |
|
193 |
} |
|
194 |
|
|
195 |
@Override |
|
196 |
public String format(Value function) { |
|
197 |
List<Value> parameters = ((Function)function).parameters(); |
|
198 |
String p1 = parameters.get(0).toString(formatter()); |
|
199 |
String r = MessageFormat.format( |
|
200 |
"( ({0}) IS NOT NULL )", |
|
201 |
p1 |
|
202 |
); |
|
203 |
return r; |
|
204 |
} |
|
205 |
} |
|
206 |
|
|
207 |
private final Formatter<Value>[] formatters; |
|
208 |
private final GeometryExpressionBuilder builder; |
|
209 |
|
|
210 |
public MyFormatter(GeometryExpressionBuilder builder) { |
|
211 |
this.builder = builder; |
|
212 |
this.formatters = new Formatter[] { |
|
213 |
new Formatter_IFNULL(), |
|
214 |
new Formatter_NOT_IS_NULL(), |
|
215 |
new Formatter_ST_AsEWKB(), |
|
216 |
new Formatter_ST_GeomFromEWKB(), |
|
217 |
new Formatter_constant_bytearray(), |
|
218 |
new Formatter_constant_geometry(), |
|
219 |
new Formatter_ST_intersects() |
|
220 |
}; |
|
221 |
} |
|
222 |
|
Also available in: Unified diff