Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.projection / org.gvsig.projection.cresques / org.gvsig.projection.cresques.impl / src / main / java / org / cresques / impl / geo / Projection.java @ 40559

History | View | Annotate | Download (4.49 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.cresques.impl.geo;
25

    
26
import org.cresques.cts.IDatum;
27
import org.cresques.cts.IProjection;
28
import org.cresques.geo.ViewPortData;
29
import org.gvsig.fmap.crs.CRSFactory;
30

    
31
import java.awt.Color;
32
import java.awt.Graphics2D;
33
import java.awt.geom.Point2D;
34

    
35

    
36
abstract public class Projection implements IProjection {
37
    public static int NORTH = 0;
38
    public static int SOUTH = 1;
39
    static String name = "Sin Proyeccion";
40
    static String abrev = "None";
41
    private static final Color basicGridColor = new Color(64, 64, 64, 128);
42
    Color gridColor = basicGridColor;
43
    Ellipsoid eli = Ellipsoid.hayford;
44
    Graticule grid;
45

    
46
    public Projection() {
47
        eli = Ellipsoid.hayford;
48
    }
49

    
50
    public Projection(Ellipsoid e) {
51
        eli = e;
52
    }
53

    
54
    public String getName() {
55
        return name;
56
    }
57

    
58
    abstract public String getAbrev();
59

    
60
    public IDatum getDatum() {
61
        return eli;
62
    }
63

    
64
    public double[] getElliPar() {
65
        return eli.getParam();
66
    }
67

    
68
    abstract public Point2D createPoint(double x, double y);
69

    
70
    public Point2D createPoint(Point2D pt) {
71
        return createPoint(pt.getX(), pt.getY());
72
    }
73

    
74
    public static IProjection getProjectionByName(IDatum eli, String name) {
75
        if (name.indexOf("UTM") >= 0) {
76
            return UtmZone.getProjectionByName(eli, name);
77
        }
78

    
79
        if (name.indexOf("GEO") >= 0) {
80
            return Geodetic.getProjectionByName(eli, name);
81
        }
82

    
83
        if (name.indexOf("MERC") >= 0) {
84
            return Mercator.getProjectionByName(eli, name);
85
        }
86

    
87
        return null;
88
    }
89

    
90
    public ReProjection getReproyectionTo(Projection proj) {
91
        ReProjection rp = new ReProjection(this, proj);
92

    
93
        return rp;
94
    }
95

    
96
    abstract public Point2D toGeo(Point2D pt);
97

    
98
    abstract public Point2D fromGeo(Point2D gPt, Point2D mPt);
99

    
100
    public void setGridColor(Color c) {
101
        gridColor = c;
102
    }
103

    
104
    public Color getGridColor() {
105
        return gridColor;
106
    }
107

    
108
    public static String coordToString(double coord, String fmt, boolean isLat) {
109
        String txt = fmt;
110
        int donde;
111
        donde = txt.indexOf("%G");
112

    
113
        if (donde >= 0) {
114
            int deg = (int) coord;
115

    
116
            if ((fmt.indexOf("%N") >= 0) && (deg < 0)) {
117
                deg = -deg;
118
            }
119

    
120
            txt = txt.substring(0, donde) + Integer.toString(deg) +
121
                  txt.substring(donde + 2);
122
        }
123

    
124
        donde = txt.indexOf("%M");
125

    
126
        if (donde >= 0) {
127
            int min = (int) ((coord - (int) coord) * 60.0) % 60;
128

    
129
            if ((fmt.indexOf("%N") >= 0) && (min < 0)) {
130
                min = -min;
131
            }
132

    
133
            txt = txt.substring(0, donde) + Integer.toString(min) +
134
                  txt.substring(donde + 2);
135
            ;
136
        }
137

    
138
        donde = txt.indexOf("%N");
139

    
140
        if (donde >= 0) {
141
            String t = "";
142

    
143
            if (isLat) {
144
                if (coord > 0) {
145
                    t = "N";
146
                } else if (coord < 0) {
147
                    t = "S";
148
                }
149
            } else {
150
                if (coord > 0) {
151
                    t = "E";
152
                } else if (coord < 0) {
153
                    t = "W";
154
                }
155
            }
156

    
157
            txt = txt.substring(0, donde) + t + txt.substring(donde + 2);
158
            ;
159
        }
160

    
161
        return txt;
162
    }
163

    
164
    abstract public void drawGrid(Graphics2D g, ViewPortData vp);
165
    
166
    public boolean isProjected() {
167
            return false;
168
    }
169
    
170
    public Object clone() throws CloneNotSupportedException {
171
        return CRSFactory.getCRS( this.getFullCode() );
172
     }
173

    
174
}