svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.sqlite / org.gvsig.sqlite.provider / src / main / java / org / gvsig / sqlite / dal / expressionbuilderformatter / ST_CoveredBy.java @ 47606
History | View | Annotate | Download (1.96 KB)
1 |
package org.gvsig.sqlite.dal.expressionbuilderformatter; |
---|---|
2 |
|
3 |
import java.text.MessageFormat; |
4 |
import java.util.List; |
5 |
import org.apache.commons.lang3.StringUtils; |
6 |
import org.gvsig.expressionevaluator.ExpressionBuilder; |
7 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Function; |
8 |
import org.gvsig.expressionevaluator.ExpressionBuilder.Value; |
9 |
import org.gvsig.expressionevaluator.Formatter; |
10 |
import static org.gvsig.expressionevaluator.GeometryExpressionBuilderHelper.FUNCTION_ST_COVEREDBY; |
11 |
import org.gvsig.fmap.dal.SQLBuilder; |
12 |
import static org.gvsig.sqlite.dal.expressionbuilderformatter.ST_Intersects.getBBoxIntersectsFilter; |
13 |
|
14 |
/**
|
15 |
*
|
16 |
* @author jjdelcerro
|
17 |
*/
|
18 |
public class ST_CoveredBy implements Formatter<Value> { |
19 |
|
20 |
private final SQLBuilder sqlbuilder; |
21 |
private final Formatter<Value> formatter; |
22 |
|
23 |
public ST_CoveredBy(SQLBuilder sqlbuilder, Formatter<Value> formatter) { |
24 |
this.sqlbuilder = sqlbuilder;
|
25 |
this.formatter = formatter;
|
26 |
} |
27 |
@Override
|
28 |
public boolean canApply(ExpressionBuilder.Value value) { |
29 |
if (value instanceof ExpressionBuilder.Function) { |
30 |
return StringUtils.equalsIgnoreCase(FUNCTION_ST_COVEREDBY, ((Function) value).name());
|
31 |
} |
32 |
return false; |
33 |
} |
34 |
|
35 |
@Override
|
36 |
public String format(Value function) { |
37 |
List<Value> parameters = ((Function) function).parameters();
|
38 |
Value p1 = parameters.get(0);
|
39 |
Value p2 = parameters.get(1);
|
40 |
String p1s = p1.toString(formatter);
|
41 |
String p2s = p2.toString(formatter);
|
42 |
|
43 |
String filter = getBBoxIntersectsFilter(formatter, p1, p2);
|
44 |
if (filter == null ) { |
45 |
filter = getBBoxIntersectsFilter(formatter, p2, p1); |
46 |
} |
47 |
String r;
|
48 |
if( filter == null ) { |
49 |
r = MessageFormat.format("ST_Covers(({1}),({0}))", p1s, p2s); |
50 |
} else {
|
51 |
r = MessageFormat.format("( ({2}) AND ST_Covers(({1}),({0}) ))", p1s, p2s, filter); |
52 |
} |
53 |
return r;
|
54 |
|
55 |
} |
56 |
|
57 |
} |