root / trunk / libraries / libCq_CMS_praster / src / org / cresques / geo / ReProjection.java @ 8026
History | View | Annotate | Download (3.71 KB)
1 |
/*
|
---|---|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
|
3 |
*
|
4 |
* Copyright (C) 2004-5.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* cresques@gmail.com
|
23 |
*/
|
24 |
package org.cresques.geo; |
25 |
|
26 |
import org.cresques.cts.ICoordTrans; |
27 |
import org.cresques.cts.IProjection; |
28 |
|
29 |
import java.awt.geom.Point2D; |
30 |
import java.awt.geom.Rectangle2D; |
31 |
|
32 |
|
33 |
/**
|
34 |
* Transformada para cambios de proyecci?n
|
35 |
*
|
36 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
37 |
*/
|
38 |
public class ReProjection implements ICoordTrans { |
39 |
Projection pOrig; |
40 |
Projection pDest; |
41 |
|
42 |
public ReProjection(Projection pOrig, Projection pDest) {
|
43 |
this.pOrig = pOrig;
|
44 |
this.pDest = pDest;
|
45 |
} |
46 |
|
47 |
public ICoordTrans getInverted() {
|
48 |
return new ReProjection(pDest, pOrig); |
49 |
} |
50 |
|
51 |
public IProjection getPOrig() {
|
52 |
return pOrig;
|
53 |
} |
54 |
|
55 |
public IProjection getPDest() {
|
56 |
return pDest;
|
57 |
} |
58 |
|
59 |
public Point2D convert(Point2D ptOrig, Point2D ptDest) { |
60 |
if (pOrig.getClass() == UtmZone.class) {
|
61 |
GeoPoint pt1 = null;
|
62 |
pt1 = (GeoPoint) ((UtmZone) pOrig).toGeo((UtmPoint) ptOrig); |
63 |
|
64 |
if (pDest.getClass() == UtmZone.class) {
|
65 |
((UtmZone) pDest).fromGeo(pt1, (UtmPoint) ptDest, |
66 |
(UtmZone) pDest); |
67 |
} else if (pDest.getClass() == Geodetic.class) { |
68 |
ptDest.setLocation(pt1.getX(), pt1.getY()); |
69 |
((GeoPoint) ptDest).proj = pt1.proj; |
70 |
} else if (pDest.getClass() == Mercator.class) { |
71 |
((Mercator) pDest).fromGeo(pt1, (ProjPoint) ptDest); |
72 |
} |
73 |
} else if (pOrig.getClass() == Geodetic.class) { |
74 |
if (pDest.getClass() == UtmZone.class) {
|
75 |
((UtmZone) pDest).fromGeo((GeoPoint) ptOrig, (UtmPoint) ptDest, |
76 |
(UtmZone) pDest); |
77 |
} else if (pDest.getClass() == Mercator.class) { |
78 |
((Mercator) pDest).fromGeo((GeoPoint) ptOrig, (ProjPoint) ptDest); |
79 |
} |
80 |
} else if (pOrig.getClass() == Mercator.class) { |
81 |
GeoPoint pt1 = null;
|
82 |
pt1 = (GeoPoint) ((Mercator) pOrig).toGeo((ProjPoint) ptOrig); |
83 |
|
84 |
if (pDest.getClass() == UtmZone.class) {
|
85 |
((UtmZone) pDest).fromGeo(pt1, (UtmPoint) ptDest, |
86 |
(UtmZone) pDest); |
87 |
} else if (pDest.getClass() == Geodetic.class) { |
88 |
ptDest.setLocation(pt1.getX(), pt1.getY()); |
89 |
((ProjPoint) ptDest).proj = pt1.proj; |
90 |
} |
91 |
} |
92 |
|
93 |
return ptDest;
|
94 |
} |
95 |
|
96 |
/* (non-Javadoc)
|
97 |
* @see org.cresques.cts.ICoordTrans#convert(java.awt.geom.Rectangle2D)
|
98 |
*/
|
99 |
public Rectangle2D convert(Rectangle2D rect) { |
100 |
Point2D pt1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); |
101 |
Point2D pt2 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); |
102 |
pt1 = convert(pt1, null);
|
103 |
pt2 = convert(pt2, null);
|
104 |
rect = new Rectangle2D.Double(); |
105 |
rect.setFrameFromDiagonal(pt1, pt2); |
106 |
|
107 |
return rect;
|
108 |
} |
109 |
} |