svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.projection / org.gvsig.projection.cresques / org.gvsig.projection.cresques.impl / src / main / java / org / cresques / impl / geo / ReProjection.java @ 40559
History | View | Annotate | Download (4.46 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40455 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40455 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40455 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40455 | jjdelcerro | *
|
21 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40455 | jjdelcerro | */
|
24 | package org.cresques.impl.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 | |||
101 | Point2D pt1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); |
||
102 | Point2D pt2 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); |
||
103 | Point2D pt3 = new Point2D.Double(rect.getMinX(), rect.getMaxY()); |
||
104 | Point2D pt4 = new Point2D.Double(rect.getMaxX(), rect.getMinY()); |
||
105 | |||
106 | convert(pt1, pt1); |
||
107 | convert(pt2, pt2); |
||
108 | convert(pt3, pt3); |
||
109 | convert(pt4, pt4); |
||
110 | |||
111 | double min_x = Math.min( |
||
112 | Math.min(pt1.getX(), pt2.getX()),
|
||
113 | Math.min(pt3.getX(), pt4.getX()));
|
||
114 | double min_y = Math.min( |
||
115 | Math.min(pt1.getY(), pt2.getY()),
|
||
116 | Math.min(pt3.getY(), pt4.getY()));
|
||
117 | double max_x = Math.max( |
||
118 | Math.max(pt1.getX(), pt2.getX()),
|
||
119 | Math.max(pt3.getX(), pt4.getX()));
|
||
120 | double max_y = Math.max( |
||
121 | Math.max(pt1.getY(), pt2.getY()),
|
||
122 | Math.max(pt3.getY(), pt4.getY()));
|
||
123 | |||
124 | return new Rectangle2D.Double( |
||
125 | min_x, min_y, max_x - min_x, max_y - min_y); |
||
126 | } |
||
127 | } |