Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / geo / ReProjection.java @ 2312

History | View | Annotate | Download (3.19 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 java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28

    
29
import org.cresques.cts.ICoordTrans;
30
import org.cresques.cts.IProjection;
31

    
32
/**
33
 * Transformada para cambios de proyecci?n
34
 * 
35
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
36
 */
37
public class ReProjection implements ICoordTrans {
38
        Projection pOrig, pDest;
39
        
40
        public ReProjection(Projection pOrig, Projection pDest) {
41
                this.pOrig = pOrig;
42
                this.pDest = pDest;
43
        }
44
        
45
        public ICoordTrans getInverted() {
46
                return new ReProjection(pDest, pOrig);
47
        }
48
        
49
        public IProjection getPOrig() { return pOrig; }
50
        public IProjection getPDest() { return pDest; }
51
        
52
        public Point2D convert(Point2D ptOrig, Point2D ptDest) {
53
                if (pOrig.getClass() == UtmZone.class) {
54
                        GeoPoint pt1 = null;
55
                        pt1 = (GeoPoint) ((UtmZone) pOrig).toGeo((UtmPoint) ptOrig);
56
                        if (pDest.getClass() == UtmZone.class) {
57
                                ((UtmZone) pDest).fromGeo(pt1, (UtmPoint) ptDest, (UtmZone) pDest);
58
                        } else if (pDest.getClass() == Geodetic.class) {
59
                                ptDest.setLocation(pt1.getX(), pt1.getY());
60
                                ((GeoPoint) ptDest).proj = pt1.proj;
61
                        } else if (pDest.getClass() == Mercator.class) {
62
                                ((Mercator) pDest).fromGeo(pt1, (ProjPoint) ptDest);
63
                        }
64
                } else if (pOrig.getClass() == Geodetic.class) {
65
                        if (pDest.getClass() == UtmZone.class) {
66
                                ((UtmZone) pDest).fromGeo((GeoPoint) ptOrig, (UtmPoint) ptDest, (UtmZone) pDest);
67
                        } else if (pDest.getClass() == Mercator.class) {
68
                                ((Mercator) pDest).fromGeo((GeoPoint) ptOrig, (ProjPoint) ptDest);
69
                        }
70
                } else if (pOrig.getClass() == Mercator.class) {
71
                        GeoPoint pt1 = null;
72
                        pt1 = (GeoPoint) ((Mercator) pOrig).toGeo((ProjPoint) ptOrig);
73
                        if (pDest.getClass() == UtmZone.class) {
74
                                ((UtmZone) pDest).fromGeo(pt1, (UtmPoint) ptDest, (UtmZone) pDest);
75
                        } else if (pDest.getClass() == Geodetic.class) {
76
                                ptDest.setLocation(pt1.getX(), pt1.getY());
77
                                ((ProjPoint) ptDest).proj = pt1.proj;
78
                        }
79
                }
80
                return ptDest;
81
        }
82

    
83
        /* (non-Javadoc)
84
         * @see org.cresques.cts.ICoordTrans#convert(java.awt.geom.Rectangle2D)
85
         */
86
        public Rectangle2D convert(Rectangle2D rect) {
87
                Point2D pt1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); 
88
                Point2D pt2 = new Point2D.Double(rect.getMaxX(), rect.getMaxY());
89
                pt1 = convert(pt1, null);
90
                pt2 = convert(pt2, null);
91
                rect = new Rectangle2D.Double();
92
                rect.setFrameFromDiagonal(pt1, pt2);
93
                return rect;
94
        }
95
}