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 |
package org.gvsig.fmap.geom.primitive.impl; |
---|---|
2 |
|
3 |
import java.awt.Shape; |
4 |
import java.awt.geom.AffineTransform; |
5 |
import java.awt.geom.PathIterator; |
6 |
import java.awt.geom.Point2D; |
7 |
import java.io.Serializable; |
8 |
|
9 |
import org.cresques.cts.ICoordTrans; |
10 |
import org.cresques.cts.IProjection; |
11 |
import org.slf4j.Logger; |
12 |
import org.slf4j.LoggerFactory; |
13 |
|
14 |
import org.gvsig.fmap.geom.Geometry; |
15 |
import org.gvsig.fmap.geom.GeometryLocator; |
16 |
import org.gvsig.fmap.geom.GeometryManager; |
17 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
18 |
import org.gvsig.fmap.geom.handler.Handler; |
19 |
import org.gvsig.fmap.geom.operation.GeometryOperation; |
20 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
21 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
22 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
23 |
import org.gvsig.fmap.geom.operation.relationship.DefaultRelationshipGeometryOperationContext; |
24 |
import org.gvsig.fmap.geom.primitive.Envelope; |
25 |
import org.gvsig.fmap.geom.primitive.FShape; |
26 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
27 |
import org.gvsig.fmap.geom.primitive.Point; |
28 |
import org.gvsig.fmap.geom.primitive.Primitive; |
29 |
import org.gvsig.fmap.geom.type.GeometryType; |
30 |
import org.gvsig.fmap.geom.util.Converter; |
31 |
|
32 |
|
33 |
/**
|
34 |
* @author Jorge Piera Llodr? (jorge.piera@iver.es)
|
35 |
*/
|
36 |
public abstract class AbstractPrimitive implements Primitive, FShape, Shape, Serializable { |
37 |
|
38 |
private static final Logger logger = LoggerFactory.getLogger(AbstractPrimitive.class); |
39 |
|
40 |
private static final long serialVersionUID = -4334977368955260872L; |
41 |
protected String id = null; |
42 |
protected IProjection projection = null; |
43 |
protected GeometryType geometryType = null; |
44 |
protected static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
45 |
|
46 |
/**
|
47 |
* 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 |
*/
|
53 |
public AbstractPrimitive(GeometryType geometryType) {
|
54 |
this(geometryType, null, null); |
55 |
} |
56 |
|
57 |
AbstractPrimitive(int type, int subtype) { |
58 |
try {
|
59 |
geometryType = geomManager.getGeometryType(type, subtype); |
60 |
} catch (Exception e) { |
61 |
//TODO Not registered geometry
|
62 |
geometryType = null;
|
63 |
} |
64 |
} |
65 |
|
66 |
public AbstractPrimitive(GeometryType geometryType, String id, IProjection projection) { |
67 |
super();
|
68 |
this.id = id;
|
69 |
this.projection = projection;
|
70 |
this.geometryType = geometryType;
|
71 |
} |
72 |
|
73 |
public AbstractPrimitive(GeometryType geometryType, IProjection projection) {
|
74 |
this(geometryType, null, projection); |
75 |
} |
76 |
|
77 |
/* (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 |
/**
|
92 |
* (non-Javadoc)
|
93 |
* @see com.iver.cit.gvsig.fmap.core.Geometry#getInternalShape()
|
94 |
* @deprecated this Geometry is a Shape.
|
95 |
*/
|
96 |
public Shape getInternalShape() { |
97 |
return this; |
98 |
} |
99 |
|
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 |
} |
113 |
|
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 |
|
124 |
|
125 |
/*
|
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 |
*/
|
138 |
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 |
*/
|
147 |
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 |
/*
|
156 |
* (non-Javadoc)
|
157 |
* @see org.gvsig.fmap.geom.Geometry#fastIntersects(double, double, double, double)
|
158 |
*/
|
159 |
public boolean fastIntersects(double x, double y, double w, double h) { |
160 |
|
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 |
} |
171 |
|
172 |
/*
|
173 |
* (non-Javadoc)
|
174 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
175 |
*/
|
176 |
public Geometry cloneGeometry() {
|
177 |
return (Geometry)cloneFShape();
|
178 |
} |
179 |
|
180 |
/*
|
181 |
* (non-Javadoc)
|
182 |
* @see org.gvsig.fmap.geom.Geometry#getHandlers(int)
|
183 |
*/
|
184 |
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 |
/*
|
194 |
* (non-Javadoc)
|
195 |
* @see org.gvsig.fmap.geom.Geometry#isSimple()
|
196 |
*/
|
197 |
public boolean isSimple() { |
198 |
return true; |
199 |
} |
200 |
|
201 |
/*
|
202 |
* (non-Javadoc)
|
203 |
* @see org.gvsig.fmap.geom.Geometry#invokeOperation(int, org.gvsig.fmap.geom.operation.GeometryOperationContext)
|
204 |
*/
|
205 |
public Object invokeOperation(int index, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException { |
206 |
return geomManager.invokeOperation(index, this, ctx); |
207 |
} |
208 |
|
209 |
/*
|
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 |
|
217 |
/*
|
218 |
* (non-Javadoc)
|
219 |
* @see java.lang.Comparable#compareTo(T)
|
220 |
*/
|
221 |
public int compareTo(Object arg0) { |
222 |
// TODO Auto-generated method stub
|
223 |
return -1; |
224 |
} |
225 |
|
226 |
/*
|
227 |
* (non-Javadoc)
|
228 |
* @see java.lang.Object#toString()
|
229 |
*/
|
230 |
public String toString() { |
231 |
String name=getGeometryType().getName();
|
232 |
return name.substring(name.lastIndexOf(".")+1); |
233 |
} |
234 |
|
235 |
/*
|
236 |
* (non-Javadoc)
|
237 |
* @see java.lang.Object#equals(java.lang.Object)
|
238 |
*/
|
239 |
public boolean equals(Object obj) { |
240 |
if (obj == null) { |
241 |
return false; |
242 |
} |
243 |
if (this.getClass() != obj.getClass()) { |
244 |
return false; |
245 |
} |
246 |
|
247 |
AbstractPrimitive other = (AbstractPrimitive) obj; |
248 |
if (this.getGeometryType().getType() != other.getGeometryType() |
249 |
.getType()) { |
250 |
return false; |
251 |
|
252 |
} |
253 |
if (this.getGeometryType().getSubType() != other.getGeometryType() |
254 |
.getSubType()) { |
255 |
return false; |
256 |
|
257 |
} |
258 |
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 |
|
270 |
|
271 |
GeneralPathX myPath = this.getGeneralPath();
|
272 |
GeneralPathX otherPath = other.getGeneralPath(); |
273 |
if (myPath == null) { |
274 |
if (otherPath != null) { |
275 |
return false; |
276 |
} else {
|
277 |
// TODO checkThis
|
278 |
return true; |
279 |
} |
280 |
|
281 |
} |
282 |
if (myPath.getNumTypes() != otherPath.getNumTypes()) {
|
283 |
return false; |
284 |
} |
285 |
if (Math.abs(myPath.getNumCoords() - otherPath.getNumCoords()) > this |
286 |
.getDimension()) { |
287 |
return false; |
288 |
} |
289 |
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 |
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 |
|
298 |
while (!myIter.isDone()) {
|
299 |
if (otherIter.isDone()) {
|
300 |
return false; |
301 |
} |
302 |
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 |
} |
363 |
if (!otherIter.isDone()) {
|
364 |
return false; |
365 |
} |
366 |
return true; |
367 |
} |
368 |
|
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 |
|
378 |
/* (non-Javadoc)
|
379 |
* @see org.gvsig.fmap.geom.primitive.FShape#getShapeType()
|
380 |
*/
|
381 |
public int getShapeType() { |
382 |
return getType();
|
383 |
} |
384 |
|
385 |
|
386 |
|
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 |
private com.vividsolutions.jts.geom.Geometry getJTS() {
|
540 |
return Converter.geometryToJts(this); |
541 |
} |
542 |
|
543 |
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 |
|
564 |
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 |
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 |
} |
677 |
|
678 |
|
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 |
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 |
|
712 |
public Shape getShape() { |
713 |
return this; |
714 |
} |
715 |
|
716 |
public Shape getShape(AffineTransform affineTransform) { |
717 |
if (affineTransform == null){ |
718 |
return this; |
719 |
} |
720 |
return new GeneralPathAdapter(affineTransform, getGeneralPath()); |
721 |
} |
722 |
} |