Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / cts / gt2 / CoordSys.java @ 8026

History | View | Annotate | Download (4.8 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.ICoordTrans;
31
import org.cresques.cts.IDatum;
32
import org.cresques.cts.IProjection;
33
import org.cresques.cts.ProjectionPool;
34
import org.cresques.geo.ViewPortData;
35
import org.geotools.cs.CoordinateSystem;
36
import org.geotools.cs.CoordinateSystemFactory;
37
import org.geotools.cs.GeographicCoordinateSystem;
38
import org.geotools.cs.ProjectedCoordinateSystem;
39

    
40

    
41
/**
42
 * Sistema de Coordenadas (Proyecci?n).
43
 * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
44
 */
45
public class CoordSys implements IProjection {
46
    private static final Color basicGridColor = new Color(64, 64, 64, 128);
47
    protected CoordinateSystemFactory csFactory = CoordinateSystemFactory.getDefault();
48
    protected CSDatum datum = null;
49
    protected GeographicCoordinateSystem geogCS = null;
50
    protected ProjectedCoordinateSystem projCS = null;
51
    protected String abrev = "";
52
    Color gridColor = basicGridColor;
53

    
54
    public CoordSys(CSDatum datum) {
55
        this.datum = datum;
56
    }
57

    
58
    /**
59
     * Crea un nuevo CoordSys geogr?fico a partir de uno proyectado.
60
     * Si el actual es geogr?fico retorna el mismo.
61
     * @return
62
     */
63
    public CoordSys toGeo() {
64
        CoordSys coordSys = new CoordSys((CSDatum) getDatum());
65

    
66
        if (geogCS != null) {
67
            coordSys.geogCS = this.geogCS;
68
        } else {
69
            coordSys.geogCS = projCS.getGeographicCoordinateSystem();
70
        }
71

    
72
        return coordSys;
73
    }
74

    
75
    public IDatum getDatum() {
76
        return datum;
77
    }
78

    
79
    public CoordinateSystem getCS() {
80
        if (projCS != null) {
81
            return projCS;
82
        }
83

    
84
        return geogCS;
85
    }
86

    
87
    public CoordinateSystem getGeogCS() {
88
        if (geogCS != null) {
89
            return geogCS;
90
        }
91

    
92
        return projCS.getGeographicCoordinateSystem();
93
    }
94

    
95
    /* (no Javadoc)
96
     * @see org.cresques.cts.IProjection#createPoint(double, double)
97
     */
98
    public Point2D createPoint(double x, double y) {
99
        return new Point2D.Double(x, y);
100
    }
101

    
102
    public String toString() {
103
        if (projCS != null) {
104
            return projCS.toString();
105
        }
106

    
107
        return geogCS.toString();
108
    }
109

    
110
    public void setAbrev(String abrev) {
111
        this.abrev = abrev;
112
    }
113

    
114
    public String getAbrev() {
115
        return abrev;
116
    }
117

    
118
    /* (no Javadoc)
119
     * @see org.cresques.cts.IProjection#drawGrid(java.awt.Graphics2D, org.cresques.geo.ViewPortData)
120
     */
121
    public void drawGrid(Graphics2D g, ViewPortData vp) {
122
        // TODO Ap?ndice de m?todo generado autom?ticamente
123
    }
124

    
125
    public void setGridColor(Color c) {
126
        gridColor = c;
127
    }
128

    
129
    public Color getGridColor() {
130
        return gridColor;
131
    }
132

    
133
    /* (no Javadoc)
134
     * @see org.cresques.cts.IProjection#toGeo(java.awt.geom.Point2D)
135
     */
136
    public Point2D toGeo(Point2D pt) {
137
        if (getGeogCS() == geogCS) {
138
            return pt;
139
        } else {
140
            CoordTrans ct = new CoordTrans(this, toGeo());
141

    
142
            return ct.convert(pt, null);
143
        }
144
    }
145

    
146
    /* (no Javadoc)
147
     * @see org.cresques.cts.IProjection#fromGeo(java.awt.geom.Point2D, java.awt.geom.Point2D)
148
     */
149
    public Point2D fromGeo(Point2D gPt, Point2D mPt) {
150
        // TODO Ap?ndice de m?todo generado autom?ticamente
151
        return null;
152
    }
153

    
154
    public double getScale(double minX, double maxX, double w, double dpi) {
155
        double scale = 0D;
156

    
157
        if (projCS == null) { // Es geogr?fico; calcula la escala.
158
            scale = ((maxX - minX) * // grados
159
                    
160
            // 1852.0 metros x minuto de meridiano
161
            (dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro
162
                    w; // pixels
163
        }
164

    
165
        return scale;
166
    }
167
    
168
    public boolean isProjected() {
169
            return projCS != null;
170
    }
171

    
172
        public ICoordTrans getCT(IProjection dest) {
173
                // TODO Auto-generated method stub
174
                return new CoordTrans(this, (CoordSys) dest);
175
        }
176
}