Statistics
| Revision:

svn-gvsig-desktop / tags / gvSIGv0_6_1RELEASE / libraries / libCq CMS for java.old / src / org / cresques / geo / Projection.java @ 5222

History | View | Annotate | Download (4.22 KB)

1 2809 nacho
/*
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 2 luisw
package org.cresques.geo;
25
26 2809 nacho
import org.cresques.cts.IDatum;
27
import org.cresques.cts.IProjection;
28
29 2 luisw
import java.awt.Color;
30
import java.awt.Graphics2D;
31
import java.awt.geom.Point2D;
32
33 92 luisw
34
abstract public class Projection implements IProjection {
35 2809 nacho
    public static int NORTH = 0;
36
    public static int SOUTH = 1;
37
    static String name = "Sin Proyeccion";
38
    static String abrev = "None";
39
    private static final Color basicGridColor = new Color(64, 64, 64, 128);
40
    Color gridColor = basicGridColor;
41
    Ellipsoid eli = Ellipsoid.hayford;
42
    Graticule grid;
43
44
    public Projection() {
45
        eli = Ellipsoid.hayford;
46
    }
47
48
    public Projection(Ellipsoid e) {
49
        eli = e;
50
    }
51
52
    public String getName() {
53
        return name;
54
    }
55
56
    abstract public String getAbrev();
57
58
    public IDatum getDatum() {
59
        return eli;
60
    }
61
62
    public double[] getElliPar() {
63
        return eli.getParam();
64
    }
65
66
    abstract public Point2D createPoint(double x, double y);
67
68
    public Point2D createPoint(Point2D pt) {
69
        return createPoint(pt.getX(), pt.getY());
70
    }
71
72
    public static IProjection getProjectionByName(IDatum eli, String name) {
73
        if (name.indexOf("UTM") >= 0) {
74
            return UtmZone.getProjectionByName(eli, name);
75
        }
76
77
        if (name.indexOf("GEO") >= 0) {
78
            return Geodetic.getProjectionByName(eli, name);
79
        }
80
81
        if (name.indexOf("MERC") >= 0) {
82
            return Mercator.getProjectionByName(eli, name);
83
        }
84
85
        return null;
86
    }
87
88
    public ReProjection getReproyectionTo(Projection proj) {
89
        ReProjection rp = new ReProjection(this, proj);
90
91
        return rp;
92
    }
93
94
    abstract public Point2D toGeo(Point2D pt);
95
96
    abstract public Point2D fromGeo(Point2D gPt, Point2D mPt);
97
98
    public void setGridColor(Color c) {
99
        gridColor = c;
100
    }
101
102
    public Color getGridColor() {
103
        return gridColor;
104
    }
105
106
    public static String coordToString(double coord, String fmt, boolean isLat) {
107
        String txt = fmt;
108
        int donde;
109
        donde = txt.indexOf("%G");
110
111
        if (donde >= 0) {
112
            int deg = (int) coord;
113
114
            if ((fmt.indexOf("%N") >= 0) && (deg < 0)) {
115
                deg = -deg;
116
            }
117
118
            txt = txt.substring(0, donde) + Integer.toString(deg) +
119
                  txt.substring(donde + 2);
120
        }
121
122
        donde = txt.indexOf("%M");
123
124
        if (donde >= 0) {
125
            int min = (int) ((coord - (int) coord) * 60.0) % 60;
126
127
            if ((fmt.indexOf("%N") >= 0) && (min < 0)) {
128
                min = -min;
129
            }
130
131
            txt = txt.substring(0, donde) + Integer.toString(min) +
132
                  txt.substring(donde + 2);
133
            ;
134
        }
135
136
        donde = txt.indexOf("%N");
137
138
        if (donde >= 0) {
139
            String t = "";
140
141
            if (isLat) {
142
                if (coord > 0) {
143
                    t = "N";
144
                } else if (coord < 0) {
145
                    t = "S";
146
                }
147
            } else {
148
                if (coord > 0) {
149
                    t = "E";
150
                } else if (coord < 0) {
151
                    t = "W";
152
                }
153
            }
154
155
            txt = txt.substring(0, donde) + t + txt.substring(donde + 2);
156
            ;
157
        }
158
159
        return txt;
160
    }
161
162
    abstract public void drawGrid(Graphics2D g, ViewPortData vp);
163 4462 luisw2
164
    public boolean isProjected() {
165
            return false;
166
    }
167 2 luisw
}