Revision 25686 branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/operation/relationship/Intersects.java
Intersects.java | ||
---|---|---|
37 | 37 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
38 | 38 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
39 | 39 |
import org.gvsig.fmap.geom.operation.tojts.ToJTS; |
40 |
import org.gvsig.fmap.geom.primitive.NullGeometry; |
|
40 | 41 |
|
41 | 42 |
/** |
42 | 43 |
* @author jmvivo |
43 | 44 |
* |
44 | 45 |
*/ |
45 | 46 |
public class Intersects extends GeometryOperation { |
46 |
public static final int CODE = GeometryManager.getInstance()
|
|
47 |
.registerGeometryOperation("intersects", new Intersects());
|
|
47 |
public static final int CODE = GeometryManager.getInstance()
|
|
48 |
.registerGeometryOperation("intersects", new Intersects());
|
|
48 | 49 |
|
49 |
/*
|
|
50 |
* (non-Javadoc)
|
|
51 |
*
|
|
52 |
* @see org.gvsig.fmap.geom.operation.GeometryOperation#getOperationIndex()
|
|
53 |
*/
|
|
54 |
public int getOperationIndex() {
|
|
55 |
return CODE;
|
|
56 |
}
|
|
50 |
/*
|
|
51 |
* (non-Javadoc)
|
|
52 |
*
|
|
53 |
* @see org.gvsig.fmap.geom.operation.GeometryOperation#getOperationIndex()
|
|
54 |
*/
|
|
55 |
public int getOperationIndex() {
|
|
56 |
return CODE;
|
|
57 |
}
|
|
57 | 58 |
|
58 |
/*
|
|
59 |
* (non-Javadoc)
|
|
60 |
*
|
|
61 |
* @see org.gvsig.fmap.geom.operation.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry,
|
|
62 |
* org.gvsig.fmap.geom.operation.GeometryOperationContext)
|
|
63 |
*/
|
|
64 |
public Object invoke(Geometry geom, GeometryOperationContext ctx)
|
|
65 |
throws GeometryOperationException {
|
|
66 |
DefaultRelationshipGeometryOperationContext myCtx = null;
|
|
67 |
myCtx = (DefaultRelationshipGeometryOperationContext) ctx;
|
|
59 |
/*
|
|
60 |
* (non-Javadoc)
|
|
61 |
*
|
|
62 |
* @see org.gvsig.fmap.geom.operation.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry,
|
|
63 |
* org.gvsig.fmap.geom.operation.GeometryOperationContext)
|
|
64 |
*/
|
|
65 |
public Object invoke(Geometry geom, GeometryOperationContext ctx)
|
|
66 |
throws GeometryOperationException {
|
|
67 |
DefaultRelationshipGeometryOperationContext myCtx = null;
|
|
68 |
myCtx = (DefaultRelationshipGeometryOperationContext) ctx;
|
|
68 | 69 |
|
69 |
Geometry otherGeom = myCtx.getGeom();
|
|
70 |
if (!otherGeom.getEnvelope().intersects(myCtx.getGeom().getEnvelope())){
|
|
71 |
return new Boolean(false);
|
|
72 |
}
|
|
73 |
// TODO optimizar esto para los rectangulos (envelope)
|
|
74 |
com.vividsolutions.jts.geom.Geometry jtsGeom = null;
|
|
75 |
com.vividsolutions.jts.geom.Geometry otherJtsGeom = null;
|
|
76 |
try {
|
|
77 |
jtsGeom = (com.vividsolutions.jts.geom.Geometry) geom
|
|
78 |
.invokeOperation(ToJTS.CODE, null);
|
|
79 |
} catch (GeometryOperationNotSupportedException e) {
|
|
80 |
throw new GeometryOperationException(geom.getType(), CODE, e);
|
|
81 |
}
|
|
82 |
try {
|
|
70 |
Geometry otherGeom = myCtx.getGeom();
|
|
71 |
if (otherGeom instanceof NullGeometry || geom instanceof NullGeometry || !otherGeom.getEnvelope().intersects(geom.getEnvelope())){
|
|
72 |
return new Boolean(false);
|
|
73 |
}
|
|
74 |
// TODO optimizar esto para los rectangulos (envelope)
|
|
75 |
com.vividsolutions.jts.geom.Geometry jtsGeom = null;
|
|
76 |
com.vividsolutions.jts.geom.Geometry otherJtsGeom = null;
|
|
77 |
try {
|
|
78 |
jtsGeom = (com.vividsolutions.jts.geom.Geometry) geom
|
|
79 |
.invokeOperation(ToJTS.CODE, null);
|
|
80 |
} catch (GeometryOperationNotSupportedException e) {
|
|
81 |
throw new GeometryOperationException(geom.getType(), CODE, e);
|
|
82 |
}
|
|
83 |
try {
|
|
83 | 84 |
|
84 |
otherJtsGeom = (com.vividsolutions.jts.geom.Geometry) otherGeom
|
|
85 |
.invokeOperation(ToJTS.CODE, null);
|
|
86 |
} catch (GeometryOperationNotSupportedException e) {
|
|
87 |
throw new GeometryOperationException(otherGeom.getType(), CODE, e);
|
|
88 |
}
|
|
89 |
if (jtsGeom!=null && otherJtsGeom!=null)
|
|
90 |
return new Boolean(jtsGeom.intersects(otherJtsGeom));
|
|
91 |
return new Boolean(false);
|
|
92 |
}
|
|
85 |
otherJtsGeom = (com.vividsolutions.jts.geom.Geometry) otherGeom
|
|
86 |
.invokeOperation(ToJTS.CODE, null);
|
|
87 |
} catch (GeometryOperationNotSupportedException e) {
|
|
88 |
throw new GeometryOperationException(otherGeom.getType(), CODE, e);
|
|
89 |
}
|
|
90 |
if (jtsGeom!=null && otherJtsGeom!=null)
|
|
91 |
return new Boolean(jtsGeom.intersects(otherJtsGeom));
|
|
92 |
return new Boolean(false);
|
|
93 |
}
|
|
93 | 94 |
|
94 | 95 |
} |
Also available in: Unified diff