svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / primitive / impl / Envelope2D.java @ 34118
History | View | Annotate | Download (2.94 KB)
1 | 27019 | jpiera | /* 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 | 29116 | jmvivo | *
|
6 | 27019 | jpiera | * 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 | 29116 | jmvivo | *
|
11 | 27019 | jpiera | * 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 | 29116 | jmvivo | *
|
16 | 27019 | jpiera | * 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 | 29116 | jmvivo | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | 27019 | jpiera | * MA 02110-1301, USA.
|
20 | 29116 | jmvivo | *
|
21 | 27019 | jpiera | */
|
22 | |||
23 | /*
|
||
24 | * AUTHORS (In addition to CIT):
|
||
25 | * 2009 {Iver T.I.} {Task}
|
||
26 | */
|
||
27 | |||
28 | 27029 | jpiera | package org.gvsig.fmap.geom.primitive.impl; |
29 | 27019 | jpiera | |
30 | import java.awt.geom.Rectangle2D; |
||
31 | |||
32 | import org.cresques.cts.ICoordTrans; |
||
33 | 27029 | jpiera | import org.gvsig.fmap.geom.primitive.Envelope; |
34 | import org.gvsig.fmap.geom.primitive.Point; |
||
35 | 33388 | jpiera | import org.gvsig.tools.ToolsLocator; |
36 | import org.gvsig.tools.dynobject.DynStruct; |
||
37 | import org.gvsig.tools.persistence.PersistenceManager; |
||
38 | 27019 | jpiera | |
39 | /**
|
||
40 | * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
||
41 | */
|
||
42 | public class Envelope2D extends DefaultEnvelope{ |
||
43 | 33603 | jpiera | public static final String PERSISTENCE_DEFINITION_NAME = "Envelope2Dimensions"; |
44 | 33388 | jpiera | |
45 | 27019 | jpiera | public Envelope2D() {
|
46 | 27397 | jpiera | super();
|
47 | min = new Point2D(0, 0); |
||
48 | 29116 | jmvivo | max = new Point2D(0, 0); |
49 | 27019 | jpiera | } |
50 | 29116 | jmvivo | |
51 | 27019 | jpiera | public Envelope2D(Point min, Point max) { |
52 | super(min, max);
|
||
53 | } |
||
54 | |||
55 | public Envelope2D(double minX,double minY,double maxX, double maxY){ |
||
56 | this(new Point2D(minX, minY), new Point2D(maxX, maxY)); |
||
57 | } |
||
58 | |||
59 | /* (non-Javadoc)
|
||
60 | * @see org.gvsig.fmap.geom.primitive.Envelope#getDimension()
|
||
61 | */
|
||
62 | public int getDimension() { |
||
63 | return 2; |
||
64 | } |
||
65 | |||
66 | /*
|
||
67 | * (non-Javadoc)
|
||
68 | * @see org.gvsig.fmap.geom.primitive.Envelope#convert(org.cresques.cts.ICoordTrans)
|
||
69 | */
|
||
70 | public Envelope convert(ICoordTrans trans) {
|
||
71 | if (this.getDimension() > 2) { |
||
72 | return null; |
||
73 | } |
||
74 | Rectangle2D rect = new Rectangle2D.Double(this.getMinimum(0), this |
||
75 | .getMinimum(1), this.getLength(0), this.getLength(1)); |
||
76 | Rectangle2D rectDest = trans.convert(rect);
|
||
77 | if (rectDest == null){ |
||
78 | return null; |
||
79 | } |
||
80 | 29116 | jmvivo | Point2D p1 = new Point2D(rectDest.getMinX(), rectDest.getMinY()); |
81 | Point2D p2 = new Point2D(rectDest.getMaxX(), rectDest.getMaxY()); |
||
82 | 27019 | jpiera | |
83 | 29116 | jmvivo | return new Envelope2D(p1, p2); |
84 | 27019 | jpiera | } |
85 | |||
86 | 33388 | jpiera | public static void registerPersistent() { |
87 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
88 | if( manager.getDefinition(PERSISTENCE_DEFINITION_NAME)==null ) { |
||
89 | DynStruct definition = manager.addDefinition( |
||
90 | Envelope2D.class, |
||
91 | PERSISTENCE_DEFINITION_NAME, |
||
92 | "Envelope2D persistence definition",
|
||
93 | null,
|
||
94 | null
|
||
95 | ); |
||
96 | |||
97 | definition.extend(manager.getDefinition(DefaultEnvelope.PERSISTENCE_DEFINITION_NAME)); |
||
98 | } |
||
99 | } |
||
100 | 27019 | jpiera | } |