Revision 44644 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.lib/org.gvsig.expressionevaluator.lib.impl/src/main/java/org/gvsig/expressionevaluator/impl/DefaultExpressionBuilder.java
DefaultExpressionBuilder.java | ||
---|---|---|
8 | 8 |
import java.util.Objects; |
9 | 9 |
import java.util.Set; |
10 | 10 |
import org.apache.commons.lang3.StringUtils; |
11 |
import org.cresques.cts.IProjection; |
|
12 | 11 |
import org.gvsig.expressionevaluator.Code; |
13 | 12 |
import org.gvsig.expressionevaluator.Expression; |
14 |
import org.gvsig.fmap.geom.Geometry; |
|
15 |
import org.gvsig.fmap.geom.primitive.Envelope; |
|
16 | 13 |
|
17 | 14 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
18 | 15 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.EMPTY_FORMATTER; |
16 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_CONSTANT; |
|
17 |
import static org.gvsig.expressionevaluator.ExpressionBuilder.PARAMETER_TYPE_VARIABLE; |
|
18 |
import org.gvsig.expressionevaluator.ExpressionEvaluatorManager; |
|
19 | 19 |
import org.gvsig.expressionevaluator.ExpressionUtils; |
20 | 20 |
import org.gvsig.expressionevaluator.Formatter; |
21 |
import org.gvsig.fmap.geom.GeometryUtils; |
|
22 | 21 |
|
23 | 22 |
@SuppressWarnings({"UseSpecificCatch" ,"OverridableMethodCallInConstructor"}) |
24 | 23 |
public class DefaultExpressionBuilder implements ExpressionBuilder { |
... | ... | |
31 | 30 |
|
32 | 31 |
private static final String FORMAT_GROUP = "( {0} )"; |
33 | 32 |
|
34 |
private static final String FORMAT_ST_SRID = "ST_SRID({0})"; |
|
35 |
private static final String FORMAT_ST_ASTEXT = "ST_AsText({0})"; |
|
36 |
private static final String FORMAT_ST_ASBINARY = "ST_AsBinary({0})"; |
|
37 |
private static final String FORMAT_ST_ASEWKB = "ST_AsEWKB({0})"; |
|
38 |
private static final String FORMAT_ST_CONTAINS = "ST_Contains(({0}), ({1}))"; |
|
39 |
private static final String FORMAT_ST_CROSSES = "ST_Crosses(({0}), ({1}))"; |
|
40 |
private static final String FORMAT_ST_DISJOINT = "ST_Disjoint(({0}), ({1}))"; |
|
41 |
private static final String FORMAT_ST_EQUALS = "ST_Equals(({0}), ({1}))"; |
|
42 |
private static final String FORMAT_ST_ISCLOSED = "ST_IsClosed({0})"; |
|
43 |
private static final String FORMAT_ST_OVERLAPS = "ST_Overlaps(({0}), ({1}))"; |
|
44 |
private static final String FORMAT_ST_TOUCHES = "ST_Touches(({0}), ({1}))"; |
|
45 |
private static final String FORMAT_ST_WITHIN = "ST_Within(({0}), ({1}))"; |
|
46 |
private static final String FORMAT_ST_ENVELOPE = "ST_Envelope({0})"; |
|
47 |
private static final String FORMAT_ST_FORCE2D = "ST_Force2D({0})"; |
|
48 |
private static final String FORMAT_ST_INTERSECTS = "ST_Intersects(({0}), ({1}))"; |
|
49 |
private static final String FORMAT_ST_GEOMFROMTEXT = "ST_GeomFromText(({0}), ({1}))"; |
|
50 |
private static final String FORMAT_ST_GEOMFROMWKB = "ST_GeomFromWKB(({0}), ({1}))"; |
|
51 |
private static final String FORMAT_ST_GEOMFROMEWKB = "ST_GeomFromEWKB(({0}), ({1}))"; |
|
52 |
private static final String FORMAT_ST_SIMPLIFY = "ST_Simplify(({0}), ({1}))"; |
|
53 |
|
|
54 | 33 |
private static final String FORMAT_ISNULL = "( ({0}) IS NULL )"; |
55 | 34 |
private static final String FORMAT_NOTISNULL = "( ({0}) IS NOT NULL )"; |
56 | 35 |
private static final String FORMAT_OPERATOR_NOT = "( NOT ({0}) )"; |
... | ... | |
71 | 50 |
private static final String FORMAT_OPERATOR_DIV = "({0} / {1})"; |
72 | 51 |
private static final String FORMAT_OPERATOR_CONCAT = "{0} || {1}"; |
73 | 52 |
|
74 |
public class GroupBase extends AbstractValue implements Group { |
|
53 |
public static class GroupBase extends AbstractValue implements Group {
|
|
75 | 54 |
|
76 | 55 |
protected Value value; |
77 | 56 |
|
... | ... | |
113 | 92 |
} |
114 | 93 |
} |
115 | 94 |
|
116 |
public class VariableBase extends AbstractValue implements Variable { |
|
95 |
public static class VariableBase extends AbstractValue implements Variable {
|
|
117 | 96 |
|
118 | 97 |
protected String name; |
119 |
|
|
120 |
public VariableBase(String name) { |
|
98 |
protected ExpressionBuilder builder; |
|
99 |
|
|
100 |
public VariableBase(ExpressionBuilder builder, String name) { |
|
121 | 101 |
this.name = name; |
102 |
this.builder = builder; |
|
122 | 103 |
} |
123 | 104 |
|
124 | 105 |
@Override |
... | ... | |
136 | 117 |
if( formatter!=null && formatter.canApply(this) ) { |
137 | 118 |
return formatter.format(this); |
138 | 119 |
} |
139 |
return identifier(this.name); |
|
120 |
return this.builder.identifier(this.name);
|
|
140 | 121 |
} |
141 | 122 |
|
142 | 123 |
@Override |
... | ... | |
160 | 141 |
} |
161 | 142 |
} |
162 | 143 |
|
163 |
public class ParameterBase extends AbstractValue implements Parameter { |
|
144 |
public static class ParameterBase extends AbstractValue implements Parameter {
|
|
164 | 145 |
|
165 | 146 |
protected String name; |
166 | 147 |
protected Object value; |
167 |
protected ParameterType type; |
|
168 |
protected Value srs; |
|
148 |
protected int type; |
|
169 | 149 |
|
170 |
/* |
|
171 |
Para un parametre de tipo Geometria, el srs sera siempre un Constant |
|
172 |
excepto cuando se le asigne una geometria contante al parametro y esta |
|
173 |
tenga un SRS asignado. En este caso, tanto la geometria como el SRS |
|
174 |
se trataran como parametros. |
|
175 |
|
|
176 |
Si se quiere que el SRS sea un Parameter, se construira como tal y se |
|
177 |
asignara a traves del metodo srs(Value srs). |
|
178 |
*/ |
|
179 | 150 |
public ParameterBase() { |
180 |
this.type = ParameterType.Constant;
|
|
151 |
this.type = PARAMETER_TYPE_CONSTANT;
|
|
181 | 152 |
this.name = null; |
182 | 153 |
this.value = null; |
183 | 154 |
} |
184 | 155 |
|
185 | 156 |
@Override |
186 |
public void accept(Visitor visitor, VisitorFilter filter) { |
|
187 |
super.accept(visitor, filter); |
|
188 |
if (this.srs != null) { |
|
189 |
this.srs.accept(visitor, filter); |
|
190 |
} |
|
191 |
} |
|
192 |
|
|
193 |
@Override |
|
194 |
public void replace(Value target, Value replacement) { |
|
195 |
if( this.srs == target ) { |
|
196 |
this.srs = replacement; |
|
197 |
} else { |
|
198 |
this.srs.replace(target, replacement); |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
202 |
@Override |
|
203 |
public Parameter as_geometry_variable() { |
|
204 |
this.type = ParameterType.Geometry; |
|
205 |
if (this.value == null && this.name != null) { |
|
206 |
this.value = this.name; |
|
207 |
} |
|
208 |
return this; |
|
209 |
} |
|
210 |
|
|
211 |
@Override |
|
212 | 157 |
public Parameter as_constant() { |
213 |
this.type = ParameterType.Constant;
|
|
158 |
this.type = PARAMETER_TYPE_CONSTANT;
|
|
214 | 159 |
if (this.value == null && this.name != null) { |
215 | 160 |
this.value = this.name; |
216 | 161 |
} |
... | ... | |
219 | 164 |
|
220 | 165 |
@Override |
221 | 166 |
public Parameter as_variable() { |
222 |
this.type = ParameterType.Variable;
|
|
167 |
this.type = PARAMETER_TYPE_VARIABLE;
|
|
223 | 168 |
if (this.value != null && this.name == null) { |
224 | 169 |
this.name = (String) this.value; |
225 | 170 |
} |
226 | 171 |
return this; |
227 | 172 |
} |
228 |
|
|
173 |
|
|
229 | 174 |
@Override |
230 |
public Parameter srs(Value srs) { |
|
231 |
this.srs = srs; |
|
232 |
if( this.type == ParameterType.Variable ) { |
|
233 |
this.type = ParameterType.Geometry; |
|
234 |
} |
|
235 |
return this; |
|
236 |
} |
|
237 |
|
|
238 |
@Override |
|
239 |
public Parameter srs(IProjection srs) { |
|
240 |
this.srs = constant(srs_id(srs)); |
|
241 |
if( this.type == ParameterType.Variable ) { |
|
242 |
this.type = ParameterType.Geometry; |
|
243 |
} |
|
244 |
return this; |
|
245 |
} |
|
246 |
|
|
247 |
@Override |
|
248 | 175 |
public String name() { |
249 | 176 |
switch (this.type) { |
250 |
case Variable: |
|
251 |
case Geometry: |
|
177 |
case PARAMETER_TYPE_VARIABLE: |
|
252 | 178 |
return this.name; |
253 |
case Constant:
|
|
179 |
case PARAMETER_TYPE_CONSTANT:
|
|
254 | 180 |
if (this.value == null) { |
255 | 181 |
return null; |
256 | 182 |
} |
... | ... | |
267 | 193 |
} |
268 | 194 |
|
269 | 195 |
@Override |
270 |
public boolean is_constant() {
|
|
271 |
return this.type == ParameterType.Constant;
|
|
196 |
public int type() {
|
|
197 |
return this.type; |
|
272 | 198 |
} |
273 | 199 |
|
274 | 200 |
@Override |
275 |
public boolean is_geometry_variable() {
|
|
276 |
return this.type == ParameterType.Geometry;
|
|
201 |
public boolean is_constant() {
|
|
202 |
return this.type == PARAMETER_TYPE_CONSTANT;
|
|
277 | 203 |
} |
278 | 204 |
|
279 | 205 |
@Override |
280 | 206 |
public boolean is_variable() { |
281 |
return this.type == ParameterType.Variable;
|
|
207 |
return this.type == PARAMETER_TYPE_VARIABLE;
|
|
282 | 208 |
} |
283 | 209 |
|
284 | 210 |
@Override |
285 | 211 |
public Parameter value(Object value) { |
286 |
if( value instanceof Geometry ) { |
|
287 |
if( this.srs == null ) { |
|
288 |
IProjection proj = ((Geometry)value).getProjection(); |
|
289 |
this.srs(parameter().value(proj)); |
|
290 |
} |
|
291 |
} |
|
292 | 212 |
this.value = value; |
293 | 213 |
return this; |
294 | 214 |
} |
295 | 215 |
|
296 | 216 |
@Override |
297 | 217 |
public Parameter name(String name) { |
298 |
this.type = ParameterType.Variable;
|
|
218 |
this.type = PARAMETER_TYPE_VARIABLE;
|
|
299 | 219 |
this.name = name; |
300 | 220 |
return this; |
301 | 221 |
} |
... | ... | |
304 | 224 |
public Object value() { |
305 | 225 |
try { |
306 | 226 |
switch (this.type) { |
307 |
case Constant: |
|
308 |
if( this.value instanceof Geometry ) { |
|
309 |
Geometry geometry = (Geometry) this.value; |
|
310 |
switch (geometry_support_type()) { |
|
311 |
case EWKB: |
|
312 |
return GeometryUtils.toEWKB(geometry); |
|
313 |
case WKB: |
|
314 |
return GeometryUtils.toWKB(geometry); |
|
315 |
case WKT: |
|
316 |
default: |
|
317 |
return GeometryUtils.toWKT(geometry); |
|
318 |
} |
|
319 |
} else if (this.value instanceof IProjection) { |
|
320 |
return srs_id((IProjection) this.value); |
|
321 |
} |
|
227 |
case PARAMETER_TYPE_CONSTANT: |
|
322 | 228 |
return this.value; |
323 |
case Variable: |
|
324 |
case Geometry: |
|
229 |
case PARAMETER_TYPE_VARIABLE: |
|
325 | 230 |
default: |
326 |
return this.value;
|
|
231 |
return this.name;
|
|
327 | 232 |
} |
328 | 233 |
} catch (Exception ex) { |
329 | 234 |
throw new RuntimeException("Can't get value from parameter.", ex); |
... | ... | |
331 | 236 |
} |
332 | 237 |
|
333 | 238 |
@Override |
334 |
public ParameterType type() { |
|
335 |
return this.type; |
|
336 |
} |
|
337 |
|
|
338 |
@Override |
|
339 |
public Value srs() { |
|
340 |
return this.srs; |
|
341 |
} |
|
342 |
|
|
343 |
@Override |
|
344 | 239 |
public String toString() { |
345 | 240 |
return this.toString(EMPTY_FORMATTER); |
346 | 241 |
} |
... | ... | |
351 | 246 |
return formatter.format(this); |
352 | 247 |
} |
353 | 248 |
switch (this.type) { |
354 |
case Constant: |
|
355 |
if( value instanceof Geometry ) { |
|
356 |
switch (geometry_support_type()) { |
|
357 |
case EWKB: |
|
358 |
return MessageFormat.format( |
|
359 |
FORMAT_ST_GEOMFROMEWKB, |
|
360 |
"?", |
|
361 |
getSRS(formatter) |
|
362 |
); |
|
363 |
case WKB: |
|
364 |
return MessageFormat.format( |
|
365 |
FORMAT_ST_GEOMFROMWKB, |
|
366 |
"?", |
|
367 |
getSRS(formatter) |
|
368 |
); |
|
369 |
case WKT: |
|
370 |
default: |
|
371 |
return MessageFormat.format( |
|
372 |
FORMAT_ST_GEOMFROMTEXT, |
|
373 |
"?", |
|
374 |
getSRS(formatter) |
|
375 |
); |
|
376 |
} |
|
377 |
} |
|
378 |
case Variable: |
|
249 |
case PARAMETER_TYPE_CONSTANT: |
|
250 |
return Objects.toString(this.value); |
|
251 |
|
|
252 |
case PARAMETER_TYPE_VARIABLE: |
|
379 | 253 |
default: |
380 | 254 |
return "?"; |
381 |
case Geometry: |
|
382 |
switch (geometry_support_type()) { |
|
383 |
case EWKB: |
|
384 |
return MessageFormat.format( |
|
385 |
FORMAT_ST_GEOMFROMEWKB, |
|
386 |
"?", |
|
387 |
getSRS(formatter) |
|
388 |
); |
|
389 |
case WKB: |
|
390 |
return MessageFormat.format( |
|
391 |
FORMAT_ST_GEOMFROMWKB, |
|
392 |
"?", |
|
393 |
getSRS(formatter) |
|
394 |
); |
|
395 |
case WKT: |
|
396 |
default: |
|
397 |
return MessageFormat.format( |
|
398 |
FORMAT_ST_GEOMFROMTEXT, |
|
399 |
"?", |
|
400 |
getSRS(formatter) |
|
401 |
); |
|
402 |
} |
|
403 | 255 |
} |
404 | 256 |
} |
405 |
|
|
406 |
private String getSRS(Formatter formatter) { |
|
407 |
if( this.srs!=null ) { |
|
408 |
return this.srs.toString(formatter); |
|
409 |
} |
|
410 |
if( this.value instanceof Geometry ) { |
|
411 |
IProjection proj = ((Geometry)this.value).getProjection(); |
|
412 |
Object s = srs_id(proj); |
|
413 |
if( s == null ) { |
|
414 |
throw new IllegalArgumentException("A parameter of type Geometry with an invalid SRS."); |
|
415 |
} |
|
416 |
return s.toString(); |
|
417 |
} |
|
418 |
throw new IllegalArgumentException("The parameter of type Geometry need a SRS."); |
|
419 |
} |
|
420 | 257 |
} |
421 | 258 |
|
422 |
public class ConstantBase extends AbstractValue implements Constant { |
|
259 |
public static class ConstantBase extends AbstractValue implements Constant {
|
|
423 | 260 |
|
424 | 261 |
protected Object value; |
425 |
|
|
426 |
public ConstantBase(Object value) { |
|
262 |
protected ExpressionBuilder builder; |
|
263 |
|
|
264 |
public ConstantBase(ExpressionBuilder builder, Object value) { |
|
427 | 265 |
this.value = value; |
266 |
this.builder = builder; |
|
428 | 267 |
} |
429 | 268 |
|
430 | 269 |
@Override |
... | ... | |
446 | 285 |
return "NULL"; |
447 | 286 |
} |
448 | 287 |
if( this.value instanceof byte[] ) { |
449 |
return "DECODE('"+bytearray_hex((byte[])this.value)+"','hex')"; |
|
288 |
return "DECODE('"+this.builder.bytearray_hex((byte[])this.value)+"','hex')";
|
|
450 | 289 |
} |
451 | 290 |
if (this.value instanceof String) { |
452 |
return string((String) this.value); |
|
291 |
return this.builder.string((String) this.value);
|
|
453 | 292 |
} |
454 |
if( this.value instanceof Geometry ) { |
|
455 |
Geometry geometry = (Geometry) this.value; |
|
456 |
switch (geometry_support_type()) { |
|
457 |
case EWKB: |
|
458 |
return MessageFormat.format( |
|
459 |
FORMAT_ST_GEOMFROMEWKB, |
|
460 |
"DECODE('"+bytearray_hex(GeometryUtils.toEWKB(geometry))+"','hex')", |
|
461 |
String.valueOf(srs_id(geometry.getProjection())) |
|
462 |
); |
|
463 |
case WKB: |
|
464 |
return MessageFormat.format( |
|
465 |
FORMAT_ST_GEOMFROMWKB, |
|
466 |
"DECODE('"+bytearray_hex(GeometryUtils.toWKB(geometry))+"','hex')", |
|
467 |
String.valueOf(srs_id(geometry.getProjection())) |
|
468 |
); |
|
469 |
case WKT: |
|
470 |
default: |
|
471 |
return MessageFormat.format( |
|
472 |
FORMAT_ST_GEOMFROMTEXT, |
|
473 |
string(GeometryUtils.toWKT(geometry)), |
|
474 |
String.valueOf(srs_id(geometry.getProjection())) |
|
475 |
); |
|
476 |
} |
|
477 |
} |
|
478 |
if( this.value instanceof IProjection ) { |
|
479 |
return Objects.toString(srs_id((IProjection)(this.value))); |
|
480 |
} |
|
481 | 293 |
if (this.value instanceof Boolean) { |
482 | 294 |
if (((Boolean) this.value)) { |
483 | 295 |
return FORMAT_TRUE; |
... | ... | |
489 | 301 |
} |
490 | 302 |
} |
491 | 303 |
|
492 |
public class CustomBase extends AbstractValue implements Custom { |
|
304 |
public static class CustomBase extends AbstractValue implements Custom {
|
|
493 | 305 |
|
494 | 306 |
protected Object value; |
495 | 307 |
|
... | ... | |
563 | 375 |
} |
564 | 376 |
} |
565 | 377 |
|
566 |
public class FunctionBase extends AbstractValue implements Function { |
|
378 |
public static class FunctionBase extends AbstractValue implements Function {
|
|
567 | 379 |
|
568 | 380 |
protected String name; |
569 | 381 |
protected String format; |
... | ... | |
600 | 412 |
@Override |
601 | 413 |
public void accept(Visitor visitor, VisitorFilter filter) { |
602 | 414 |
super.accept(visitor, filter); |
603 |
for (Value value : this.parameters) { |
|
604 |
value.accept(visitor, filter); |
|
415 |
if( this.parameters!=null ) { |
|
416 |
for (Value value : this.parameters) { |
|
417 |
if( value!=null ) { |
|
418 |
value.accept(visitor, filter); |
|
419 |
} |
|
420 |
} |
|
605 | 421 |
} |
606 | 422 |
} |
607 | 423 |
|
... | ... | |
696 | 512 |
builder.append(this.instance.toString(formatter)); |
697 | 513 |
builder.append("->"); |
698 | 514 |
builder.append(this.name()); |
699 |
builder.append(name); |
|
700 | 515 |
builder.append("("); |
701 | 516 |
if (this.parameters != null && !this.parameters.isEmpty()) { |
702 | 517 |
boolean first = true; |
... | ... | |
805 | 620 |
} |
806 | 621 |
} |
807 | 622 |
|
808 |
protected GeometrySupportType geometrySupportType; |
|
809 | 623 |
protected Value value; |
624 |
protected ExpressionEvaluatorManager manager; |
|
810 | 625 |
|
811 |
public DefaultExpressionBuilder() { |
|
812 |
this.geometrySupportType = GeometrySupportType.WKB;
|
|
626 |
public DefaultExpressionBuilder(ExpressionEvaluatorManager manager) {
|
|
627 |
this.manager = manager;
|
|
813 | 628 |
} |
814 | 629 |
|
815 | 630 |
@Override |
... | ... | |
819 | 634 |
|
820 | 635 |
@Override |
821 | 636 |
public ExpressionBuilder createExpressionBuilder() { |
822 |
return new DefaultExpressionBuilder(); |
|
637 |
return new DefaultExpressionBuilder(this.manager);
|
|
823 | 638 |
} |
824 | 639 |
|
825 | 640 |
@Override |
826 |
public GeometrySupportType geometry_support_type() { |
|
827 |
return this.geometrySupportType; |
|
828 |
} |
|
829 |
|
|
830 |
@Override |
|
831 |
public ExpressionBuilder geometry_support_type(GeometrySupportType geometrySupportType) { |
|
832 |
this.geometrySupportType = geometrySupportType; |
|
833 |
return this; |
|
834 |
} |
|
835 |
|
|
836 |
@Override |
|
837 | 641 |
public Value value() { |
838 | 642 |
return this.value; |
839 | 643 |
} |
... | ... | |
924 | 728 |
return "x'" + bytearray_hex(data) + "'"; |
925 | 729 |
} |
926 | 730 |
|
927 |
@Override |
|
928 |
public Object srs_id(IProjection projection) { |
|
929 |
if( projection==null ) { |
|
930 |
return 0; |
|
931 |
} |
|
932 |
return ProjectionUtils.getCode(projection); |
|
933 |
} |
|
934 | 731 |
|
935 | 732 |
@Override |
936 | 733 |
public Constant bytearray(byte[] data) { |
937 |
return new ConstantBase(data); |
|
734 |
return new ConstantBase(this, data);
|
|
938 | 735 |
} |
939 | 736 |
|
940 | 737 |
@Override |
941 |
public Constant srs(IProjection projection) { |
|
942 |
return constant(projection); |
|
943 |
} |
|
944 |
|
|
945 |
@Override |
|
946 | 738 |
public Variable variable(String name) { |
947 |
return new VariableBase(name); |
|
739 |
return new VariableBase(this, name);
|
|
948 | 740 |
} |
949 | 741 |
|
950 | 742 |
@Override |
951 | 743 |
public Variable column(String name) { |
952 |
return new VariableBase(name); |
|
744 |
return new VariableBase(this, name);
|
|
953 | 745 |
} |
954 | 746 |
|
955 | 747 |
@Override |
... | ... | |
972 | 764 |
|
973 | 765 |
@Override |
974 | 766 |
public Constant constant(Object value) { |
975 |
return new ConstantBase(value); |
|
767 |
return new ConstantBase(this, value);
|
|
976 | 768 |
} |
977 | 769 |
|
978 | 770 |
@Override |
... | ... | |
981 | 773 |
} |
982 | 774 |
|
983 | 775 |
@Override |
984 |
public Constant geometry(Geometry geom, IProjection projection) { |
|
985 |
geom.setProjection(projection); |
|
986 |
return new ConstantBase(geom); |
|
987 |
} |
|
988 |
|
|
989 |
@Override |
|
990 |
public Constant geometry(Geometry geom) { |
|
991 |
if( geom.getProjection()==null ) { |
|
992 |
throw new IllegalArgumentException("The geometry does not have an associated projection. Use 'geometry(Geometry, IProjection)'."); |
|
993 |
} |
|
994 |
return new ConstantBase(geom); |
|
995 |
} |
|
996 |
|
|
997 |
@Override |
|
998 |
public Constant envelope(Envelope envelope, IProjection projection) { |
|
999 |
Geometry geom = envelope.getGeometry(); |
|
1000 |
geom.setProjection(projection); |
|
1001 |
return new ConstantBase(geom); |
|
1002 |
} |
|
1003 |
|
|
1004 |
@Override |
|
1005 |
public Constant envelope(Envelope envelope) { |
|
1006 |
if( envelope.getProjection()==null ) { |
|
1007 |
throw new IllegalArgumentException("The envelope does not have an associated projection. Use 'envelope(Geometry, IProjection)'."); |
|
1008 |
} |
|
1009 |
Geometry geom = envelope.getGeometry(); |
|
1010 |
return new ConstantBase(geom); |
|
1011 |
} |
|
1012 |
|
|
1013 |
@Override |
|
1014 | 776 |
public Custom custom(Object value) { |
1015 | 777 |
return new CustomBase(value); |
1016 | 778 |
} |
... | ... | |
1088 | 850 |
Object theValue = param.value(); |
1089 | 851 |
String s; |
1090 | 852 |
switch(param.type()) { |
1091 |
case Constant:
|
|
853 |
case PARAMETER_TYPE_CONSTANT:
|
|
1092 | 854 |
if( theValue==null ) { |
1093 | 855 |
s = "NULL"; |
1094 | 856 |
} else if( theValue instanceof String ) { |
... | ... | |
1101 | 863 |
s = theValue.toString(); |
1102 | 864 |
} |
1103 | 865 |
break; |
1104 |
case Geometry: |
|
1105 |
if( param.name()==null ) { |
|
1106 |
s = bytearray_0x((byte[]) theValue); |
|
1107 |
} else { |
|
1108 |
s = "\"" + param.name() + "\""; |
|
1109 |
} |
|
1110 |
break; |
|
1111 |
case Variable: |
|
866 |
case PARAMETER_TYPE_VARIABLE: |
|
1112 | 867 |
default: |
1113 | 868 |
s = "\"" + param.name() + "\""; |
1114 | 869 |
} |
... | ... | |
1131 | 886 |
} |
1132 | 887 |
|
1133 | 888 |
@Override |
1134 |
public Function as_geometry(Value value) { |
|
1135 |
return builtin_function(FUNCTION_ST_ASBINARY, FORMAT_ST_ASBINARY, value); |
|
1136 |
} |
|
1137 |
|
|
1138 |
@Override |
|
1139 | 889 |
public ExpressionBuilder set(Value value) { |
1140 | 890 |
this.value = value; |
1141 | 891 |
return this; |
... | ... | |
1162 | 912 |
} |
1163 | 913 |
|
1164 | 914 |
@Override |
1165 |
public Function ST_Intersects(Value geom1, Value geom2) { |
|
1166 |
return builtin_function(FUNCTION_ST_INTERSECTS, FORMAT_ST_INTERSECTS, geom1, geom2); |
|
1167 |
} |
|
1168 |
|
|
1169 |
@Override |
|
1170 |
public Function ST_SRID(Value geom) { |
|
1171 |
return builtin_function(FUNCTION_ST_SRID, FORMAT_ST_SRID, geom); |
|
1172 |
} |
|
1173 |
|
|
1174 |
@Override |
|
1175 |
public Function ST_Envelope(Value geom) { |
|
1176 |
return builtin_function(FUNCTION_ST_ENVELOPE, FORMAT_ST_ENVELOPE, geom); |
|
1177 |
} |
|
1178 |
|
|
1179 |
@Override |
|
1180 |
public Function ST_Force2D(Value geom) { |
|
1181 |
return builtin_function(FUNCTION_ST_FORCE2D, FORMAT_ST_FORCE2D, geom); |
|
1182 |
} |
|
1183 |
|
|
1184 |
@Override |
|
1185 |
public Function ST_AsText(Value geom) { |
|
1186 |
return builtin_function(FUNCTION_ST_ASTEXT, FORMAT_ST_ASTEXT, geom); |
|
1187 |
} |
|
1188 |
|
|
1189 |
@Override |
|
1190 |
public Function ST_AsBinary(Value geom) { |
|
1191 |
return builtin_function(FUNCTION_ST_ASBINARY, FORMAT_ST_ASBINARY, geom); |
|
1192 |
} |
|
1193 |
|
|
1194 |
@Override |
|
1195 |
public Function ST_AsEWKB(Value geom) { |
|
1196 |
return builtin_function(FUNCTION_ST_ASEWKB, FORMAT_ST_ASEWKB, geom); |
|
1197 |
} |
|
1198 |
|
|
1199 |
@Override |
|
1200 |
public Function ST_GeomFromText(Value geom, Value crs) { |
|
1201 |
return builtin_function(FUNCTION_ST_GEOMFROMTEXT, FORMAT_ST_GEOMFROMTEXT, geom, crs); |
|
1202 |
} |
|
1203 |
|
|
1204 |
@Override |
|
1205 |
public Function ST_GeomFromWKB(Value geom, Value crs) { |
|
1206 |
return builtin_function(FUNCTION_ST_GEOMFROMWKB, FORMAT_ST_GEOMFROMWKB, geom, crs); |
|
1207 |
} |
|
1208 |
|
|
1209 |
@Override |
|
1210 |
public Function ST_GeomFromEWKB(Value geom, Value crs) { |
|
1211 |
return builtin_function(FUNCTION_ST_GEOMFROMEWKB, FORMAT_ST_GEOMFROMEWKB, geom, crs); |
|
1212 |
} |
|
1213 |
|
|
1214 |
@Override |
|
1215 |
public Function ST_Simplify(Value geom, Value tolerance) { |
|
1216 |
return builtin_function(FUNCTION_ST_SIMPLIFY, FORMAT_ST_SIMPLIFY, tolerance); |
|
1217 |
} |
|
1218 |
|
|
1219 |
@Override |
|
1220 |
public Function ST_Disjoint(Value geom1, Value geom2) { |
|
1221 |
return builtin_function(FUNCTION_ST_DISJOINT, FORMAT_ST_DISJOINT, geom1, geom2); |
|
1222 |
} |
|
1223 |
|
|
1224 |
@Override |
|
1225 |
public Function ST_Contains(Value geom1, Value geom2) { |
|
1226 |
return builtin_function(FUNCTION_ST_CONTAINS, FORMAT_ST_CONTAINS, geom1, geom2); |
|
1227 |
} |
|
1228 |
|
|
1229 |
@Override |
|
1230 |
public Function ST_Equals(Value geom1, Value geom2) { |
|
1231 |
return builtin_function(FUNCTION_ST_EQUALS, FORMAT_ST_EQUALS, geom1, geom2); |
|
1232 |
} |
|
1233 |
|
|
1234 |
@Override |
|
1235 |
public Function ST_Crosses(Value geom1, Value geom2) { |
|
1236 |
return builtin_function(FUNCTION_ST_CROSSES, FORMAT_ST_CROSSES, geom1, geom2); |
|
1237 |
} |
|
1238 |
|
|
1239 |
@Override |
|
1240 |
public Function ST_IsClosed(Value geom) { |
|
1241 |
return builtin_function(FUNCTION_ST_ISCLOSED, FORMAT_ST_ISCLOSED, geom); |
|
1242 |
} |
|
1243 |
|
|
1244 |
@Override |
|
1245 |
public Function ST_Overlaps(Value geom1, Value geom2) { |
|
1246 |
return builtin_function(FUNCTION_ST_OVERLAPS, FORMAT_ST_OVERLAPS, geom1, geom2); |
|
1247 |
} |
|
1248 |
|
|
1249 |
@Override |
|
1250 |
public Function ST_Touches(Value geom1, Value geom2) { |
|
1251 |
return builtin_function(FUNCTION_ST_TOUCHES, FORMAT_ST_TOUCHES, geom1, geom2); |
|
1252 |
} |
|
1253 |
|
|
1254 |
@Override |
|
1255 |
public Function ST_Within(Value geom1, Value geom2) { |
|
1256 |
return builtin_function("ST_Within", FORMAT_ST_WITHIN, geom1, geom2); |
|
1257 |
} |
|
1258 |
|
|
1259 |
@Override |
|
1260 |
public Function ST_Area(Value geom) { |
|
1261 |
return function("ST_Area", geom); |
|
1262 |
} |
|
1263 |
|
|
1264 |
@Override |
|
1265 |
public Function ST_Buffer(Value geom) { |
|
1266 |
return function("ST_Buffer", geom); |
|
1267 |
} |
|
1268 |
|
|
1269 |
@Override |
|
1270 |
public Function ST_Buffer(Value geom, Value dist) { |
|
1271 |
return function("ST_Buffer", geom, dist); |
|
1272 |
} |
|
1273 |
|
|
1274 |
@Override |
|
1275 |
public Function ST_Centroid(Value geom) { |
|
1276 |
return function("ST_Centroid", geom); |
|
1277 |
} |
|
1278 |
|
|
1279 |
@Override |
|
1280 |
public Function ST_CoveredBy(Value geom1, Value geom2) { |
|
1281 |
return function("ST_CoveredBy", geom1, geom2); |
|
1282 |
} |
|
1283 |
|
|
1284 |
@Override |
|
1285 |
public Function ST_Covers(Value geom1, Value geom2) { |
|
1286 |
return function("ST_Covers", geom1, geom2); |
|
1287 |
} |
|
1288 |
|
|
1289 |
@Override |
|
1290 |
public Function ST_Diference(Value geom1, Value geom2) { |
|
1291 |
return function("ST_Diference", geom1, geom2); |
|
1292 |
} |
|
1293 |
|
|
1294 |
@Override |
|
1295 |
public Function ST_Dimension(Value geom) { |
|
1296 |
return function("ST_Dimension", geom); |
|
1297 |
} |
|
1298 |
|
|
1299 |
@Override |
|
1300 |
public Function ST_Distance(Value geom1, Value geom2) { |
|
1301 |
return function("ST_Distance", geom1, geom2); |
|
1302 |
} |
|
1303 |
|
|
1304 |
@Override |
|
1305 |
public Function ST_EndPoint(Value geom) { |
|
1306 |
return function("ST_EndPoint", geom); |
|
1307 |
} |
|
1308 |
|
|
1309 |
@Override |
|
1310 |
public Function ST_Intersection(Value geom1, Value geom2) { |
|
1311 |
return function("ST_Intersection", geom1, geom2); |
|
1312 |
} |
|
1313 |
|
|
1314 |
@Override |
|
1315 |
public Function ST_IsSimple(Value geom) { |
|
1316 |
return function("ST_IsSimple", geom); |
|
1317 |
} |
|
1318 |
|
|
1319 |
@Override |
|
1320 |
public Function ST_IsValid(Value geom) { |
|
1321 |
return function("ST_IsValid", geom); |
|
1322 |
} |
|
1323 |
|
|
1324 |
@Override |
|
1325 |
public Function ST_NumGeometries(Value geom) { |
|
1326 |
return function("ST_NumGeometries", geom); |
|
1327 |
} |
|
1328 |
|
|
1329 |
@Override |
|
1330 |
public Function ST_NumPoints(Value geom) { |
|
1331 |
return function("ST_NumPoints", geom); |
|
1332 |
} |
|
1333 |
|
|
1334 |
@Override |
|
1335 |
public Function ST_Perimeter(Value geom) { |
|
1336 |
return function("ST_Perimeter", geom); |
|
1337 |
} |
|
1338 |
|
|
1339 |
@Override |
|
1340 |
public Function ST_PointN(Value geom, Value n) { |
|
1341 |
return function("ST_PointN", geom, n); |
|
1342 |
} |
|
1343 |
|
|
1344 |
@Override |
|
1345 |
public Function ST_StartPoint(Value geom) { |
|
1346 |
return function("ST_StartPoint", geom); |
|
1347 |
} |
|
1348 |
|
|
1349 |
@Override |
|
1350 |
public Function ST_Union(Value geom1, Value geom2) { |
|
1351 |
return function("ST_Union", geom1, geom2); |
|
1352 |
} |
|
1353 |
|
|
1354 |
@Override |
|
1355 |
public Function ST_X(Value geom) { |
|
1356 |
return function("ST_X", geom); |
|
1357 |
} |
|
1358 |
|
|
1359 |
@Override |
|
1360 |
public Function ST_Y(Value geom) { |
|
1361 |
return function("ST_Y", geom); |
|
1362 |
} |
|
1363 |
|
|
1364 |
@Override |
|
1365 |
public Function ST_Z(Value geom) { |
|
1366 |
return function("ST_Z", geom); |
|
1367 |
} |
|
1368 |
|
|
1369 |
@Override |
|
1370 | 915 |
public Function is_null(Value value) { |
1371 | 916 |
return builtin_function("IS NULL", FORMAT_ISNULL, value); |
1372 | 917 |
} |
... | ... | |
1652 | 1197 |
} |
1653 | 1198 |
|
1654 | 1199 |
@Override |
1655 |
public Function pi(Value num) {
|
|
1656 |
return function(FUNCTION_PI, num);
|
|
1200 |
public Function pi() { |
|
1201 |
return function(FUNCTION_PI); |
|
1657 | 1202 |
} |
1658 | 1203 |
|
1659 | 1204 |
@Override |
1205 |
public Function abs(Value num) { |
|
1206 |
return function(FUNCTION_ABS, num); |
|
1207 |
} |
|
1208 |
|
|
1209 |
@Override |
|
1660 | 1210 |
public Function power(Value num) { |
1661 | 1211 |
return function(FUNCTION_POWER, num); |
1662 | 1212 |
} |
... | ... | |
1716 | 1266 |
} |
1717 | 1267 |
|
1718 | 1268 |
@Override |
1719 |
public Function ST_ExtentAggregate(Value geom) { |
|
1720 |
return function(FUNCTION_ST_EXTENTAGGREGATE, geom); |
|
1721 |
} |
|
1722 |
|
|
1723 |
@Override |
|
1724 |
public Function ST_UnionAggregate(Value geom) { |
|
1725 |
return function(FUNCTION_ST_UNIONAGGREGATE, geom); |
|
1726 |
} |
|
1727 |
|
|
1728 |
@Override |
|
1729 | 1269 |
public Function cast(Value object, Value typeName) { |
1730 | 1270 |
return function(FUNCTION_CAST, object, typeName); |
1731 | 1271 |
} |
... | ... | |
1761 | 1301 |
} |
1762 | 1302 |
|
1763 | 1303 |
@Override |
1764 |
public Function ST_Point(Value x, Value y) { |
|
1765 |
return function(FUNCTION_ST_POINT, x, y); |
|
1766 |
} |
|
1767 |
|
|
1768 |
@Override |
|
1769 |
public Function ST_MakePoint(Value x, Value y) { |
|
1770 |
return function(FUNCTION_ST_MAKEPOINT, x, y); |
|
1771 |
} |
|
1772 |
|
|
1773 |
@Override |
|
1774 |
public Function ST_MakePoint(Value x, Value y, Value z) { |
|
1775 |
return function(FUNCTION_ST_MAKEPOINT, x, y, z); |
|
1776 |
} |
|
1777 |
|
|
1778 |
@Override |
|
1779 |
public Function ST_MakePoint(Value x, Value y, Value z, Value m) { |
|
1780 |
return function(FUNCTION_ST_MAKEPOINT, x, y, z, m); |
|
1781 |
} |
|
1782 |
|
|
1783 |
@Override |
|
1784 |
public Function ST_SetSRID(Value geom, Value srid) { |
|
1785 |
return function(FUNCTION_ST_POINT, geom, srid); |
|
1786 |
} |
|
1787 |
|
|
1788 |
@Override |
|
1789 | 1304 |
public Function list() { |
1790 | 1305 |
return function(FUNCTION_LIST); |
1791 | 1306 |
} |
... | ... | |
1804 | 1319 |
return fn; |
1805 | 1320 |
} |
1806 | 1321 |
|
1322 |
@Override |
|
1323 |
public String repr(Object value) { |
|
1324 |
return this.manager.getReprMethod(value).repr(value); |
|
1325 |
} |
|
1807 | 1326 |
|
1808 | 1327 |
} |
Also available in: Unified diff