root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / impl / AbstractPrimitive.java @ 38770
History | View | Annotate | Download (20.4 KB)
1 | 27029 | jpiera | package org.gvsig.fmap.geom.primitive.impl; |
---|---|---|---|
2 | 20761 | jmvivo | |
3 | import java.awt.Shape; |
||
4 | import java.awt.geom.AffineTransform; |
||
5 | 28624 | jmvivo | import java.awt.geom.PathIterator; |
6 | 20761 | jmvivo | import java.awt.geom.Point2D; |
7 | import java.io.Serializable; |
||
8 | |||
9 | 21870 | vcaballero | import org.cresques.cts.ICoordTrans; |
10 | import org.cresques.cts.IProjection; |
||
11 | 34140 | jpiera | import org.slf4j.Logger; |
12 | import org.slf4j.LoggerFactory; |
||
13 | |||
14 | 20761 | jmvivo | import org.gvsig.fmap.geom.Geometry; |
15 | 26328 | jpiera | import org.gvsig.fmap.geom.GeometryLocator; |
16 | 27230 | jpiera | import org.gvsig.fmap.geom.GeometryManager; |
17 | 32924 | jjdelcerro | import org.gvsig.fmap.geom.exception.CreateGeometryException; |
18 | 20761 | jmvivo | import org.gvsig.fmap.geom.handler.Handler; |
19 | 29972 | jldominguez | import org.gvsig.fmap.geom.operation.GeometryOperation; |
20 | 20761 | jmvivo | import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
21 | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
||
22 | 21000 | jiyarza | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
23 | 29972 | jldominguez | import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext; |
24 | import org.gvsig.fmap.geom.primitive.Envelope; |
||
25 | 27029 | jpiera | import org.gvsig.fmap.geom.primitive.FShape; |
26 | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
||
27 | 33262 | jpiera | import org.gvsig.fmap.geom.primitive.Point; |
28 | 27029 | jpiera | import org.gvsig.fmap.geom.primitive.Primitive; |
29 | 20761 | jmvivo | import org.gvsig.fmap.geom.type.GeometryType; |
30 | 32924 | jjdelcerro | import org.gvsig.fmap.geom.util.Converter; |
31 | 20761 | jmvivo | |
32 | |||
33 | /**
|
||
34 | 21308 | jiyarza | * @author Jorge Piera Llodr? (jorge.piera@iver.es)
|
35 | 20761 | jmvivo | */
|
36 | 35346 | jpiera | public abstract class AbstractPrimitive implements Primitive, FShape, Shape, Serializable { |
37 | 29972 | jldominguez | |
38 | 38595 | cordinyana | private static final Logger logger = LoggerFactory.getLogger(AbstractPrimitive.class); |
39 | 29972 | jldominguez | |
40 | 27049 | jpiera | private static final long serialVersionUID = -4334977368955260872L; |
41 | 20761 | jmvivo | protected String id = null; |
42 | protected IProjection projection = null; |
||
43 | 29097 | jpiera | protected GeometryType geometryType = null; |
44 | 38595 | cordinyana | protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
45 | 21425 | vcaballero | |
46 | 26788 | jpiera | /**
|
47 | 29097 | jpiera | * The constructor with the GeometryType like and argument
|
48 | * is used by the {@link GeometryType}{@link #create()}
|
||
49 | * to create the geometry
|
||
50 | * @param type
|
||
51 | * The geometry type
|
||
52 | 26788 | jpiera | */
|
53 | 29097 | jpiera | public AbstractPrimitive(GeometryType geometryType) {
|
54 | this(geometryType, null, null); |
||
55 | 26788 | jpiera | } |
56 | 29097 | jpiera | |
57 | AbstractPrimitive(int type, int subtype) { |
||
58 | try {
|
||
59 | 29166 | jpiera | geometryType = geomManager.getGeometryType(type, subtype); |
60 | 29097 | jpiera | } catch (Exception e) { |
61 | 29166 | jpiera | //TODO Not registered geometry
|
62 | geometryType = null;
|
||
63 | 29097 | jpiera | } |
64 | } |
||
65 | |||
66 | public AbstractPrimitive(GeometryType geometryType, String id, IProjection projection) { |
||
67 | 20761 | jmvivo | super();
|
68 | this.id = id;
|
||
69 | this.projection = projection;
|
||
70 | 29097 | jpiera | this.geometryType = geometryType;
|
71 | 21425 | vcaballero | } |
72 | 20761 | jmvivo | |
73 | 29097 | jpiera | public AbstractPrimitive(GeometryType geometryType, IProjection projection) {
|
74 | this(geometryType, null, projection); |
||
75 | 20761 | jmvivo | } |
76 | 21425 | vcaballero | |
77 | 29097 | jpiera | /* (non-Javadoc)
|
78 | * @see org.gvsig.fmap.geom.Geometry#getGeometryType()
|
||
79 | */
|
||
80 | public GeometryType getGeometryType() {
|
||
81 | return geometryType;
|
||
82 | } |
||
83 | |||
84 | /* (non-Javadoc)
|
||
85 | * @see org.gvsig.fmap.geom.Geometry#getType()
|
||
86 | */
|
||
87 | public int getType() { |
||
88 | return geometryType.getType();
|
||
89 | } |
||
90 | |||
91 | 22724 | vcaballero | /**
|
92 | 20761 | jmvivo | * (non-Javadoc)
|
93 | * @see com.iver.cit.gvsig.fmap.core.Geometry#getInternalShape()
|
||
94 | 22724 | vcaballero | * @deprecated this Geometry is a Shape.
|
95 | 20761 | jmvivo | */
|
96 | public Shape getInternalShape() { |
||
97 | return this; |
||
98 | 21425 | vcaballero | } |
99 | 20761 | jmvivo | |
100 | /* (non-Javadoc)
|
||
101 | * @see org.gvsig.geometries.iso.AbstractGeometry#getId()
|
||
102 | */
|
||
103 | public String getId() { |
||
104 | return id;
|
||
105 | } |
||
106 | |||
107 | /* (non-Javadoc)
|
||
108 | * @see org.gvsig.geometries.iso.AbstractGeometry#getSRS()
|
||
109 | */
|
||
110 | public IProjection getSRS() {
|
||
111 | return projection;
|
||
112 | 21425 | vcaballero | } |
113 | 20761 | jmvivo | |
114 | /* (non-Javadoc)
|
||
115 | * @see org.gvsig.geometries.iso.AbstractGeometry#transform(org.cresques.cts.IProjection)
|
||
116 | */
|
||
117 | public AbstractPrimitive transform(IProjection newProjection) {
|
||
118 | Geometry newGeom = cloneGeometry(); |
||
119 | ICoordTrans coordTrans = projection.getCT(newProjection); |
||
120 | newGeom.reProject(coordTrans); |
||
121 | return (AbstractPrimitive)newGeom;
|
||
122 | } |
||
123 | 21425 | vcaballero | |
124 | |||
125 | 20761 | jmvivo | /*
|
126 | * TODO adaptar metodo procedente de UtilFunctions
|
||
127 | */
|
||
128 | public static void rotateGeom(Geometry geometry, double radAngle, double basex, double basey) { |
||
129 | AffineTransform at = new AffineTransform(); |
||
130 | at.rotate(radAngle,basex,basey); |
||
131 | geometry.transform(at); |
||
132 | |||
133 | } |
||
134 | |||
135 | /*
|
||
136 | * TODO adaptar metodo procedente de UtilFunctions
|
||
137 | 21425 | vcaballero | */
|
138 | 20761 | jmvivo | public static void moveGeom(Geometry geometry, double dx, double dy) { |
139 | AffineTransform at = new AffineTransform(); |
||
140 | at.translate(dx, dy); |
||
141 | geometry.transform(at); |
||
142 | } |
||
143 | |||
144 | /*
|
||
145 | * TODO adaptar metodo procedente de UtilFunctions
|
||
146 | 21425 | vcaballero | */
|
147 | 20761 | jmvivo | public static void scaleGeom(Geometry geometry, Point2D basePoint, double sx, double sy) { |
148 | AffineTransform at = new AffineTransform(); |
||
149 | at.setToTranslation(basePoint.getX(),basePoint.getY()); |
||
150 | at.scale(sx,sy); |
||
151 | at.translate(-basePoint.getX(),-basePoint.getY()); |
||
152 | geometry.transform(at); |
||
153 | } |
||
154 | |||
155 | 27049 | jpiera | /*
|
156 | * (non-Javadoc)
|
||
157 | * @see org.gvsig.fmap.geom.Geometry#fastIntersects(double, double, double, double)
|
||
158 | */
|
||
159 | 20761 | jmvivo | public boolean fastIntersects(double x, double y, double w, double h) { |
160 | 29972 | jldominguez | |
161 | boolean resp = true; |
||
162 | |||
163 | try {
|
||
164 | resp = intersectsRectangle(this, x, y, w, h);
|
||
165 | } catch (GeometryOperationException e) {
|
||
166 | logger.error("While doing fastintersects: " + e.getMessage(), e);
|
||
167 | } |
||
168 | |||
169 | return resp;
|
||
170 | 20761 | jmvivo | } |
171 | 28624 | jmvivo | |
172 | 27049 | jpiera | /*
|
173 | * (non-Javadoc)
|
||
174 | * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
||
175 | */
|
||
176 | 20761 | jmvivo | public Geometry cloneGeometry() {
|
177 | return (Geometry)cloneFShape();
|
||
178 | } |
||
179 | |||
180 | 27049 | jpiera | /*
|
181 | * (non-Javadoc)
|
||
182 | * @see org.gvsig.fmap.geom.Geometry#getHandlers(int)
|
||
183 | */
|
||
184 | 20761 | jmvivo | public Handler[] getHandlers(int type) { |
185 | if (type==STRETCHINGHANDLER){
|
||
186 | return getStretchingHandlers();
|
||
187 | }else if (type==SELECTHANDLER){ |
||
188 | return getSelectHandlers();
|
||
189 | } |
||
190 | return null; |
||
191 | } |
||
192 | |||
193 | 27049 | jpiera | /*
|
194 | * (non-Javadoc)
|
||
195 | * @see org.gvsig.fmap.geom.Geometry#isSimple()
|
||
196 | */
|
||
197 | 20761 | jmvivo | public boolean isSimple() { |
198 | return true; |
||
199 | } |
||
200 | |||
201 | 27049 | jpiera | /*
|
202 | * (non-Javadoc)
|
||
203 | * @see org.gvsig.fmap.geom.Geometry#invokeOperation(int, org.gvsig.fmap.geom.operation.GeometryOperationContext)
|
||
204 | 20761 | jmvivo | */
|
205 | 21000 | jiyarza | public Object invokeOperation(int index, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException { |
206 | 27230 | jpiera | return geomManager.invokeOperation(index, this, ctx); |
207 | 20761 | jmvivo | } |
208 | 28624 | jmvivo | |
209 | 27230 | jpiera | /*
|
210 | * (non-Javadoc)
|
||
211 | * @see org.gvsig.fmap.geom.Geometry#invokeOperation(java.lang.String, org.gvsig.fmap.geom.operation.GeometryOperationContext)
|
||
212 | */
|
||
213 | public Object invokeOperation(String oppName, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
214 | return geomManager.invokeOperation(oppName, this, ctx); |
||
215 | } |
||
216 | 20761 | jmvivo | |
217 | 27049 | jpiera | /*
|
218 | * (non-Javadoc)
|
||
219 | * @see java.lang.Comparable#compareTo(T)
|
||
220 | 20761 | jmvivo | */
|
221 | 22238 | vcaballero | public int compareTo(Object arg0) { |
222 | // TODO Auto-generated method stub
|
||
223 | return -1; |
||
224 | } |
||
225 | |||
226 | 27049 | jpiera | /*
|
227 | * (non-Javadoc)
|
||
228 | * @see java.lang.Object#toString()
|
||
229 | */
|
||
230 | 22724 | vcaballero | public String toString() { |
231 | String name=getGeometryType().getName();
|
||
232 | return name.substring(name.lastIndexOf(".")+1); |
||
233 | } |
||
234 | |||
235 | 27049 | jpiera | /*
|
236 | * (non-Javadoc)
|
||
237 | * @see java.lang.Object#equals(java.lang.Object)
|
||
238 | */
|
||
239 | 26038 | jmvivo | public boolean equals(Object obj) { |
240 | if (obj == null) { |
||
241 | return false; |
||
242 | } |
||
243 | if (this.getClass() != obj.getClass()) { |
||
244 | return false; |
||
245 | } |
||
246 | 26289 | jmvivo | |
247 | 26038 | jmvivo | AbstractPrimitive other = (AbstractPrimitive) obj; |
248 | 26289 | jmvivo | if (this.getGeometryType().getType() != other.getGeometryType() |
249 | .getType()) { |
||
250 | return false; |
||
251 | |||
252 | } |
||
253 | 28624 | jmvivo | if (this.getGeometryType().getSubType() != other.getGeometryType() |
254 | .getSubType()) { |
||
255 | return false; |
||
256 | 26289 | jmvivo | |
257 | 28624 | jmvivo | } |
258 | 26038 | jmvivo | if (this.projection != other.projection) { |
259 | if (this.projection == null) { |
||
260 | return false; |
||
261 | } |
||
262 | if (this.projection.getAbrev() != other.projection.getAbrev()) { //FIXME this must be false |
||
263 | return false; |
||
264 | } |
||
265 | } |
||
266 | if (!this.getBounds().equals(other.getBounds())) { |
||
267 | return false; |
||
268 | } |
||
269 | 26289 | jmvivo | |
270 | |||
271 | 26038 | jmvivo | GeneralPathX myPath = this.getGeneralPath();
|
272 | GeneralPathX otherPath = other.getGeneralPath(); |
||
273 | 26289 | jmvivo | if (myPath == null) { |
274 | if (otherPath != null) { |
||
275 | return false; |
||
276 | } else {
|
||
277 | // TODO checkThis
|
||
278 | return true; |
||
279 | } |
||
280 | |||
281 | } |
||
282 | 28624 | jmvivo | if (myPath.getNumTypes() != otherPath.getNumTypes()) {
|
283 | 26038 | jmvivo | return false; |
284 | } |
||
285 | 28624 | jmvivo | if (Math.abs(myPath.getNumCoords() - otherPath.getNumCoords()) > this |
286 | .getDimension()) { |
||
287 | 26038 | jmvivo | return false; |
288 | } |
||
289 | 28624 | jmvivo | PathIterator myIter = myPath.getPathIterator(null); |
290 | PathIterator otherIter = otherPath.getPathIterator(null); |
||
291 | int myType,otherType;
|
||
292 | // FIXME when 3D, 2DM and 3DM
|
||
293 | double[] myData = new double[6]; |
||
294 | double[] otherData = new double[6]; |
||
295 | 35474 | jpiera | double[] myFirst = new double[] { myPath.getPointAt(0).getX(),myPath.getPointAt(0).getY()}; |
296 | double[] otherFirst = new double[] { otherPath.getPointAt(0).getX(),otherPath.getPointAt(0).getY()}; |
||
297 | 28624 | jmvivo | |
298 | while (!myIter.isDone()) {
|
||
299 | if (otherIter.isDone()) {
|
||
300 | 26038 | jmvivo | return false; |
301 | } |
||
302 | 28624 | jmvivo | for (int i = 0; i < myData.length; i++) { |
303 | myData[i] = 0.0;
|
||
304 | otherData[i] = 0.0;
|
||
305 | } |
||
306 | |||
307 | myType = myIter.currentSegment(myData); |
||
308 | otherType = otherIter.currentSegment(otherData); |
||
309 | |||
310 | switch (myType) {
|
||
311 | case PathIterator.SEG_LINETO: |
||
312 | if (otherType != myType) {
|
||
313 | if (otherType == PathIterator.SEG_CLOSE){ |
||
314 | if (!comparePathIteratorData(otherFirst, myData)) {
|
||
315 | return false; |
||
316 | } |
||
317 | } else {
|
||
318 | return false; |
||
319 | } |
||
320 | } else {
|
||
321 | if (!comparePathIteratorData(myData, otherData)) {
|
||
322 | return false; |
||
323 | } |
||
324 | } |
||
325 | break;
|
||
326 | |||
327 | |||
328 | case PathIterator.SEG_CLOSE: |
||
329 | if (otherType != myType) {
|
||
330 | if (otherType == PathIterator.SEG_LINETO) { |
||
331 | if (!comparePathIteratorData(myFirst, otherData)) {
|
||
332 | return false; |
||
333 | } |
||
334 | } else {
|
||
335 | return false; |
||
336 | } |
||
337 | } else {
|
||
338 | if (!comparePathIteratorData(myData, otherData)) {
|
||
339 | return false; |
||
340 | } |
||
341 | } |
||
342 | break;
|
||
343 | |||
344 | |||
345 | |||
346 | case PathIterator.SEG_MOVETO: |
||
347 | case PathIterator.SEG_QUADTO: |
||
348 | case PathIterator.SEG_CUBICTO: |
||
349 | if (otherType != myType) {
|
||
350 | return false; |
||
351 | } |
||
352 | if (!comparePathIteratorData(myData, otherData)) {
|
||
353 | return false; |
||
354 | } |
||
355 | break;
|
||
356 | |||
357 | } // end switch
|
||
358 | |||
359 | |||
360 | myIter.next(); |
||
361 | otherIter.next(); |
||
362 | 26038 | jmvivo | } |
363 | 28624 | jmvivo | if (!otherIter.isDone()) {
|
364 | return false; |
||
365 | } |
||
366 | 26038 | jmvivo | return true; |
367 | } |
||
368 | 28624 | jmvivo | |
369 | private boolean comparePathIteratorData(double[] org, double[] other) { |
||
370 | for (int i = 0; i < org.length; i++) { |
||
371 | if (Math.abs(org[i] - other[i]) > 0.0000001) { |
||
372 | return false; |
||
373 | } |
||
374 | } |
||
375 | return true; |
||
376 | } |
||
377 | 28996 | jpiera | |
378 | /* (non-Javadoc)
|
||
379 | * @see org.gvsig.fmap.geom.primitive.FShape#getShapeType()
|
||
380 | */
|
||
381 | public int getShapeType() { |
||
382 | return getType();
|
||
383 | } |
||
384 | |||
385 | |||
386 | 29972 | jldominguez | |
387 | |||
388 | |||
389 | |||
390 | |||
391 | |||
392 | /**
|
||
393 | * Utility method
|
||
394 | * @param geometry
|
||
395 | * @param x
|
||
396 | * @param y
|
||
397 | * @return
|
||
398 | * @throws GeometryOperationException
|
||
399 | */
|
||
400 | protected boolean containsPoint(Geometry geom, double x, double y) throws GeometryOperationException { |
||
401 | |||
402 | // exclude disjoint
|
||
403 | Envelope env = geom.getEnvelope(); |
||
404 | if (x > env.getMaximum(0)) return false; |
||
405 | if (y > env.getMaximum(1)) return false; |
||
406 | if (x < env.getMinimum(0)) return false; |
||
407 | if (y < env.getMinimum(1)) return false; |
||
408 | |||
409 | // boxes overlap, need long version
|
||
410 | |||
411 | Geometry geompoint = null;
|
||
412 | try {
|
||
413 | geompoint = GeometryLocator.getGeometryManager().createPoint(x, y, SUBTYPES.GEOM2D); |
||
414 | } catch (Exception e1) { |
||
415 | throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e1); |
||
416 | } |
||
417 | |||
418 | DefaultRelationshipGeometryOperationContext drgoc = |
||
419 | new DefaultRelationshipGeometryOperationContext(geompoint);
|
||
420 | |||
421 | Object resp = null; |
||
422 | boolean respboolean = true; |
||
423 | try {
|
||
424 | resp = geom.invokeOperation(GeometryOperation.OPERATION_CONTAINS_CODE, drgoc); |
||
425 | respboolean = ((Boolean) resp).booleanValue();
|
||
426 | } catch (Exception e) { |
||
427 | throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e); |
||
428 | } |
||
429 | |||
430 | return respboolean;
|
||
431 | } |
||
432 | |||
433 | /**
|
||
434 | *
|
||
435 | * @param geometry
|
||
436 | * @param x
|
||
437 | * @param y
|
||
438 | * @param w
|
||
439 | * @param h
|
||
440 | * @return
|
||
441 | */
|
||
442 | protected boolean containsRectangle(Geometry geom, double x, double y, |
||
443 | double w, double h) throws GeometryOperationException { |
||
444 | |||
445 | |||
446 | // exclude disjoint boxes
|
||
447 | Envelope env = geom.getEnvelope(); |
||
448 | if (x > env.getMaximum(0)) return false; |
||
449 | if ((x+w) < env.getMinimum(0)) return false; |
||
450 | if (y > env.getMaximum(1)) return false; |
||
451 | if ((y+h) < env.getMinimum(1)) return false; |
||
452 | |||
453 | if (w == 0 && h == 0) { |
||
454 | return containsPoint(geom, x, y);
|
||
455 | } |
||
456 | |||
457 | // boxes overlap, need long version
|
||
458 | Geometry rectgeom = null;
|
||
459 | GeneralPathX gpx = new GeneralPathX();
|
||
460 | gpx.moveTo(x, y); |
||
461 | gpx.lineTo(x+w, y); |
||
462 | gpx.lineTo(x+w, y+h); |
||
463 | gpx.lineTo(x, y+h); |
||
464 | gpx.lineTo(x, y); |
||
465 | |||
466 | try {
|
||
467 | rectgeom = GeometryLocator.getGeometryManager().createSurface(gpx, SUBTYPES.GEOM2D); |
||
468 | } catch (Exception e1) { |
||
469 | throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e1); |
||
470 | } |
||
471 | |||
472 | DefaultRelationshipGeometryOperationContext drgoc = |
||
473 | new DefaultRelationshipGeometryOperationContext(rectgeom);
|
||
474 | |||
475 | Object resp = null; |
||
476 | boolean respboolean = true; |
||
477 | try {
|
||
478 | resp = geom.invokeOperation(GeometryOperation.OPERATION_CONTAINS_CODE, drgoc); |
||
479 | respboolean = ((Boolean) resp).booleanValue();
|
||
480 | } catch (Exception e) { |
||
481 | throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_CONTAINS_CODE, e); |
||
482 | } |
||
483 | |||
484 | return respboolean;
|
||
485 | } |
||
486 | |||
487 | |||
488 | /**
|
||
489 | *
|
||
490 | * @param geom
|
||
491 | * @param x
|
||
492 | * @param y
|
||
493 | * @param w
|
||
494 | * @param h
|
||
495 | * @return
|
||
496 | */
|
||
497 | protected boolean intersectsRectangle(Geometry geom, double x, double y, |
||
498 | double w, double h) throws GeometryOperationException { |
||
499 | |||
500 | // exclude disjoint boxes
|
||
501 | Envelope env = geom.getEnvelope(); |
||
502 | if (x > env.getMaximum(0)) return false; |
||
503 | if ((x+w) < env.getMinimum(0)) return false; |
||
504 | if (y > env.getMaximum(1)) return false; |
||
505 | if ((y+h) < env.getMinimum(1)) return false; |
||
506 | |||
507 | // boxes overlap, need long version
|
||
508 | Geometry rectgeom = null;
|
||
509 | GeneralPathX gpx = new GeneralPathX();
|
||
510 | gpx.moveTo(x, y); |
||
511 | gpx.lineTo(x+w, y); |
||
512 | gpx.lineTo(x+w, y+h); |
||
513 | gpx.lineTo(x, y+h); |
||
514 | gpx.lineTo(x, y); |
||
515 | |||
516 | try {
|
||
517 | rectgeom = GeometryLocator.getGeometryManager().createSurface(gpx, SUBTYPES.GEOM2D); |
||
518 | } catch (Exception e1) { |
||
519 | throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_INTERSECTS_CODE, e1); |
||
520 | } |
||
521 | |||
522 | DefaultRelationshipGeometryOperationContext drgoc = |
||
523 | new DefaultRelationshipGeometryOperationContext(rectgeom);
|
||
524 | |||
525 | Object resp = null; |
||
526 | boolean respboolean = true; |
||
527 | try {
|
||
528 | resp = geom.invokeOperation(GeometryOperation.OPERATION_INTERSECTS_CODE, drgoc); |
||
529 | respboolean = ((Boolean) resp).booleanValue();
|
||
530 | } catch (Exception e) { |
||
531 | throw new GeometryOperationException(geom.getType(), GeometryOperation.OPERATION_INTERSECTS_CODE, e); |
||
532 | } |
||
533 | |||
534 | return respboolean;
|
||
535 | |||
536 | |||
537 | } |
||
538 | |||
539 | 32924 | jjdelcerro | private com.vividsolutions.jts.geom.Geometry getJTS() {
|
540 | return Converter.geometryToJts(this); |
||
541 | } |
||
542 | 29972 | jldominguez | |
543 | 32924 | jjdelcerro | public byte[] convertToWKB() throws GeometryOperationNotSupportedException, |
544 | GeometryOperationException { |
||
545 | return (byte[]) this.invokeOperation(OPERATIONS.CONVERTTOWKB, null); |
||
546 | } |
||
547 | |||
548 | public String convertToWKT() throws GeometryOperationNotSupportedException, |
||
549 | GeometryOperationException { |
||
550 | return (String) this.invokeOperation(OPERATIONS.CONVERTTOWKT, null); |
||
551 | } |
||
552 | |||
553 | public Geometry buffer(double distance) |
||
554 | throws GeometryOperationNotSupportedException,
|
||
555 | GeometryOperationException { |
||
556 | // TODO: this method can be implemented throw invokeOperation
|
||
557 | try {
|
||
558 | return Converter.jtsToGeometry( getJTS().buffer(distance) );
|
||
559 | } catch (CreateGeometryException e) {
|
||
560 | throw new GeometryOperationException(e); |
||
561 | } |
||
562 | } |
||
563 | 29972 | jldominguez | |
564 | 32924 | jjdelcerro | public boolean contains(Geometry geometry) |
565 | throws GeometryOperationNotSupportedException,
|
||
566 | GeometryOperationException { |
||
567 | // TODO: this method can be implemented throw invokeOperation
|
||
568 | return getJTS().contains(Converter.geometryToJts(geometry));
|
||
569 | } |
||
570 | |||
571 | public double distance(Geometry geometry) |
||
572 | throws GeometryOperationNotSupportedException,
|
||
573 | GeometryOperationException { |
||
574 | // TODO: this method can be implemented throw invokeOperation
|
||
575 | return getJTS().distance( Converter.geometryToJts(geometry));
|
||
576 | } |
||
577 | |||
578 | public boolean overlaps(Geometry geometry) |
||
579 | throws GeometryOperationNotSupportedException,
|
||
580 | GeometryOperationException { |
||
581 | // TODO: this method can be implemented throw invokeOperation
|
||
582 | return getJTS().overlaps(Converter.geometryToJts(geometry));
|
||
583 | } |
||
584 | |||
585 | public Geometry convexHull() throws GeometryOperationNotSupportedException, |
||
586 | GeometryOperationException { |
||
587 | // TODO: this method can be implemented throw invokeOperation
|
||
588 | try {
|
||
589 | return Converter.jtsToGeometry( getJTS().convexHull() );
|
||
590 | } catch (CreateGeometryException e) {
|
||
591 | throw new GeometryOperationException(e); |
||
592 | } |
||
593 | } |
||
594 | |||
595 | public boolean coveredBy(Geometry geometry) |
||
596 | throws GeometryOperationNotSupportedException,
|
||
597 | GeometryOperationException { |
||
598 | // TODO: this method can be implemented throw invokeOperation
|
||
599 | return getJTS().coveredBy( Converter.geometryToJts(geometry));
|
||
600 | } |
||
601 | |||
602 | public boolean crosses(Geometry geometry) |
||
603 | throws GeometryOperationNotSupportedException,
|
||
604 | GeometryOperationException { |
||
605 | // TODO: this method can be implemented throw invokeOperation
|
||
606 | return getJTS().crosses(Converter.geometryToJts(geometry));
|
||
607 | } |
||
608 | |||
609 | public Geometry difference(Geometry other)
|
||
610 | throws GeometryOperationNotSupportedException,
|
||
611 | GeometryOperationException { |
||
612 | // TODO: this method can be implemented throw invokeOperation
|
||
613 | try {
|
||
614 | return Converter.jtsToGeometry( getJTS().difference( Converter.geometryToJts(other)) );
|
||
615 | } catch (CreateGeometryException e) {
|
||
616 | throw new GeometryOperationException(e); |
||
617 | } |
||
618 | } |
||
619 | |||
620 | public Geometry intersection(Geometry other)
|
||
621 | throws GeometryOperationNotSupportedException,
|
||
622 | GeometryOperationException { |
||
623 | // TODO: this method can be implemented throw invokeOperation
|
||
624 | try {
|
||
625 | return Converter.jtsToGeometry( getJTS().intersection(Converter.geometryToJts(other)) );
|
||
626 | } catch (CreateGeometryException e) {
|
||
627 | throw new GeometryOperationException(e); |
||
628 | } |
||
629 | } |
||
630 | |||
631 | public boolean intersects(Geometry geometry) |
||
632 | throws GeometryOperationNotSupportedException,
|
||
633 | GeometryOperationException { |
||
634 | // TODO: this method can be implemented throw invokeOperation
|
||
635 | return getJTS().intersects(Converter.geometryToJts(geometry));
|
||
636 | } |
||
637 | |||
638 | public boolean touches(Geometry geometry) |
||
639 | throws GeometryOperationNotSupportedException,
|
||
640 | GeometryOperationException { |
||
641 | // TODO: this method can be implemented throw invokeOperation
|
||
642 | return getJTS().touches(Converter.geometryToJts(geometry));
|
||
643 | } |
||
644 | |||
645 | public Geometry union(Geometry other)
|
||
646 | throws GeometryOperationNotSupportedException,
|
||
647 | GeometryOperationException { |
||
648 | // TODO: this method can be implemented throw invokeOperation
|
||
649 | try {
|
||
650 | return Converter.jtsToGeometry( getJTS().union(Converter.geometryToJts(other)) );
|
||
651 | } catch (CreateGeometryException e) {
|
||
652 | throw new GeometryOperationException(e); |
||
653 | } |
||
654 | } |
||
655 | |||
656 | public boolean disjoint(Geometry geometry) |
||
657 | throws GeometryOperationNotSupportedException,
|
||
658 | GeometryOperationException { |
||
659 | // TODO: this method can be implemented throw invokeOperation
|
||
660 | return getJTS().disjoint(Converter.geometryToJts(geometry));
|
||
661 | } |
||
662 | |||
663 | public boolean within(Geometry geometry) |
||
664 | throws GeometryOperationNotSupportedException,
|
||
665 | GeometryOperationException { |
||
666 | // TODO: this method can be implemented throw invokeOperation
|
||
667 | return getJTS().within(Converter.geometryToJts(geometry));
|
||
668 | } |
||
669 | |||
670 | 33262 | jpiera | public Point centroid() throws GeometryOperationNotSupportedException, GeometryOperationException { |
671 | com.vividsolutions.jts.geom.Geometry geometry = getJTS(); |
||
672 | com.vividsolutions.jts.geom.Point point = geometry.getCentroid(); |
||
673 | GeometryOperationContext geometryOperationContext = new GeometryOperationContext();
|
||
674 | geometryOperationContext.setAttribute("JTSGeometry", point);
|
||
675 | return (Point)this.invokeOperation("fromJTS", geometryOperationContext); |
||
676 | 38770 | jldominguez | } |
677 | 34140 | jpiera | |
678 | 38770 | jldominguez | |
679 | public Point getInteriorPoint() throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
680 | |||
681 | try {
|
||
682 | com.vividsolutions.jts.geom.Geometry geometry = getJTS(); |
||
683 | com.vividsolutions.jts.geom.Point point = geometry.getInteriorPoint(); |
||
684 | GeometryOperationContext geometryOperationContext = new GeometryOperationContext();
|
||
685 | geometryOperationContext.setAttribute("JTSGeometry", point);
|
||
686 | return (Point)this.invokeOperation("fromJTS", geometryOperationContext); |
||
687 | } catch (GeometryOperationNotSupportedException ns_ex) {
|
||
688 | throw ns_ex;
|
||
689 | } catch (GeometryOperationException op_ex) {
|
||
690 | throw op_ex;
|
||
691 | } catch (Exception ex) { |
||
692 | /*
|
||
693 | * This is for unexpected null pointer exceptions or other
|
||
694 | */
|
||
695 | throw new GeometryOperationException(ex); |
||
696 | } |
||
697 | } |
||
698 | |||
699 | |||
700 | 34140 | jpiera | public double area() throws GeometryOperationNotSupportedException, GeometryOperationException |
701 | { |
||
702 | //Using get getJTS method instead of use the "toJTS" operation just for performance
|
||
703 | return getJTS().getArea();
|
||
704 | } |
||
705 | |||
706 | public double perimeter() throws GeometryOperationNotSupportedException, GeometryOperationException |
||
707 | { |
||
708 | //Using get getJTS method instead of use the "toJTS" operation just for performance
|
||
709 | return getJTS().getLength();
|
||
710 | } |
||
711 | 35346 | jpiera | |
712 | public Shape getShape() { |
||
713 | return this; |
||
714 | 35472 | jpiera | } |
715 | |||
716 | public Shape getShape(AffineTransform affineTransform) { |
||
717 | if (affineTransform == null){ |
||
718 | return this; |
||
719 | } |
||
720 | 37201 | jpiera | return new GeneralPathAdapter(affineTransform, getGeneralPath()); |
721 | 35346 | jpiera | } |
722 | 20761 | jmvivo | } |