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