Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / cts / gt2 / CoordSys.java @ 2312

History | View | Annotate | Download (4.01 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.cts.gt2;
25

    
26
import java.awt.Color;
27
import java.awt.Graphics2D;
28
import java.awt.geom.Point2D;
29

    
30
import org.cresques.cts.IDatum;
31
import org.cresques.cts.IProjection;
32
import org.cresques.geo.ViewPortData;
33
import org.geotools.cs.CoordinateSystem;
34
import org.geotools.cs.CoordinateSystemFactory;
35
import org.geotools.cs.GeographicCoordinateSystem;
36
import org.geotools.cs.ProjectedCoordinateSystem;
37

    
38
/**
39
 * Sistema de Coordenadas (Proyecci?n).
40
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
41
 */
42
public class CoordSys implements IProjection {
43
        protected CoordinateSystemFactory csFactory = CoordinateSystemFactory.getDefault();
44

    
45
        protected CSDatum datum = null;
46
        protected GeographicCoordinateSystem geogCS = null;
47
        protected ProjectedCoordinateSystem projCS = null;
48
        protected String abrev = "";
49
        
50
        private static final Color basicGridColor = new Color(64,64,64,128);
51
        Color gridColor = basicGridColor;
52

    
53
        public CoordSys(CSDatum datum) {
54
                this.datum = datum;
55
        }
56
        
57
        /**
58
         * Crea un nuevo CoordSys geogr?fico a partir de uno proyectado.
59
         * Si el actual es geogr?fico retorna el mismo.
60
         * @return
61
         */
62
        
63
        public CoordSys toGeo() {
64
                CoordSys coordSys = new CoordSys((CSDatum)getDatum());
65
                if (geogCS != null)
66
                        coordSys.geogCS = this.geogCS;
67
                else
68
                        coordSys.geogCS = projCS.getGeographicCoordinateSystem();
69
                
70
                return coordSys;
71
        }
72
        
73
        public IDatum getDatum() {
74
                return datum;
75
        }
76
        
77
        public CoordinateSystem getCS() {
78
                if (projCS != null) return projCS;
79
                return geogCS;
80
        }
81

    
82
        public CoordinateSystem getGeogCS() {
83
                if (geogCS != null) return geogCS;
84
                return projCS.getGeographicCoordinateSystem();
85
        }
86
        
87
        /* (no Javadoc)
88
         * @see org.cresques.cts.IProjection#createPoint(double, double)
89
         */
90
        public Point2D createPoint(double x, double y) {
91
                return new Point2D.Double(x,y);
92
        }
93
        
94
        
95
        public String toString() {
96
                if (projCS != null) return projCS.toString();
97
                return geogCS.toString();
98
        }
99

    
100
        public void setAbrev(String abrev) { this.abrev = abrev; }
101
        public String getAbrev() {         return abrev; }
102

    
103
        /* (no Javadoc)
104
         * @see org.cresques.cts.IProjection#drawGrid(java.awt.Graphics2D, org.cresques.geo.ViewPortData)
105
         */
106
        public void drawGrid(Graphics2D g, ViewPortData vp) {
107
                // TODO Ap?ndice de m?todo generado autom?ticamente
108
                
109
        }
110
        
111
        public void setGridColor(Color c) { gridColor = c;}
112
        public Color getGridColor() { return gridColor;        }
113

    
114
        /* (no Javadoc)
115
         * @see org.cresques.cts.IProjection#toGeo(java.awt.geom.Point2D)
116
         */
117
        public Point2D toGeo(Point2D pt) {
118
                if (getGeogCS() == geogCS) return pt;
119
                else {
120
                        CoordTrans ct = new CoordTrans(this, toGeo());
121
                        return ct.convert(pt, null);
122
                }
123
        }
124

    
125
        /* (no Javadoc)
126
         * @see org.cresques.cts.IProjection#fromGeo(java.awt.geom.Point2D, java.awt.geom.Point2D)
127
         */
128
        public Point2D fromGeo(Point2D gPt, Point2D mPt) {
129
                // TODO Ap?ndice de m?todo generado autom?ticamente
130
                return null;
131
        }
132
        
133
        public double getScale(double minX, double maxX, double w, double dpi) {
134
                double scale = 0D;
135
                if (projCS == null) { // Es geogr?fico; calcula la escala.
136
                        scale = (maxX - minX)*                // grados
137
                        // 1852.0 metros x minuto de meridiano
138
                        (dpi / 2.54 * 100.0 * 1852.0 * 60.0)/        // px / metro
139
                        w;                                                                                // pixels
140
                }
141
                return scale;
142
        }
143

    
144

    
145
}