Revision 5878 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/gt2/FLiteShape.java
FLiteShape.java | ||
---|---|---|
2 | 2 |
* Created on 12-may-2005 |
3 | 3 |
* |
4 | 4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
5 |
*
|
|
5 |
* |
|
6 | 6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
7 |
*
|
|
7 |
* |
|
8 | 8 |
* This program is free software; you can redistribute it and/or |
9 | 9 |
* modify it under the terms of the GNU General Public License |
10 | 10 |
* as published by the Free Software Foundation; either version 2 |
11 | 11 |
* of the License, or (at your option) any later version. |
12 |
*
|
|
12 |
* |
|
13 | 13 |
* This program is distributed in the hope that it will be useful, |
14 | 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | 16 |
* GNU General Public License for more details. |
17 |
*
|
|
17 |
* |
|
18 | 18 |
* You should have received a copy of the GNU General Public License |
19 | 19 |
* along with this program; if not, write to the Free Software |
20 | 20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* For more information, contact: |
23 | 23 |
* |
24 | 24 |
* Generalitat Valenciana |
... | ... | |
30 | 30 |
* +34 963862235 |
31 | 31 |
* gvsig@gva.es |
32 | 32 |
* www.gvsig.gva.es |
33 |
*
|
|
33 |
* |
|
34 | 34 |
* or |
35 |
*
|
|
35 |
* |
|
36 | 36 |
* IVER T.I. S.A |
37 | 37 |
* Salamanca 50 |
38 | 38 |
* 46005 Valencia |
39 | 39 |
* Spain |
40 |
*
|
|
40 |
* |
|
41 | 41 |
* +34 963163400 |
42 | 42 |
* dac@iver.es |
43 | 43 |
*/ |
... | ... | |
92 | 92 |
private AffineTransform affineTransform = null; |
93 | 93 |
private boolean generalize = false; |
94 | 94 |
private double maxDistance = 1; |
95 |
|
|
95 |
|
|
96 | 96 |
// cached iterators |
97 | 97 |
private LineIterator lineIterator = new LineIterator(); |
98 | 98 |
private GeomCollectionIterator collIterator = new GeomCollectionIterator(); |
... | ... | |
100 | 100 |
private float xScale; |
101 | 101 |
|
102 | 102 |
private float yScale; |
103 |
|
|
103 |
|
|
104 | 104 |
private GeometryFactory geomFac; |
105 | 105 |
|
106 | 106 |
private MathTransform mathTransform; |
107 | 107 |
|
108 | 108 |
private static final AffineTransform IDENTITY = new AffineTransform(); |
109 |
|
|
109 |
|
|
110 | 110 |
class PointHandler extends AbstractHandler { |
111 | 111 |
/** |
112 | 112 |
* Crea un nuevo PointHandler. |
... | ... | |
129 | 129 |
* |
130 | 130 |
* @return DOCUMENT ME! |
131 | 131 |
*/ |
132 |
public void move(double x, double y) {
|
|
132 |
public void move(double x, double y) { |
|
133 | 133 |
c.x+=x; |
134 | 134 |
c.y+=y; |
135 | 135 |
geometry.geometryChanged(); |
... | ... | |
144 | 144 |
geometry.geometryChanged(); |
145 | 145 |
} |
146 | 146 |
} |
147 |
|
|
148 | 147 |
|
148 |
|
|
149 | 149 |
/** |
150 | 150 |
* Creates a new LiteShape object. |
151 | 151 |
* |
... | ... | |
154 | 154 |
* @param generalize - set to true if the geometry need to be generalized |
155 | 155 |
* during rendering |
156 | 156 |
* @param maxDistance - distance used in the generalization process |
157 |
* @throws TransformException
|
|
158 |
* @throws FactoryException
|
|
157 |
* @throws TransformException |
|
158 |
* @throws FactoryException |
|
159 | 159 |
*/ |
160 | 160 |
public FLiteShape(Geometry geom, AffineTransform at, MathTransform mathTransform, boolean generalize, |
161 | 161 |
double maxDistance) throws TransformException, FactoryException { |
... | ... | |
171 | 171 |
* @param generalize - set to true if the geometry need to be generalized |
172 | 172 |
* during rendering |
173 | 173 |
* @param maxDistance - distance used in the generalization process |
174 |
* @throws TransformException
|
|
175 |
* @throws FactoryException
|
|
174 |
* @throws TransformException |
|
175 |
* @throws FactoryException |
|
176 | 176 |
*/ |
177 | 177 |
public FLiteShape(Geometry geom, AffineTransform at, MathTransform mathTransform, boolean generalize) throws TransformException, FactoryException { |
178 | 178 |
if( geom!=null) |
... | ... | |
200 | 200 |
* @param generalize - set to true if the geometry need to be generalized |
201 | 201 |
* during rendering |
202 | 202 |
* @param maxDistance - distance used in the generalization process |
203 |
* @throws TransformException
|
|
203 |
* @throws TransformException |
|
204 | 204 |
*/ |
205 | 205 |
public FLiteShape(Geometry geom, AffineTransform at, boolean generalize, |
206 | 206 |
double maxDistance){ |
207 | 207 |
this(geom, at, generalize); |
208 | 208 |
this.maxDistance = maxDistance; |
209 | 209 |
} |
210 |
|
|
210 |
|
|
211 | 211 |
public FLiteShape(Geometry geom) |
212 | 212 |
{ |
213 | 213 |
this(geom, null, false); |
... | ... | |
221 | 221 |
* @param generalize - set to true if the geometry need to be generalized |
222 | 222 |
* during rendering |
223 | 223 |
* @param maxDistance - distance used in the generalization process |
224 |
* @throws TransformException
|
|
224 |
* @throws TransformException |
|
225 | 225 |
*/ |
226 | 226 |
public FLiteShape(Geometry geom, AffineTransform at, boolean generalize){ |
227 | 227 |
if( geom!=null) |
... | ... | |
245 | 245 |
(affineTransform.getScaleY() * affineTransform.getScaleY()) |
246 | 246 |
+ (affineTransform.getShearY() * affineTransform.getShearY())); |
247 | 247 |
} |
248 |
|
|
248 |
|
|
249 | 249 |
private void transformGeometry(Geometry geometry) throws TransformException, FactoryException { |
250 |
|
|
250 |
|
|
251 | 251 |
if( mathTransform==null || mathTransform.isIdentity() ){ |
252 | 252 |
if( !affineTransform.isIdentity() ){ |
253 | 253 |
MathTransformFactory factory=FactoryFinder.getMathTransformFactory(null); |
... | ... | |
259 | 259 |
factory.createConcatenatedTransform(mathTransform, factory.createAffineTransform(new GeneralMatrix(affineTransform))); |
260 | 260 |
affineTransform=IDENTITY; |
261 | 261 |
} |
262 |
|
|
262 |
|
|
263 | 263 |
if( mathTransform==null || mathTransform.isIdentity() ) |
264 | 264 |
return; |
265 |
|
|
266 |
|
|
265 |
|
|
266 |
|
|
267 | 267 |
CoordinateSequenceTransformer transformer=new InPlaceCoordinateSequenceTransformer(); |
268 | 268 |
if (geometry instanceof GeometryCollection) { |
269 | 269 |
GeometryCollection collection=(GeometryCollection)geometry; |
... | ... | |
272 | 272 |
} |
273 | 273 |
}else if (geometry instanceof Point) { |
274 | 274 |
transformer.transform(((Point)geometry).getCoordinateSequence(), mathTransform); |
275 |
}else if (geometry instanceof Polygon) {
|
|
275 |
}else if (geometry instanceof Polygon) { |
|
276 | 276 |
Polygon polygon=(Polygon) geometry; |
277 | 277 |
transformGeometry(polygon.getExteriorRing()); |
278 | 278 |
for (int i = 0; i < polygon.getNumInteriorRing(); i++) { |
... | ... | |
280 | 280 |
} |
281 | 281 |
} else if (geometry instanceof LineString) { |
282 | 282 |
transformer.transform(((LineString)geometry).getCoordinateSequence(), mathTransform); |
283 |
}
|
|
283 |
} |
|
284 | 284 |
} |
285 | 285 |
|
286 | 286 |
private GeometryFactory getGeometryFactory() { |
... | ... | |
296 | 296 |
* object instead of creating it again and again during rendering |
297 | 297 |
* |
298 | 298 |
* @param g |
299 |
* @throws TransformException
|
|
300 |
* @throws FactoryException
|
|
299 |
* @throws TransformException |
|
300 |
* @throws FactoryException |
|
301 | 301 |
*/ |
302 | 302 |
public void setGeometry(Geometry g) throws TransformException, FactoryException { |
303 | 303 |
if( g!=null){ |
... | ... | |
316 | 316 |
} catch (FactoryException e) { |
317 | 317 |
// TODO Auto-generated catch block |
318 | 318 |
e.printStackTrace(); |
319 |
}
|
|
319 |
} |
|
320 | 320 |
xScale = (float) Math.sqrt( |
321 | 321 |
(affineTransform.getScaleX() * affineTransform.getScaleX()) |
322 | 322 |
+ (affineTransform.getShearX() * affineTransform.getShearX())); |
323 | 323 |
yScale = (float) Math.sqrt( |
324 | 324 |
(affineTransform.getScaleY() * affineTransform.getScaleY()) |
325 | 325 |
+ (affineTransform.getShearY() * affineTransform.getShearY())); |
326 |
|
|
326 |
|
|
327 | 327 |
} |
328 | 328 |
|
329 | 329 |
/** |
330 | 330 |
* Tests if the interior of the <code>Shape</code> entirely contains the |
331 | 331 |
* specified <code>Rectangle2D</code>. This method might conservatively |
332 | 332 |
* return <code>false</code> when: |
333 |
*
|
|
333 |
* |
|
334 | 334 |
* <ul> |
335 | 335 |
* <li> |
336 | 336 |
* the <code>intersect</code> method returns <code>true</code> and |
... | ... | |
341 | 341 |
* expensive. |
342 | 342 |
* </li> |
343 | 343 |
* </ul> |
344 |
*
|
|
344 |
* |
|
345 | 345 |
* This means that this method might return <code>false</code> even though |
346 | 346 |
* the <code>Shape</code> contains the <code>Rectangle2D</code>. The |
347 | 347 |
* <code>Area</code> class can be used to perform more accurate |
... | ... | |
405 | 405 |
* rectangular area must lie within the <code>Shape</code> for the entire |
406 | 406 |
* rectanglar area to be considered contained within the |
407 | 407 |
* <code>Shape</code>. |
408 |
*
|
|
408 |
* |
|
409 | 409 |
* <p> |
410 | 410 |
* This method might conservatively return <code>false</code> when: |
411 |
*
|
|
411 |
* |
|
412 | 412 |
* <ul> |
413 | 413 |
* <li> |
414 | 414 |
* the <code>intersect</code> method returns <code>true</code> and |
... | ... | |
418 | 418 |
* entirely contains the rectangular area are prohibitively expensive. |
419 | 419 |
* </li> |
420 | 420 |
* </ul> |
421 |
*
|
|
421 |
* |
|
422 | 422 |
* This means that this method might return <code>false</code> even though |
423 | 423 |
* the <code>Shape</code> contains the rectangular area. The |
424 | 424 |
* <code>Area</code> class can be used to perform more accurate |
... | ... | |
574 | 574 |
* boundary and provides access to the geometry of the <code>Shape</code> |
575 | 575 |
* outline. If an optional {@link AffineTransform} is specified, the |
576 | 576 |
* coordinates returned in the iteration are transformed accordingly. |
577 |
*
|
|
577 |
* |
|
578 | 578 |
* <p> |
579 | 579 |
* Each call to this method returns a fresh <code>PathIterator</code> |
580 | 580 |
* object that traverses the geometry of the <code>Shape</code> object |
581 | 581 |
* independently from any other <code>PathIterator</code> objects in use |
582 | 582 |
* at the same time. |
583 | 583 |
* </p> |
584 |
*
|
|
584 |
* |
|
585 | 585 |
* <p> |
586 | 586 |
* It is recommended, but not guaranteed, that objects implementing the |
587 | 587 |
* <code>Shape</code> interface isolate iterations that are in process |
588 | 588 |
* from any changes that might occur to the original object's geometry |
589 | 589 |
* during such iterations. |
590 | 590 |
* </p> |
591 |
*
|
|
591 |
* |
|
592 | 592 |
* <p> |
593 | 593 |
* Before using a particular implementation of the <code>Shape</code> |
594 | 594 |
* interface in more than one thread simultaneously, refer to its |
... | ... | |
619 | 619 |
pi = new PointIterator((Point) geometry, combined); |
620 | 620 |
} |
621 | 621 |
|
622 |
if (this.geometry instanceof Polygon) {
|
|
622 |
if (this.geometry instanceof Polygon) { |
|
623 | 623 |
|
624 | 624 |
pi = new PolygonIterator((Polygon) geometry, combined, generalize, |
625 | 625 |
maxDistance); |
... | ... | |
635 | 635 |
if(combined == affineTransform) |
636 | 636 |
lineIterator.init((LineString) geometry, combined, generalize, |
637 | 637 |
(float) maxDistance, xScale, yScale); |
638 |
else
|
|
638 |
else |
|
639 | 639 |
lineIterator.init((LineString) geometry, combined, generalize, |
640 | 640 |
(float) maxDistance); |
641 | 641 |
pi = lineIterator; |
... | ... | |
651 | 651 |
* Returns an iterator object that iterates along the <code>Shape</code> |
652 | 652 |
* boundary and provides access to a flattened view of the |
653 | 653 |
* <code>Shape</code> outline geometry. |
654 |
*
|
|
654 |
* |
|
655 | 655 |
* <p> |
656 | 656 |
* Only SEG_MOVETO, SEG_LINETO, and SEG_CLOSE point types are returned by |
657 | 657 |
* the iterator. |
658 | 658 |
* </p> |
659 |
*
|
|
659 |
* |
|
660 | 660 |
* <p> |
661 | 661 |
* If an optional <code>AffineTransform</code> is specified, the |
662 | 662 |
* coordinates returned in the iteration are transformed accordingly. |
663 | 663 |
* </p> |
664 |
*
|
|
664 |
* |
|
665 | 665 |
* <p> |
666 | 666 |
* The amount of subdivision of the curved segments is controlled by the |
667 | 667 |
* <code>flatness</code> parameter, which specifies the maximum distance |
... | ... | |
671 | 671 |
* flattening parameters to be treated as larger values. This limit, if |
672 | 672 |
* there is one, is defined by the particular implementation that is used. |
673 | 673 |
* </p> |
674 |
*
|
|
674 |
* |
|
675 | 675 |
* <p> |
676 | 676 |
* Each call to this method returns a fresh <code>PathIterator</code> |
677 | 677 |
* object that traverses the <code>Shape</code> object geometry |
678 | 678 |
* independently from any other <code>PathIterator</code> objects in use |
679 | 679 |
* at the same time. |
680 | 680 |
* </p> |
681 |
*
|
|
681 |
* |
|
682 | 682 |
* <p> |
683 | 683 |
* It is recommended, but not guaranteed, that objects implementing the |
684 | 684 |
* <code>Shape</code> interface isolate iterations that are in process |
685 | 685 |
* from any changes that might occur to the original object's geometry |
686 | 686 |
* during such iterations. |
687 | 687 |
* </p> |
688 |
*
|
|
688 |
* |
|
689 | 689 |
* <p> |
690 | 690 |
* Before using a particular implementation of this interface in more than |
691 | 691 |
* one thread simultaneously, refer to its documentation to verify that it |
... | ... | |
710 | 710 |
* Tests if the interior of the <code>Shape</code> intersects the interior |
711 | 711 |
* of a specified <code>Rectangle2D</code>. This method might |
712 | 712 |
* conservatively return <code>true</code> when: |
713 |
*
|
|
713 |
* |
|
714 | 714 |
* <ul> |
715 | 715 |
* <li> |
716 | 716 |
* there is a high probability that the <code>Rectangle2D</code> and the |
... | ... | |
721 | 721 |
* prohibitively expensive. |
722 | 722 |
* </li> |
723 | 723 |
* </ul> |
724 |
*
|
|
724 |
* |
|
725 | 725 |
* This means that this method might return <code>true</code> even though |
726 | 726 |
* the <code>Rectangle2D</code> does not intersect the <code>Shape</code>. |
727 | 727 |
* |
... | ... | |
746 | 746 |
* of a specified rectangular area. The rectangular area is considered to |
747 | 747 |
* intersect the <code>Shape</code> if any point is contained in both the |
748 | 748 |
* interior of the <code>Shape</code> and the specified rectangular area. |
749 |
*
|
|
749 |
* |
|
750 | 750 |
* <p> |
751 | 751 |
* This method might conservatively return <code>true</code> when: |
752 |
*
|
|
752 |
* |
|
753 | 753 |
* <ul> |
754 | 754 |
* <li> |
755 | 755 |
* there is a high probability that the rectangular area and the |
... | ... | |
760 | 760 |
* prohibitively expensive. |
761 | 761 |
* </li> |
762 | 762 |
* </ul> |
763 |
*
|
|
763 |
* |
|
764 | 764 |
* This means that this method might return <code>true</code> even though |
765 | 765 |
* the rectangular area does not intersect the <code>Shape</code>. The |
766 | 766 |
* {@link java.awt.geom.Area Area} class can be used to perform more |
... | ... | |
819 | 819 |
|
820 | 820 |
return geometry.getFactory().createPolygon(lr, null); |
821 | 821 |
} |
822 |
|
|
822 |
|
|
823 | 823 |
/** |
824 | 824 |
* Returns the affine transform for this lite shape |
825 | 825 |
* @return |
... | ... | |
849 | 849 |
if (geometry instanceof MultiLineString) |
850 | 850 |
type = FShape.LINE; |
851 | 851 |
|
852 |
|
|
852 |
|
|
853 | 853 |
return type; |
854 | 854 |
} |
855 | 855 |
|
... | ... | |
873 | 873 |
pointCoords[i] = pt.getX(); |
874 | 874 |
pointCoords[i+1] = pt.getY(); |
875 | 875 |
} */ |
876 |
|
|
876 |
|
|
877 | 877 |
} |
878 | 878 |
|
879 | 879 |
public Handler[] getStretchingHandlers() { |
Also available in: Unified diff