svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.impl / src / main / java / org / gvsig / fmap / geom / primitive / impl / Envelope2D.java @ 40559
History | View | Annotate | Download (3.25 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
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 3
|
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 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/*
|
25 |
* AUTHORS (In addition to CIT):
|
26 |
* 2009 {Iver T.I.} {Task}
|
27 |
*/
|
28 |
|
29 |
package org.gvsig.fmap.geom.primitive.impl; |
30 |
|
31 |
import java.awt.geom.Rectangle2D; |
32 |
|
33 |
import org.cresques.cts.ICoordTrans; |
34 |
import org.gvsig.fmap.geom.primitive.Envelope; |
35 |
import org.gvsig.fmap.geom.primitive.EnvelopeNotInitializedException; |
36 |
import org.gvsig.fmap.geom.primitive.Point; |
37 |
import org.gvsig.tools.ToolsLocator; |
38 |
import org.gvsig.tools.dynobject.DynStruct; |
39 |
import org.gvsig.tools.lang.Cloneable; |
40 |
import org.gvsig.tools.persistence.PersistenceManager; |
41 |
|
42 |
/**
|
43 |
* @author <a href="mailto:jpiera@gvsig.org">Jorge Piera</a>
|
44 |
*/
|
45 |
public class Envelope2D extends DefaultEnvelope implements Cloneable{ |
46 |
public static final String PERSISTENCE_DEFINITION_NAME = "Envelope2Dimensions"; |
47 |
|
48 |
public Envelope2D() {
|
49 |
super();
|
50 |
} |
51 |
|
52 |
public Envelope2D(Point min, Point max) { |
53 |
super(min, max);
|
54 |
} |
55 |
|
56 |
public Envelope2D(double minX,double minY,double maxX, double maxY){ |
57 |
this(new Point2D(minX, minY), new Point2D(maxX, maxY)); |
58 |
} |
59 |
|
60 |
/* (non-Javadoc)
|
61 |
* @see org.gvsig.fmap.geom.primitive.Envelope#getDimension()
|
62 |
*/
|
63 |
public int getDimension() { |
64 |
return 2; |
65 |
} |
66 |
|
67 |
/*
|
68 |
* (non-Javadoc)
|
69 |
* @see org.gvsig.fmap.geom.primitive.Envelope#convert(org.cresques.cts.ICoordTrans)
|
70 |
*/
|
71 |
public Envelope convert(ICoordTrans trans) {
|
72 |
if (isEmpty){
|
73 |
throw new EnvelopeNotInitializedException(); |
74 |
} |
75 |
if (this.getDimension() > 2) { |
76 |
return null; |
77 |
} |
78 |
Rectangle2D rect = new Rectangle2D.Double(this.getMinimum(0), this |
79 |
.getMinimum(1), this.getLength(0), this.getLength(1)); |
80 |
Rectangle2D rectDest = trans.convert(rect);
|
81 |
if (rectDest == null){ |
82 |
return null; |
83 |
} |
84 |
Point2D p1 = new Point2D(rectDest.getMinX(), rectDest.getMinY()); |
85 |
Point2D p2 = new Point2D(rectDest.getMaxX(), rectDest.getMaxY()); |
86 |
|
87 |
return new Envelope2D(p1, p2); |
88 |
} |
89 |
|
90 |
public static void registerPersistent() { |
91 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
92 |
if( manager.getDefinition(PERSISTENCE_DEFINITION_NAME)==null ) { |
93 |
DynStruct definition = manager.addDefinition( |
94 |
Envelope2D.class, |
95 |
PERSISTENCE_DEFINITION_NAME, |
96 |
"Envelope2D persistence definition",
|
97 |
null,
|
98 |
null
|
99 |
); |
100 |
|
101 |
definition.extend(manager.getDefinition(DefaultEnvelope.PERSISTENCE_DEFINITION_NAME)); |
102 |
} |
103 |
} |
104 |
|
105 |
public Object clone() throws CloneNotSupportedException { |
106 |
return super.clone(); |
107 |
} |
108 |
} |
109 |
|