svn-gvsig-desktop / 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 / DefaultGeometryExpressionBuilderHelper.java @ 46105
History | View | Annotate | Download (27.3 KB)
1 | 44006 | jjdelcerro | package org.gvsig.expressionevaluator.impl; |
---|---|---|---|
2 | 43020 | jjdelcerro | |
3 | import java.text.MessageFormat; |
||
4 | import java.util.Objects; |
||
5 | import org.cresques.cts.IProjection; |
||
6 | 44644 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder; |
7 | 43020 | jjdelcerro | import org.gvsig.fmap.geom.Geometry; |
8 | 43034 | jjdelcerro | import org.gvsig.fmap.geom.primitive.Envelope; |
9 | 43020 | jjdelcerro | |
10 | 44644 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder.AbstractValue; |
11 | import org.gvsig.expressionevaluator.ExpressionBuilder.Constant; |
||
12 | import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
||
13 | import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_CONSTANT; |
||
14 | 44769 | jjdelcerro | import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_VARIABLE; |
15 | 44644 | jjdelcerro | import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
16 | import org.gvsig.expressionevaluator.ExpressionBuilder.Visitor; |
||
17 | import org.gvsig.expressionevaluator.ExpressionBuilder.VisitorFilter; |
||
18 | 44198 | jjdelcerro | import org.gvsig.expressionevaluator.Formatter; |
19 | import org.gvsig.fmap.geom.GeometryUtils; |
||
20 | 44644 | jjdelcerro | import org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper; |
21 | import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.PARAMETER_TYPE_GEOMETRY; |
||
22 | 43093 | jjdelcerro | |
23 | 44644 | jjdelcerro | public class DefaultGeometryExpressionBuilderHelper |
24 | implements GeometryExpressionBuilderHelper {
|
||
25 | 44198 | jjdelcerro | |
26 | private static final String FORMAT_ST_SRID = "ST_SRID({0})"; |
||
27 | private static final String FORMAT_ST_ASTEXT = "ST_AsText({0})"; |
||
28 | private static final String FORMAT_ST_ASBINARY = "ST_AsBinary({0})"; |
||
29 | private static final String FORMAT_ST_ASEWKB = "ST_AsEWKB({0})"; |
||
30 | private static final String FORMAT_ST_CONTAINS = "ST_Contains(({0}), ({1}))"; |
||
31 | private static final String FORMAT_ST_CROSSES = "ST_Crosses(({0}), ({1}))"; |
||
32 | private static final String FORMAT_ST_DISJOINT = "ST_Disjoint(({0}), ({1}))"; |
||
33 | private static final String FORMAT_ST_EQUALS = "ST_Equals(({0}), ({1}))"; |
||
34 | private static final String FORMAT_ST_ISCLOSED = "ST_IsClosed({0})"; |
||
35 | private static final String FORMAT_ST_OVERLAPS = "ST_Overlaps(({0}), ({1}))"; |
||
36 | private static final String FORMAT_ST_TOUCHES = "ST_Touches(({0}), ({1}))"; |
||
37 | private static final String FORMAT_ST_WITHIN = "ST_Within(({0}), ({1}))"; |
||
38 | private static final String FORMAT_ST_ENVELOPE = "ST_Envelope({0})"; |
||
39 | 44612 | jjdelcerro | private static final String FORMAT_ST_FORCE2D = "ST_Force2D({0})"; |
40 | 44198 | jjdelcerro | private static final String FORMAT_ST_INTERSECTS = "ST_Intersects(({0}), ({1}))"; |
41 | private static final String FORMAT_ST_GEOMFROMTEXT = "ST_GeomFromText(({0}), ({1}))"; |
||
42 | private static final String FORMAT_ST_GEOMFROMWKB = "ST_GeomFromWKB(({0}), ({1}))"; |
||
43 | private static final String FORMAT_ST_GEOMFROMEWKB = "ST_GeomFromEWKB(({0}), ({1}))"; |
||
44 | private static final String FORMAT_ST_SIMPLIFY = "ST_Simplify(({0}), ({1}))"; |
||
45 | 43093 | jjdelcerro | |
46 | 44769 | jjdelcerro | public class GeometryParameterBase |
47 | extends AbstractValue
|
||
48 | 44644 | jjdelcerro | implements GeometryParameter {
|
49 | 43093 | jjdelcerro | |
50 | 43020 | jjdelcerro | protected Value srs;
|
51 | 44644 | jjdelcerro | protected GeometryExpressionBuilderHelper builder;
|
52 | 44769 | jjdelcerro | protected String name; |
53 | protected Object value; |
||
54 | protected int type; |
||
55 | 44198 | jjdelcerro | /*
|
56 | 44644 | jjdelcerro | Para un parametro de tipo Geometria, el srs sera siempre un Constant
|
57 | 44198 | jjdelcerro | excepto cuando se le asigne una geometria contante al parametro y esta
|
58 | tenga un SRS asignado. En este caso, tanto la geometria como el SRS
|
||
59 | se trataran como parametros.
|
||
60 | |||
61 | 44644 | jjdelcerro | Si se quiere que el SRS sea un Parameter, se construira como tal.
|
62 | 44198 | jjdelcerro | */
|
63 | 44644 | jjdelcerro | public GeometryParameterBase(GeometryExpressionBuilderHelper builder) {
|
64 | 44769 | jjdelcerro | this.type = PARAMETER_TYPE_CONSTANT;
|
65 | this.name = null; |
||
66 | this.value = null; |
||
67 | 44644 | jjdelcerro | this.builder = builder;
|
68 | 43020 | jjdelcerro | } |
69 | |||
70 | @Override
|
||
71 | 46105 | omartinez | public Value clone() throws CloneNotSupportedException { |
72 | GeometryParameterBase other = (GeometryParameterBase) super.clone();
|
||
73 | other.srs = (Value) org.gvsig.tools.lang.Cloneable.cloneQuietly(srs); |
||
74 | return other;
|
||
75 | } |
||
76 | |||
77 | |||
78 | |||
79 | @Override
|
||
80 | 43020 | jjdelcerro | public void accept(Visitor visitor, VisitorFilter filter) { |
81 | super.accept(visitor, filter);
|
||
82 | 43093 | jjdelcerro | if (this.srs != null) { |
83 | 43020 | jjdelcerro | this.srs.accept(visitor, filter);
|
84 | } |
||
85 | } |
||
86 | 43093 | jjdelcerro | |
87 | 43020 | jjdelcerro | @Override
|
88 | 44376 | jjdelcerro | public void replace(Value target, Value replacement) { |
89 | if( this.srs == target ) { |
||
90 | this.srs = replacement;
|
||
91 | } else {
|
||
92 | this.srs.replace(target, replacement);
|
||
93 | } |
||
94 | } |
||
95 | |||
96 | @Override
|
||
97 | 44644 | jjdelcerro | public GeometryParameter value(Object value) { |
98 | if( value instanceof Geometry ) { |
||
99 | if( this.srs == null ) { |
||
100 | IProjection proj = ((Geometry)value).getProjection(); |
||
101 | this.srs(this.builder.parameter().value(proj)); |
||
102 | } |
||
103 | 43093 | jjdelcerro | } |
104 | 44644 | jjdelcerro | this.value = value;
|
105 | 43020 | jjdelcerro | return this; |
106 | } |
||
107 | 43093 | jjdelcerro | |
108 | 43020 | jjdelcerro | @Override
|
109 | 44644 | jjdelcerro | public GeometryParameter srs(IProjection srs) {
|
110 | this.srs = new ProjectionConstant(this.builder, srs); |
||
111 | if( this.type == PARAMETER_TYPE_VARIABLE ) { |
||
112 | this.type = PARAMETER_TYPE_GEOMETRY;
|
||
113 | 43093 | jjdelcerro | } |
114 | 43020 | jjdelcerro | return this; |
115 | } |
||
116 | 43093 | jjdelcerro | |
117 | 43020 | jjdelcerro | @Override
|
118 | 44644 | jjdelcerro | public GeometryParameter srs(Value srs) {
|
119 | this.srs = srs;
|
||
120 | if( this.type == PARAMETER_TYPE_VARIABLE ) { |
||
121 | this.type = PARAMETER_TYPE_GEOMETRY;
|
||
122 | 43093 | jjdelcerro | } |
123 | 43020 | jjdelcerro | return this; |
124 | } |
||
125 | 43093 | jjdelcerro | |
126 | 43020 | jjdelcerro | @Override
|
127 | 44644 | jjdelcerro | public Value srs() {
|
128 | return this.srs; |
||
129 | 43020 | jjdelcerro | } |
130 | |||
131 | @Override
|
||
132 | 44644 | jjdelcerro | public Geometry geometry() {
|
133 | return (Geometry) this.value; |
||
134 | 43020 | jjdelcerro | } |
135 | 43093 | jjdelcerro | |
136 | 44769 | jjdelcerro | |
137 | 43020 | jjdelcerro | @Override
|
138 | 44769 | jjdelcerro | public GeometryParameter as_constant() {
|
139 | this.type = PARAMETER_TYPE_CONSTANT;
|
||
140 | if (this.value == null && this.name != null) { |
||
141 | this.value = this.name; |
||
142 | } |
||
143 | return this; |
||
144 | 43020 | jjdelcerro | } |
145 | |||
146 | @Override
|
||
147 | 44644 | jjdelcerro | public GeometryParameter as_variable() {
|
148 | 44769 | jjdelcerro | this.type = PARAMETER_TYPE_VARIABLE;
|
149 | if (this.value != null && this.name == null) { |
||
150 | this.name = (String) this.value; |
||
151 | } |
||
152 | return this; |
||
153 | 43020 | jjdelcerro | } |
154 | 44769 | jjdelcerro | |
155 | @Override
|
||
156 | public GeometryParameter name(String name) { |
||
157 | this.type = PARAMETER_TYPE_VARIABLE;
|
||
158 | this.name = name;
|
||
159 | return this; |
||
160 | } |
||
161 | 44644 | jjdelcerro | |
162 | 43020 | jjdelcerro | @Override
|
163 | 44769 | jjdelcerro | public String name() { |
164 | switch (this.type) { |
||
165 | case PARAMETER_TYPE_VARIABLE:
|
||
166 | return this.name; |
||
167 | case PARAMETER_TYPE_CONSTANT:
|
||
168 | if (this.value == null) { |
||
169 | return null; |
||
170 | } |
||
171 | return this.value.toString(); |
||
172 | default:
|
||
173 | if (this.name != null) { |
||
174 | return this.name; |
||
175 | } |
||
176 | if (this.value != null) { |
||
177 | return this.value.toString(); |
||
178 | } |
||
179 | return null; |
||
180 | } |
||
181 | } |
||
182 | |||
183 | @Override
|
||
184 | public int type() { |
||
185 | return this.type; |
||
186 | } |
||
187 | |||
188 | @Override
|
||
189 | public boolean is_constant() { |
||
190 | return this.type == PARAMETER_TYPE_CONSTANT; |
||
191 | } |
||
192 | |||
193 | @Override
|
||
194 | public boolean is_variable() { |
||
195 | return this.type == PARAMETER_TYPE_VARIABLE; |
||
196 | } |
||
197 | |||
198 | @Override
|
||
199 | 44644 | jjdelcerro | public GeometryParameter as_geometry_variable() {
|
200 | this.type = PARAMETER_TYPE_GEOMETRY;
|
||
201 | if (this.value == null && this.name != null) { |
||
202 | this.value = this.name; |
||
203 | } |
||
204 | return this; |
||
205 | } |
||
206 | |||
207 | @Override
|
||
208 | 43020 | jjdelcerro | public boolean is_geometry_variable() { |
209 | 44644 | jjdelcerro | return this.type == PARAMETER_TYPE_GEOMETRY; |
210 | 43020 | jjdelcerro | } |
211 | |||
212 | @Override
|
||
213 | 44198 | jjdelcerro | public Object value() { |
214 | 43020 | jjdelcerro | try {
|
215 | 43093 | jjdelcerro | switch (this.type) { |
216 | 44644 | jjdelcerro | case PARAMETER_TYPE_CONSTANT:
|
217 | 44198 | jjdelcerro | if( this.value instanceof Geometry ) { |
218 | 44644 | jjdelcerro | switch (this.builder.geometry_support_type()) { |
219 | 43020 | jjdelcerro | case EWKB:
|
220 | 44644 | jjdelcerro | return GeometryUtils.toEWKB(this.geometry()); |
221 | 43020 | jjdelcerro | case WKB:
|
222 | 44644 | jjdelcerro | return GeometryUtils.toWKB(this.geometry()); |
223 | 43020 | jjdelcerro | case WKT:
|
224 | default:
|
||
225 | 44644 | jjdelcerro | return GeometryUtils.toWKT(this.geometry()); |
226 | 43020 | jjdelcerro | } |
227 | 43093 | jjdelcerro | } |
228 | 44644 | jjdelcerro | if( this.value instanceof IProjection ) { |
229 | return this.builder.srs_id((IProjection) this.value); |
||
230 | } |
||
231 | 43020 | jjdelcerro | return this.value; |
232 | 44644 | jjdelcerro | case PARAMETER_TYPE_VARIABLE:
|
233 | case PARAMETER_TYPE_GEOMETRY:
|
||
234 | 43020 | jjdelcerro | default:
|
235 | 44652 | jjdelcerro | return this.value; |
236 | 43020 | jjdelcerro | } |
237 | 43093 | jjdelcerro | } catch (Exception ex) { |
238 | throw new RuntimeException("Can't get value from parameter.", ex); |
||
239 | 43020 | jjdelcerro | } |
240 | } |
||
241 | 44769 | jjdelcerro | |
242 | @Override
|
||
243 | public String toString() { |
||
244 | return this.toString(this.builder.builder().formatter()); |
||
245 | } |
||
246 | 43020 | jjdelcerro | |
247 | @Override
|
||
248 | 44198 | jjdelcerro | public String toString(Formatter<Value> formatter) { |
249 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
250 | 44198 | jjdelcerro | return formatter.format(this); |
251 | } |
||
252 | 43093 | jjdelcerro | switch (this.type) { |
253 | 44644 | jjdelcerro | case PARAMETER_TYPE_CONSTANT:
|
254 | if( this.value instanceof Geometry ) { |
||
255 | switch (this.builder.geometry_support_type()) { |
||
256 | case EWKB:
|
||
257 | return MessageFormat.format( |
||
258 | FORMAT_ST_GEOMFROMEWKB, |
||
259 | "?",
|
||
260 | this.getSRS(formatter)
|
||
261 | ); |
||
262 | case WKB:
|
||
263 | return MessageFormat.format( |
||
264 | FORMAT_ST_GEOMFROMWKB, |
||
265 | "?",
|
||
266 | this.getSRS(formatter)
|
||
267 | ); |
||
268 | case WKT:
|
||
269 | default:
|
||
270 | return MessageFormat.format( |
||
271 | FORMAT_ST_GEOMFROMTEXT, |
||
272 | "?",
|
||
273 | this.getSRS(formatter)
|
||
274 | ); |
||
275 | } |
||
276 | 44198 | jjdelcerro | } |
277 | 44644 | jjdelcerro | case PARAMETER_TYPE_VARIABLE:
|
278 | 43020 | jjdelcerro | default:
|
279 | return "?"; |
||
280 | 44644 | jjdelcerro | case PARAMETER_TYPE_GEOMETRY:
|
281 | switch (this.builder.geometry_support_type()) { |
||
282 | 43020 | jjdelcerro | case EWKB:
|
283 | return MessageFormat.format( |
||
284 | 44198 | jjdelcerro | FORMAT_ST_GEOMFROMEWKB, |
285 | "?",
|
||
286 | getSRS(formatter) |
||
287 | 43020 | jjdelcerro | ); |
288 | case WKB:
|
||
289 | return MessageFormat.format( |
||
290 | 44198 | jjdelcerro | FORMAT_ST_GEOMFROMWKB, |
291 | "?",
|
||
292 | getSRS(formatter) |
||
293 | 43020 | jjdelcerro | ); |
294 | case WKT:
|
||
295 | default:
|
||
296 | return MessageFormat.format( |
||
297 | 44198 | jjdelcerro | FORMAT_ST_GEOMFROMTEXT, |
298 | "?",
|
||
299 | getSRS(formatter) |
||
300 | 43093 | jjdelcerro | ); |
301 | } |
||
302 | 43020 | jjdelcerro | } |
303 | 43093 | jjdelcerro | } |
304 | 44644 | jjdelcerro | |
305 | 44198 | jjdelcerro | private String getSRS(Formatter formatter) { |
306 | if( this.srs!=null ) { |
||
307 | return this.srs.toString(formatter); |
||
308 | } |
||
309 | if( this.value instanceof Geometry ) { |
||
310 | IProjection proj = ((Geometry)this.value).getProjection();
|
||
311 | 44644 | jjdelcerro | Object s = this.builder.srs_id(proj); |
312 | 44198 | jjdelcerro | if( s == null ) { |
313 | throw new IllegalArgumentException("A parameter of type Geometry with an invalid SRS."); |
||
314 | } |
||
315 | return s.toString();
|
||
316 | } |
||
317 | throw new IllegalArgumentException("The parameter of type Geometry need a SRS."); |
||
318 | } |
||
319 | 44644 | jjdelcerro | |
320 | 43020 | jjdelcerro | } |
321 | |||
322 | 44644 | jjdelcerro | //
|
323 | // public static class ProjectionParameterBase
|
||
324 | // extends ParameterBase
|
||
325 | // implements Parameter {
|
||
326 | //
|
||
327 | // protected GeometryExpressionBuilderHelper builder;
|
||
328 | //
|
||
329 | // public ProjectionParameterBase(GeometryExpressionBuilderHelper builder) {
|
||
330 | // this.builder = builder;
|
||
331 | // }
|
||
332 | //
|
||
333 | // @Override
|
||
334 | // public Parameter value(Object value) {
|
||
335 | // if( !(value instanceof IProjection) ) {
|
||
336 | // throw new IllegalArgumentException("Only IProjection are allowed.");
|
||
337 | // }
|
||
338 | // return super.value(value);
|
||
339 | // }
|
||
340 | //
|
||
341 | // @Override
|
||
342 | // public Object value() {
|
||
343 | // try {
|
||
344 | // switch (this.type) {
|
||
345 | // case PARAMETER_TYPE_CONSTANT:
|
||
346 | // return this.builder.srs_id((IProjection) this.value);
|
||
347 | // case PARAMETER_TYPE_VARIABLE:
|
||
348 | // default:
|
||
349 | // return this.value;
|
||
350 | // }
|
||
351 | // } catch (Exception ex) {
|
||
352 | // throw new RuntimeException("Can't get value from parameter.", ex);
|
||
353 | // }
|
||
354 | // }
|
||
355 | // }
|
||
356 | |||
357 | public static class GeometryConstant extends AbstractValue implements Constant { |
||
358 | 43093 | jjdelcerro | |
359 | 44644 | jjdelcerro | protected Geometry geometry;
|
360 | protected GeometryExpressionBuilderHelper builder;
|
||
361 | |||
362 | public GeometryConstant(GeometryExpressionBuilderHelper builder, Geometry geometry) {
|
||
363 | this.builder = builder;
|
||
364 | this.geometry = geometry;
|
||
365 | 43020 | jjdelcerro | } |
366 | 43093 | jjdelcerro | |
367 | 43020 | jjdelcerro | @Override
|
368 | 44769 | jjdelcerro | public String toString() { |
369 | return this.toString(builder.builder().formatter()); |
||
370 | } |
||
371 | |||
372 | @Override
|
||
373 | 44198 | jjdelcerro | public String toString(Formatter<Value> formatter) { |
374 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
375 | 44198 | jjdelcerro | return formatter.format(this); |
376 | } |
||
377 | 44644 | jjdelcerro | try {
|
378 | switch (this.builder.geometry_support_type()) { |
||
379 | 44198 | jjdelcerro | case EWKB:
|
380 | return MessageFormat.format( |
||
381 | FORMAT_ST_GEOMFROMEWKB, |
||
382 | 44644 | jjdelcerro | "DECODE('"+this.builder.builder().bytearray_hex(GeometryUtils.toEWKB(geometry))+"','hex')", |
383 | this.getSRS()
|
||
384 | 44198 | jjdelcerro | ); |
385 | case WKB:
|
||
386 | return MessageFormat.format( |
||
387 | FORMAT_ST_GEOMFROMWKB, |
||
388 | 44644 | jjdelcerro | "DECODE('"+this.builder.builder().bytearray_hex(GeometryUtils.toWKB(geometry))+"','hex')", |
389 | this.getSRS()
|
||
390 | 44198 | jjdelcerro | ); |
391 | case WKT:
|
||
392 | default:
|
||
393 | return MessageFormat.format( |
||
394 | FORMAT_ST_GEOMFROMTEXT, |
||
395 | 44644 | jjdelcerro | this.builder.builder().string(GeometryUtils.toWKT(geometry)),
|
396 | this.getSRS()
|
||
397 | 44198 | jjdelcerro | ); |
398 | } |
||
399 | 44644 | jjdelcerro | } catch(Throwable th) { |
400 | throw th;
|
||
401 | 44198 | jjdelcerro | } |
402 | 43020 | jjdelcerro | } |
403 | |||
404 | @Override
|
||
405 | 44198 | jjdelcerro | public Object value() { |
406 | 44644 | jjdelcerro | return this.geometry; |
407 | 43020 | jjdelcerro | } |
408 | |||
409 | 44644 | jjdelcerro | private String getSRS() { |
410 | IProjection proj = this.geometry.getProjection();
|
||
411 | Object s = this.builder.srs_id(proj); |
||
412 | if( s == null ) { |
||
413 | throw new IllegalArgumentException("A parameter of type Geometry with an invalid SRS."); |
||
414 | 43020 | jjdelcerro | } |
415 | 44644 | jjdelcerro | return s.toString();
|
416 | 43020 | jjdelcerro | } |
417 | |||
418 | 43093 | jjdelcerro | } |
419 | 43020 | jjdelcerro | |
420 | 44644 | jjdelcerro | public static class ProjectionConstant extends AbstractValue implements Constant { |
421 | 43020 | jjdelcerro | |
422 | 44644 | jjdelcerro | protected IProjection projection;
|
423 | protected GeometryExpressionBuilderHelper builder;
|
||
424 | 44020 | jjdelcerro | |
425 | 44644 | jjdelcerro | public ProjectionConstant(GeometryExpressionBuilderHelper builder, IProjection projection) {
|
426 | this.projection = projection;
|
||
427 | this.builder = builder;
|
||
428 | 43093 | jjdelcerro | } |
429 | 43020 | jjdelcerro | |
430 | @Override
|
||
431 | 44769 | jjdelcerro | public String toString() { |
432 | return this.toString(this.builder.builder().formatter()); |
||
433 | } |
||
434 | |||
435 | @Override
|
||
436 | 44198 | jjdelcerro | public String toString(Formatter<Value> formatter) { |
437 | 44296 | jjdelcerro | if( formatter!=null && formatter.canApply(this) ) { |
438 | 44198 | jjdelcerro | return formatter.format(this); |
439 | } |
||
440 | 44644 | jjdelcerro | return Objects.toString(this.builder.srs_id(this.projection)); |
441 | 43020 | jjdelcerro | } |
442 | 43093 | jjdelcerro | |
443 | 44198 | jjdelcerro | @Override
|
444 | 44644 | jjdelcerro | public Object value() { |
445 | return this.projection; |
||
446 | 44198 | jjdelcerro | } |
447 | |||
448 | } |
||
449 | |||
450 | protected GeometrySupportType geometrySupportType;
|
||
451 | 44644 | jjdelcerro | protected ExpressionBuilder builder;
|
452 | 43093 | jjdelcerro | |
453 | 44644 | jjdelcerro | public DefaultGeometryExpressionBuilderHelper(ExpressionBuilder builder) {
|
454 | this.builder = builder;
|
||
455 | 44198 | jjdelcerro | this.geometrySupportType = GeometrySupportType.WKB;
|
456 | 43020 | jjdelcerro | } |
457 | 44644 | jjdelcerro | |
458 | public DefaultGeometryExpressionBuilderHelper() {
|
||
459 | this.geometrySupportType = GeometrySupportType.WKB;
|
||
460 | } |
||
461 | 43020 | jjdelcerro | |
462 | @Override
|
||
463 | 44644 | jjdelcerro | public ExpressionBuilder builder() {
|
464 | return this.builder; |
||
465 | 44259 | jjdelcerro | } |
466 | |||
467 | @Override
|
||
468 | 44198 | jjdelcerro | public GeometrySupportType geometry_support_type() {
|
469 | return this.geometrySupportType; |
||
470 | 43093 | jjdelcerro | } |
471 | |||
472 | 43020 | jjdelcerro | @Override
|
473 | 44644 | jjdelcerro | public GeometryExpressionBuilderHelper geometry_support_type(GeometrySupportType geometrySupportType) {
|
474 | 44198 | jjdelcerro | this.geometrySupportType = geometrySupportType;
|
475 | return this; |
||
476 | } |
||
477 | |||
478 | 43020 | jjdelcerro | @Override
|
479 | 44198 | jjdelcerro | public Object srs_id(IProjection projection) { |
480 | 44006 | jjdelcerro | if( projection==null ) { |
481 | return 0; |
||
482 | } |
||
483 | return ProjectionUtils.getCode(projection);
|
||
484 | 43020 | jjdelcerro | } |
485 | 43093 | jjdelcerro | |
486 | 43020 | jjdelcerro | @Override
|
487 | public Constant srs(IProjection projection) {
|
||
488 | 44983 | jjdelcerro | if( projection == null ) { |
489 | return this.builder.constant(null); |
||
490 | } |
||
491 | 44644 | jjdelcerro | return new ProjectionConstant(this, projection); |
492 | 43020 | jjdelcerro | } |
493 | |||
494 | @Override
|
||
495 | 44198 | jjdelcerro | public Constant geometry(Geometry geom, IProjection projection) {
|
496 | 44983 | jjdelcerro | if( geom == null ) { |
497 | return this.builder.constant(null); |
||
498 | } |
||
499 | 44198 | jjdelcerro | geom.setProjection(projection); |
500 | 44644 | jjdelcerro | return new GeometryConstant(this, geom); |
501 | 43020 | jjdelcerro | } |
502 | |||
503 | @Override
|
||
504 | 44198 | jjdelcerro | public Constant geometry(Geometry geom) {
|
505 | 44983 | jjdelcerro | if( geom == null ) { |
506 | return this.builder.constant(null); |
||
507 | } |
||
508 | 44006 | jjdelcerro | if( geom.getProjection()==null ) { |
509 | throw new IllegalArgumentException("The geometry does not have an associated projection. Use 'geometry(Geometry, IProjection)'."); |
||
510 | } |
||
511 | 44644 | jjdelcerro | return new GeometryConstant(this, geom); |
512 | 44006 | jjdelcerro | } |
513 | |||
514 | @Override
|
||
515 | 44198 | jjdelcerro | public Constant envelope(Envelope envelope, IProjection projection) {
|
516 | 44983 | jjdelcerro | if( envelope == null ) { |
517 | return this.builder.constant(null); |
||
518 | } |
||
519 | 44198 | jjdelcerro | Geometry geom = envelope.getGeometry(); |
520 | geom.setProjection(projection); |
||
521 | 44644 | jjdelcerro | return new GeometryConstant(this, geom); |
522 | 43034 | jjdelcerro | } |
523 | |||
524 | @Override
|
||
525 | 44198 | jjdelcerro | public Constant envelope(Envelope envelope) {
|
526 | 44983 | jjdelcerro | if( envelope == null ) { |
527 | return this.builder.constant(null); |
||
528 | } |
||
529 | 44006 | jjdelcerro | if( envelope.getProjection()==null ) { |
530 | throw new IllegalArgumentException("The envelope does not have an associated projection. Use 'envelope(Geometry, IProjection)'."); |
||
531 | } |
||
532 | 44198 | jjdelcerro | Geometry geom = envelope.getGeometry(); |
533 | 44644 | jjdelcerro | return new GeometryConstant(this, geom); |
534 | 44006 | jjdelcerro | } |
535 | |||
536 | @Override
|
||
537 | 44644 | jjdelcerro | public GeometryParameter parameter() {
|
538 | GeometryParameterBase p = new GeometryParameterBase(this); |
||
539 | return p;
|
||
540 | 43020 | jjdelcerro | } |
541 | |||
542 | 44198 | jjdelcerro | @Override
|
543 | 44644 | jjdelcerro | public GeometryParameter parameter(String name) { |
544 | GeometryParameterBase p = new GeometryParameterBase(this); |
||
545 | p.name(name); |
||
546 | return p;
|
||
547 | 44198 | jjdelcerro | } |
548 | 44644 | jjdelcerro | |
549 | 44198 | jjdelcerro | @Override
|
550 | 44644 | jjdelcerro | public GeometryParameter parameter(Object value) { |
551 | GeometryParameterBase p = new GeometryParameterBase(this); |
||
552 | p.value(value); |
||
553 | return p;
|
||
554 | 44020 | jjdelcerro | } |
555 | |||
556 | public Function builtin_function(String name, String format, Value... values) { |
||
557 | 44769 | jjdelcerro | Function func = this.builder.function(name, values);
|
558 | func.format(format); |
||
559 | 43020 | jjdelcerro | return func;
|
560 | 44644 | jjdelcerro | } |
561 | 44198 | jjdelcerro | |
562 | 44644 | jjdelcerro | public Function function(String name, Value... values) { |
563 | 44769 | jjdelcerro | Function func = this.builder.function(name, values);
|
564 | 44644 | jjdelcerro | return func;
|
565 | } |
||
566 | 44198 | jjdelcerro | |
567 | @Override
|
||
568 | public Function as_geometry(Value value) {
|
||
569 | return builtin_function(FUNCTION_ST_ASBINARY, FORMAT_ST_ASBINARY, value);
|
||
570 | } |
||
571 | 43020 | jjdelcerro | |
572 | @Override
|
||
573 | public Function ST_Intersects(Value geom1, Value geom2) {
|
||
574 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_INTERSECTS, FORMAT_ST_INTERSECTS, geom1, geom2);
|
575 | 43020 | jjdelcerro | } |
576 | |||
577 | @Override
|
||
578 | public Function ST_SRID(Value geom) {
|
||
579 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_SRID, FORMAT_ST_SRID, geom);
|
580 | 43020 | jjdelcerro | } |
581 | |||
582 | @Override
|
||
583 | public Function ST_Envelope(Value geom) {
|
||
584 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_ENVELOPE, FORMAT_ST_ENVELOPE, geom);
|
585 | 43020 | jjdelcerro | } |
586 | |||
587 | @Override
|
||
588 | 44612 | jjdelcerro | public Function ST_Force2D(Value geom) {
|
589 | return builtin_function(FUNCTION_ST_FORCE2D, FORMAT_ST_FORCE2D, geom);
|
||
590 | } |
||
591 | |||
592 | @Override
|
||
593 | 43020 | jjdelcerro | public Function ST_AsText(Value geom) {
|
594 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_ASTEXT, FORMAT_ST_ASTEXT, geom);
|
595 | 43020 | jjdelcerro | } |
596 | |||
597 | @Override
|
||
598 | public Function ST_AsBinary(Value geom) {
|
||
599 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_ASBINARY, FORMAT_ST_ASBINARY, geom);
|
600 | 43020 | jjdelcerro | } |
601 | |||
602 | @Override
|
||
603 | public Function ST_AsEWKB(Value geom) {
|
||
604 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_ASEWKB, FORMAT_ST_ASEWKB, geom);
|
605 | 43020 | jjdelcerro | } |
606 | |||
607 | @Override
|
||
608 | public Function ST_GeomFromText(Value geom, Value crs) {
|
||
609 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_GEOMFROMTEXT, FORMAT_ST_GEOMFROMTEXT, geom, crs);
|
610 | 43020 | jjdelcerro | } |
611 | |||
612 | @Override
|
||
613 | public Function ST_GeomFromWKB(Value geom, Value crs) {
|
||
614 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_GEOMFROMWKB, FORMAT_ST_GEOMFROMWKB, geom, crs);
|
615 | 43020 | jjdelcerro | } |
616 | |||
617 | @Override
|
||
618 | public Function ST_GeomFromEWKB(Value geom, Value crs) {
|
||
619 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_GEOMFROMEWKB, FORMAT_ST_GEOMFROMEWKB, geom, crs);
|
620 | 43020 | jjdelcerro | } |
621 | |||
622 | @Override
|
||
623 | 43355 | jjdelcerro | public Function ST_Simplify(Value geom, Value tolerance) {
|
624 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_SIMPLIFY, FORMAT_ST_SIMPLIFY, tolerance);
|
625 | 43355 | jjdelcerro | } |
626 | |||
627 | @Override
|
||
628 | 43034 | jjdelcerro | public Function ST_Disjoint(Value geom1, Value geom2) {
|
629 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_DISJOINT, FORMAT_ST_DISJOINT, geom1, geom2);
|
630 | 43034 | jjdelcerro | } |
631 | 43093 | jjdelcerro | |
632 | 43034 | jjdelcerro | @Override
|
633 | 43020 | jjdelcerro | public Function ST_Contains(Value geom1, Value geom2) {
|
634 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_CONTAINS, FORMAT_ST_CONTAINS, geom1, geom2);
|
635 | 43020 | jjdelcerro | } |
636 | |||
637 | @Override
|
||
638 | 43034 | jjdelcerro | public Function ST_Equals(Value geom1, Value geom2) {
|
639 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_EQUALS, FORMAT_ST_EQUALS, geom1, geom2);
|
640 | 43034 | jjdelcerro | } |
641 | |||
642 | @Override
|
||
643 | 43020 | jjdelcerro | public Function ST_Crosses(Value geom1, Value geom2) {
|
644 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_CROSSES, FORMAT_ST_CROSSES, geom1, geom2);
|
645 | 43020 | jjdelcerro | } |
646 | |||
647 | @Override
|
||
648 | public Function ST_IsClosed(Value geom) {
|
||
649 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_ISCLOSED, FORMAT_ST_ISCLOSED, geom);
|
650 | 43020 | jjdelcerro | } |
651 | |||
652 | @Override
|
||
653 | public Function ST_Overlaps(Value geom1, Value geom2) {
|
||
654 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_OVERLAPS, FORMAT_ST_OVERLAPS, geom1, geom2);
|
655 | 43020 | jjdelcerro | } |
656 | |||
657 | @Override
|
||
658 | public Function ST_Touches(Value geom1, Value geom2) {
|
||
659 | 44198 | jjdelcerro | return builtin_function(FUNCTION_ST_TOUCHES, FORMAT_ST_TOUCHES, geom1, geom2);
|
660 | 43020 | jjdelcerro | } |
661 | |||
662 | @Override
|
||
663 | public Function ST_Within(Value geom1, Value geom2) {
|
||
664 | 44198 | jjdelcerro | return builtin_function("ST_Within", FORMAT_ST_WITHIN, geom1, geom2); |
665 | 43020 | jjdelcerro | } |
666 | |||
667 | @Override
|
||
668 | 44364 | jjdelcerro | public Function ST_Area(Value geom) {
|
669 | return function("ST_Area", geom); |
||
670 | } |
||
671 | |||
672 | @Override
|
||
673 | public Function ST_Buffer(Value geom) {
|
||
674 | return function("ST_Buffer", geom); |
||
675 | } |
||
676 | |||
677 | @Override
|
||
678 | 44568 | jjdelcerro | public Function ST_Buffer(Value geom, Value dist) {
|
679 | return function("ST_Buffer", geom, dist); |
||
680 | } |
||
681 | |||
682 | @Override
|
||
683 | 44364 | jjdelcerro | public Function ST_Centroid(Value geom) {
|
684 | return function("ST_Centroid", geom); |
||
685 | } |
||
686 | |||
687 | @Override
|
||
688 | public Function ST_CoveredBy(Value geom1, Value geom2) {
|
||
689 | return function("ST_CoveredBy", geom1, geom2); |
||
690 | } |
||
691 | |||
692 | @Override
|
||
693 | public Function ST_Covers(Value geom1, Value geom2) {
|
||
694 | return function("ST_Covers", geom1, geom2); |
||
695 | } |
||
696 | |||
697 | @Override
|
||
698 | public Function ST_Diference(Value geom1, Value geom2) {
|
||
699 | return function("ST_Diference", geom1, geom2); |
||
700 | } |
||
701 | |||
702 | @Override
|
||
703 | public Function ST_Dimension(Value geom) {
|
||
704 | return function("ST_Dimension", geom); |
||
705 | } |
||
706 | |||
707 | @Override
|
||
708 | public Function ST_Distance(Value geom1, Value geom2) {
|
||
709 | return function("ST_Distance", geom1, geom2); |
||
710 | } |
||
711 | |||
712 | @Override
|
||
713 | public Function ST_EndPoint(Value geom) {
|
||
714 | return function("ST_EndPoint", geom); |
||
715 | } |
||
716 | |||
717 | @Override
|
||
718 | public Function ST_Intersection(Value geom1, Value geom2) {
|
||
719 | return function("ST_Intersection", geom1, geom2); |
||
720 | } |
||
721 | |||
722 | @Override
|
||
723 | public Function ST_IsSimple(Value geom) {
|
||
724 | return function("ST_IsSimple", geom); |
||
725 | } |
||
726 | |||
727 | @Override
|
||
728 | public Function ST_IsValid(Value geom) {
|
||
729 | return function("ST_IsValid", geom); |
||
730 | } |
||
731 | |||
732 | @Override
|
||
733 | public Function ST_NumGeometries(Value geom) {
|
||
734 | return function("ST_NumGeometries", geom); |
||
735 | } |
||
736 | |||
737 | @Override
|
||
738 | public Function ST_NumPoints(Value geom) {
|
||
739 | return function("ST_NumPoints", geom); |
||
740 | } |
||
741 | |||
742 | @Override
|
||
743 | public Function ST_Perimeter(Value geom) {
|
||
744 | return function("ST_Perimeter", geom); |
||
745 | } |
||
746 | |||
747 | @Override
|
||
748 | public Function ST_PointN(Value geom, Value n) {
|
||
749 | return function("ST_PointN", geom, n); |
||
750 | } |
||
751 | |||
752 | @Override
|
||
753 | public Function ST_StartPoint(Value geom) {
|
||
754 | return function("ST_StartPoint", geom); |
||
755 | } |
||
756 | |||
757 | @Override
|
||
758 | public Function ST_Union(Value geom1, Value geom2) {
|
||
759 | return function("ST_Union", geom1, geom2); |
||
760 | } |
||
761 | |||
762 | @Override
|
||
763 | public Function ST_X(Value geom) {
|
||
764 | return function("ST_X", geom); |
||
765 | } |
||
766 | |||
767 | @Override
|
||
768 | public Function ST_Y(Value geom) {
|
||
769 | return function("ST_Y", geom); |
||
770 | } |
||
771 | |||
772 | @Override
|
||
773 | public Function ST_Z(Value geom) {
|
||
774 | return function("ST_Z", geom); |
||
775 | } |
||
776 | |||
777 | @Override
|
||
778 | 44198 | jjdelcerro | public Function ST_ExtentAggregate(Value geom) {
|
779 | return function(FUNCTION_ST_EXTENTAGGREGATE, geom);
|
||
780 | 44053 | omartinez | } |
781 | 44198 | jjdelcerro | |
782 | @Override
|
||
783 | public Function ST_UnionAggregate(Value geom) {
|
||
784 | return function(FUNCTION_ST_UNIONAGGREGATE, geom);
|
||
785 | } |
||
786 | |||
787 | @Override
|
||
788 | 44253 | jjdelcerro | public Function ST_Point(Value x, Value y) {
|
789 | return function(FUNCTION_ST_POINT, x, y);
|
||
790 | } |
||
791 | 44198 | jjdelcerro | |
792 | 44253 | jjdelcerro | @Override
|
793 | 44431 | jjdelcerro | public Function ST_MakePoint(Value x, Value y) {
|
794 | return function(FUNCTION_ST_MAKEPOINT, x, y);
|
||
795 | } |
||
796 | |||
797 | @Override
|
||
798 | public Function ST_MakePoint(Value x, Value y, Value z) {
|
||
799 | return function(FUNCTION_ST_MAKEPOINT, x, y, z);
|
||
800 | } |
||
801 | |||
802 | @Override
|
||
803 | public Function ST_MakePoint(Value x, Value y, Value z, Value m) {
|
||
804 | return function(FUNCTION_ST_MAKEPOINT, x, y, z, m);
|
||
805 | } |
||
806 | |||
807 | @Override
|
||
808 | 44253 | jjdelcerro | public Function ST_SetSRID(Value geom, Value srid) {
|
809 | return function(FUNCTION_ST_POINT, geom, srid);
|
||
810 | } |
||
811 | 44376 | jjdelcerro | |
812 | 43020 | jjdelcerro | } |