root / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / Geometry.java @ 29166
History | View | Annotate | Download (12 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.geom; |
29 |
|
30 |
import java.awt.Shape; |
31 |
import java.awt.geom.AffineTransform; |
32 |
import java.awt.geom.PathIterator; |
33 |
import java.awt.geom.Rectangle2D; |
34 |
import java.io.Serializable; |
35 |
|
36 |
import org.cresques.cts.ICoordTrans; |
37 |
import org.gvsig.fmap.geom.handler.Handler; |
38 |
import org.gvsig.fmap.geom.operation.GeometryOperationContext; |
39 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
40 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
41 |
import org.gvsig.fmap.geom.primitive.Envelope; |
42 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
43 |
import org.gvsig.fmap.geom.type.GeometryType; |
44 |
|
45 |
/**
|
46 |
* <p>
|
47 |
* This interface is equivalent to the GM_Object specified in
|
48 |
* <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012">ISO 19107</a>.
|
49 |
* It is the root class of the geometric object taxonomy and supports
|
50 |
* interfaces common to all geographically referenced geometric objects.
|
51 |
* </p>
|
52 |
* <p>
|
53 |
* Geometry instances are sets of direct positions in a particular
|
54 |
* coordinate reference system. A Geometry can be regarded as an
|
55 |
* infinite set of points that satisfies the set operation interfaces
|
56 |
* for a set of direct positions.
|
57 |
* </p>
|
58 |
* <p>
|
59 |
* A geometric object shall be a combination of a coordinate geometry
|
60 |
* and a coordinate reference system. In all of the operations,
|
61 |
* all geometric calculations shall be done in the coordinate
|
62 |
* reference system of the first geometric object accessed,
|
63 |
* which is normally the object whose operation is being invoked.
|
64 |
* Returned objects shall be in the coordinate reference system in which
|
65 |
* the calculations are done unless explicitly stated otherwise.
|
66 |
* </p>
|
67 |
* @see <a href="http://www.iso.org/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=26012">ISO 19107</a>
|
68 |
*/
|
69 |
public interface Geometry extends Shape, Serializable, Comparable { |
70 |
|
71 |
/**
|
72 |
* Predefined geometry types in the model.
|
73 |
*/
|
74 |
public interface TYPES { |
75 |
/**
|
76 |
* NO DATA geometry.
|
77 |
*/
|
78 |
public final static int NULL = -1; |
79 |
|
80 |
/**
|
81 |
* Any geometry.
|
82 |
*/
|
83 |
|
84 |
public final static int GEOMETRY = 0; |
85 |
|
86 |
/**
|
87 |
* A geometric element that has zero dimensions and a location determinable by an ordered set
|
88 |
* of coordinates.
|
89 |
*/
|
90 |
public final static int POINT = 1; |
91 |
|
92 |
/**
|
93 |
* A straight or curved geometric element that is generated by a moving point and that has extension
|
94 |
* only along the path of the point.
|
95 |
*/
|
96 |
public final static int CURVE = 2; |
97 |
|
98 |
/**
|
99 |
* A closed plane figure bounded by straight lines.
|
100 |
*/
|
101 |
public final static int SURFACE = 4; |
102 |
|
103 |
/**
|
104 |
* Solids in 3D.
|
105 |
*/
|
106 |
public final static int SOLID = 8; |
107 |
|
108 |
/**
|
109 |
* Words, symbols and form of a written or printed work.
|
110 |
*/
|
111 |
public final static int TEXT = 16; |
112 |
|
113 |
/**
|
114 |
* A set that can contain points, lines and polygons. This is usual in <i>CAD</i> layers <i>(dxf, dgn, dwg)</i>.
|
115 |
*/
|
116 |
public final static int AGGREGATE = 32; |
117 |
/**
|
118 |
* A set of points.
|
119 |
*/
|
120 |
public final static int MULTIPOINT = 64; |
121 |
|
122 |
/**
|
123 |
* A set of lines.
|
124 |
*/
|
125 |
public final static int MULTICURVE = 128; |
126 |
|
127 |
/**
|
128 |
* A set of polygons.
|
129 |
*/
|
130 |
public final static int MULTISURFACE = 256; |
131 |
|
132 |
/**
|
133 |
* A set of solids.
|
134 |
*/
|
135 |
public final static int MULTISOLID = 512; |
136 |
|
137 |
/**
|
138 |
* A closed plane curve every point of which is equidistant from a fixed point within the curve.
|
139 |
*/
|
140 |
public final static int CIRCLE = 1024; |
141 |
|
142 |
/**
|
143 |
* A continuous portion (as of a circle or ellipse) of a curved line.
|
144 |
*/
|
145 |
public final static int ARC = 2048; |
146 |
|
147 |
/**
|
148 |
* A closed plane curve generated by a point moving in such a way that the sums of its distances
|
149 |
* from two fixed points is a constant : a plane section of a right circular cone that is a closed
|
150 |
* curve.
|
151 |
*/
|
152 |
public final static int ELLIPSE=4096; |
153 |
|
154 |
public final static int SPLINE = 8192; |
155 |
|
156 |
public final static int ELLIPTICARC = 16384; |
157 |
|
158 |
} |
159 |
|
160 |
/**
|
161 |
* The subtype of a geometry is related with the dimension
|
162 |
* of the geometry, that is a combination between the
|
163 |
* spatial dimension (2D, 2ZD, 3D) and the M coordinate
|
164 |
* or "measure".
|
165 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
166 |
*/
|
167 |
public interface SUBTYPES{ |
168 |
/**
|
169 |
* The subtype us unknown.
|
170 |
*/
|
171 |
public final static int UNKNOWN = 0; |
172 |
|
173 |
/**
|
174 |
* Geometries with two dimensions.
|
175 |
*/
|
176 |
public final static int GEOM2D = 1; |
177 |
|
178 |
/**
|
179 |
* Geometries with two dimensions and with a value
|
180 |
* for the elevation.
|
181 |
*/
|
182 |
public final static int GEOM2DZ = 2; |
183 |
|
184 |
/**
|
185 |
* Geometries with three dimensions.
|
186 |
*/
|
187 |
public final static int GEOM3D = 3; |
188 |
|
189 |
/**
|
190 |
* Geometries with two dimensions and with the
|
191 |
* M coordinate.
|
192 |
*/
|
193 |
public final static int GEOM2DM = 4; |
194 |
|
195 |
/**
|
196 |
* Geometries with three dimensions and with the
|
197 |
* M coordinate.
|
198 |
*/
|
199 |
public final static int GEOM3DM = 5; |
200 |
} |
201 |
|
202 |
/** Initial value for new geometry types (it must not overlap with the basic ones defined in TYPES). */
|
203 |
public static final int EXTENDED_GEOMTYPE_OFFSET = 65536; //2^16; |
204 |
|
205 |
public static int BEST = 0; |
206 |
/**
|
207 |
* North.
|
208 |
*/
|
209 |
public static int N = 1; |
210 |
|
211 |
/**
|
212 |
* North - East.
|
213 |
*/
|
214 |
public static int NE = 2; |
215 |
|
216 |
/**
|
217 |
* East.
|
218 |
*/
|
219 |
public static int E = 3; |
220 |
|
221 |
/**
|
222 |
* South - East.
|
223 |
*/
|
224 |
public static int SE = 4; |
225 |
|
226 |
/**
|
227 |
* South.
|
228 |
*/
|
229 |
public static int S = 5; |
230 |
|
231 |
/**
|
232 |
* South - West.
|
233 |
*/
|
234 |
public static int SW = 6; |
235 |
|
236 |
/**
|
237 |
* West.
|
238 |
*/
|
239 |
public static int W = 7; |
240 |
|
241 |
/**
|
242 |
* North - West.
|
243 |
*/
|
244 |
public static int NW = 8; |
245 |
|
246 |
public static int SELECTHANDLER=0; |
247 |
public static int STRETCHINGHANDLER=1; |
248 |
|
249 |
/**
|
250 |
* If this geometry is a predefined interface then this method returns one of {@link Geometry.TYPES} contants.<br>
|
251 |
* If this geometry is an extended type then this method returns a runtime constant that identifies its type.
|
252 |
* By convention this value is stored in a constant called .CODE within the geometry class, for instance: Point2D.CODE.
|
253 |
*
|
254 |
* @return If this geometry is a predefined interface then one of {@link Geometry.TYPES} or a runtime constant if
|
255 |
* it is an extended type.
|
256 |
*/
|
257 |
public int getType(); |
258 |
|
259 |
/**
|
260 |
* Creates a clone of this geometry.
|
261 |
*
|
262 |
* @return A clone of this geometry.
|
263 |
*/
|
264 |
public Geometry cloneGeometry();
|
265 |
|
266 |
/**
|
267 |
* Returns true if this geometry intersects the rectangle passed as parameter.
|
268 |
*
|
269 |
* @param r Rectangle.
|
270 |
*
|
271 |
* @return True, if <code>this</code> intersects <code>r</code>.
|
272 |
*/
|
273 |
public boolean intersects(Rectangle2D r); |
274 |
|
275 |
/**
|
276 |
* Used by the drawing strategies to quickly test whether this geometry
|
277 |
* intersects with the visible rectangle.
|
278 |
*
|
279 |
* @param x
|
280 |
* The minimum X coordinate.
|
281 |
* @param y
|
282 |
* The minimum Y coordinate.
|
283 |
* @param w
|
284 |
* The width of the envelope.
|
285 |
* @param h
|
286 |
* The height of the envelope.
|
287 |
* @return true if <code>this</code> intersects the rectangle defined by the parameters.
|
288 |
*/
|
289 |
public boolean fastIntersects(double x, double y, double w, double h); |
290 |
|
291 |
/**
|
292 |
* Returns this geometry's boundary rectangle.
|
293 |
* @deprecated use getEnvelope.
|
294 |
* @return Boundary rectangle.
|
295 |
*/
|
296 |
public Rectangle2D getBounds2D(); |
297 |
|
298 |
/**
|
299 |
* <p>
|
300 |
* Returns the minimum bounding box for this Geometry. This shall
|
301 |
* be the coordinate region spanning the minimum and maximum value
|
302 |
* for each ordinate taken on by DirectPositions in this Geometry.
|
303 |
* The simplest representation for an envelope consists of two
|
304 |
* DirectPositions, the first one containing all the minimums for
|
305 |
* each ordinate, and second one containing all the maximums.
|
306 |
* </p>
|
307 |
* @return
|
308 |
* The minimum bounding box for this Geometry.
|
309 |
*/
|
310 |
public Envelope getEnvelope();
|
311 |
|
312 |
/**
|
313 |
* Reprojects this geometry by the coordinate transformer
|
314 |
* passed as parameter.
|
315 |
*
|
316 |
* @param ct
|
317 |
* Coordinate Transformer.
|
318 |
*/
|
319 |
public void reProject(ICoordTrans ct); |
320 |
|
321 |
/**
|
322 |
* If applies an affine transformation and
|
323 |
* returns the GeneralPathXIterator with this geometry's information.
|
324 |
* @param at
|
325 |
* The transformation to apply.
|
326 |
* @return
|
327 |
* The GeneralPathXIterator with this geometry's information.
|
328 |
*/
|
329 |
public PathIterator getPathIterator(AffineTransform at); |
330 |
|
331 |
/**
|
332 |
* It returns the handlers of the geometry,
|
333 |
* these they can be of two types is straightening and of selection.
|
334 |
*
|
335 |
* @param type
|
336 |
* Type of handlers.
|
337 |
*
|
338 |
* @return
|
339 |
* The handlers.
|
340 |
*/
|
341 |
public Handler[] getHandlers(int type); |
342 |
|
343 |
/**
|
344 |
* It applies an affine transformation to the geometry.
|
345 |
*
|
346 |
* @param at
|
347 |
* The transformation to apply.
|
348 |
*/
|
349 |
public void transform(AffineTransform at); |
350 |
|
351 |
/**
|
352 |
* If applies an affine transformation and
|
353 |
* returns the GeneralPathXIterator with this geometry's information.
|
354 |
* @param at
|
355 |
* The affine transformation.
|
356 |
* @param flatness
|
357 |
*
|
358 |
* @return
|
359 |
* The GeneralPathXIterator with this geometry's information.
|
360 |
*/
|
361 |
PathIterator getPathIterator(AffineTransform at, double flatness); |
362 |
|
363 |
/**
|
364 |
* Useful to have the real shape behind the scenes.
|
365 |
* May be uses to edit it knowing it it is a Circle, Ellipse, etc.
|
366 |
* @return
|
367 |
* The awt shape
|
368 |
*/
|
369 |
public Shape getInternalShape(); |
370 |
|
371 |
/**
|
372 |
* Returns the largest number n such that each direct position
|
373 |
* in a geometric set can be associated with a subset
|
374 |
* that has the direct position in its interior and
|
375 |
* is similar (isomorphic) to Rn, Euclidean n-space.
|
376 |
* @return
|
377 |
* The dimension.
|
378 |
*/
|
379 |
public int getDimension(); |
380 |
|
381 |
/**
|
382 |
* Returns <code>true</code> if this Geometry has no interior point
|
383 |
* of self-intersection or self-tangency. In mathematical
|
384 |
* formalisms, this means that every point in the
|
385 |
* interior of the object must have a metric neighborhood
|
386 |
* whose intersection with the object is isomorphic to an
|
387 |
* n-sphere, where n is the dimension of this Geometry.
|
388 |
* @return
|
389 |
* If the geometry is simple.
|
390 |
*/
|
391 |
public boolean isSimple(); |
392 |
|
393 |
/**
|
394 |
* Invokes a geometry operation given its index and context.
|
395 |
* @param index
|
396 |
* Unique index of the operation. Operation code.
|
397 |
* @param ctx
|
398 |
* The context of the geometry operation.
|
399 |
* @return
|
400 |
* Object returned by the operation.
|
401 |
* @throws GeometryOperationNotSupportedException
|
402 |
* It is thrown when the operation has been not registered for this geometry.
|
403 |
* @throws GeometryOperationException
|
404 |
* It is thrown when there is an error executing the operation.
|
405 |
*/
|
406 |
public Object invokeOperation(int index, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException; |
407 |
|
408 |
/**
|
409 |
* Invokes a geometry operation given its name and context.
|
410 |
* @param opName
|
411 |
* Operation name.
|
412 |
* @param ctx
|
413 |
* The context of the geometry operation.
|
414 |
* @return
|
415 |
* Object returned by the operation.
|
416 |
* @throws GeometryOperationNotSupportedException
|
417 |
* It is thrown when the operation has been not registered for this geometry.
|
418 |
* @throws GeometryOperationException
|
419 |
* It is thrown when there is an error executing the operation.
|
420 |
*/
|
421 |
public Object invokeOperation(String opName, GeometryOperationContext ctx) throws GeometryOperationNotSupportedException, GeometryOperationException; |
422 |
|
423 |
/**
|
424 |
* Instance of the GeometryType associated to this geometry.
|
425 |
* @return
|
426 |
* The geometry type.
|
427 |
*/
|
428 |
public GeometryType getGeometryType();
|
429 |
|
430 |
/**
|
431 |
* Get GeneralPathIterator, to do registered operations to it.
|
432 |
* @return
|
433 |
* The GeneralPathX.
|
434 |
*/
|
435 |
public GeneralPathX getGeneralPath();
|
436 |
} |