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