Statistics
| Revision:

svn-gvsig-desktop / tags / gvSIGv0_6_1RELEASE / libraries / libCq CMS for java.old / src / org / cresques / cts / gt2 / CoordSys.java @ 5222

History | View | Annotate | Download (4.52 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 org.cresques.cts.IDatum;
27
import org.cresques.cts.IProjection;
28

    
29
import org.cresques.geo.ViewPortData;
30

    
31
import org.geotools.cs.CoordinateSystem;
32
import org.geotools.cs.CoordinateSystemFactory;
33
import org.geotools.cs.GeographicCoordinateSystem;
34
import org.geotools.cs.ProjectedCoordinateSystem;
35

    
36
import java.awt.Color;
37
import java.awt.Graphics2D;
38
import java.awt.geom.Point2D;
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 (isProjected()) {
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
        return getCS().toString();
104
    }
105

    
106
    public void setAbrev(String abrev) {
107
        this.abrev = abrev;
108
    }
109

    
110
    public String getAbrev() {
111
        return abrev;
112
    }
113

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

    
121
    public void setGridColor(Color c) {
122
        gridColor = c;
123
    }
124

    
125
    public Color getGridColor() {
126
        return gridColor;
127
    }
128

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

    
138
            return ct.convert(pt, null);
139
        }
140
    }
141

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

    
150
    public double getScale(double minX, double maxX, double w, double dpi) {
151
        double scale = 0D;
152

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

    
161
        return scale;
162
    }
163
    
164
    public boolean isProjected() {
165
            return projCS != null;
166
    }
167
}