Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/cts/gt2/CoordSys.java
CoordSys.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.cts.gt2; |
25 | 25 |
|
26 |
import java.awt.Color; |
|
27 |
import java.awt.Graphics2D; |
|
28 |
import java.awt.geom.Point2D; |
|
29 |
|
|
30 | 26 |
import org.cresques.cts.IDatum; |
31 | 27 |
import org.cresques.cts.IProjection; |
28 |
|
|
32 | 29 |
import org.cresques.geo.ViewPortData; |
30 |
|
|
33 | 31 |
import org.geotools.cs.CoordinateSystem; |
34 | 32 |
import org.geotools.cs.CoordinateSystemFactory; |
35 | 33 |
import org.geotools.cs.GeographicCoordinateSystem; |
36 | 34 |
import org.geotools.cs.ProjectedCoordinateSystem; |
37 | 35 |
|
36 |
import java.awt.Color; |
|
37 |
import java.awt.Graphics2D; |
|
38 |
import java.awt.geom.Point2D; |
|
39 |
|
|
40 |
|
|
38 | 41 |
/** |
39 | 42 |
* Sistema de Coordenadas (Proyecci?n). |
40 | 43 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es> |
41 | 44 |
*/ |
42 | 45 |
public class CoordSys implements IProjection { |
43 |
protected CoordinateSystemFactory csFactory = CoordinateSystemFactory.getDefault(); |
|
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; |
|
44 | 53 |
|
45 |
protected CSDatum datum = null; |
|
46 |
protected GeographicCoordinateSystem geogCS = null; |
|
47 |
protected ProjectedCoordinateSystem projCS = null; |
|
48 |
protected String abrev = ""; |
|
49 |
|
|
50 |
private static final Color basicGridColor = new Color(64,64,64,128); |
|
51 |
Color gridColor = basicGridColor; |
|
54 |
public CoordSys(CSDatum datum) { |
|
55 |
this.datum = datum; |
|
56 |
} |
|
52 | 57 |
|
53 |
public CoordSys(CSDatum datum) { |
|
54 |
this.datum = datum; |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* Crea un nuevo CoordSys geogr?fico a partir de uno proyectado. |
|
59 |
* Si el actual es geogr?fico retorna el mismo. |
|
60 |
* @return |
|
61 |
*/ |
|
62 |
|
|
63 |
public CoordSys toGeo() { |
|
64 |
CoordSys coordSys = new CoordSys((CSDatum)getDatum()); |
|
65 |
if (geogCS != null) |
|
66 |
coordSys.geogCS = this.geogCS; |
|
67 |
else |
|
68 |
coordSys.geogCS = projCS.getGeographicCoordinateSystem(); |
|
69 |
|
|
70 |
return coordSys; |
|
71 |
} |
|
72 |
|
|
73 |
public IDatum getDatum() { |
|
74 |
return datum; |
|
75 |
} |
|
76 |
|
|
77 |
public CoordinateSystem getCS() { |
|
78 |
if (projCS != null) return projCS; |
|
79 |
return geogCS; |
|
80 |
} |
|
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()); |
|
81 | 65 |
|
82 |
public CoordinateSystem getGeogCS() { |
|
83 |
if (geogCS != null) return geogCS; |
|
84 |
return projCS.getGeographicCoordinateSystem(); |
|
85 |
} |
|
86 |
|
|
87 |
/* (no Javadoc) |
|
88 |
* @see org.cresques.cts.IProjection#createPoint(double, double) |
|
89 |
*/ |
|
90 |
public Point2D createPoint(double x, double y) { |
|
91 |
return new Point2D.Double(x,y); |
|
92 |
} |
|
93 |
|
|
94 |
|
|
95 |
public String toString() { |
|
96 |
if (projCS != null) return projCS.toString(); |
|
97 |
return geogCS.toString(); |
|
98 |
} |
|
66 |
if (geogCS != null) { |
|
67 |
coordSys.geogCS = this.geogCS; |
|
68 |
} else { |
|
69 |
coordSys.geogCS = projCS.getGeographicCoordinateSystem(); |
|
70 |
} |
|
99 | 71 |
|
100 |
public void setAbrev(String abrev) { this.abrev = abrev; }
|
|
101 |
public String getAbrev() { return abrev; }
|
|
72 |
return coordSys;
|
|
73 |
}
|
|
102 | 74 |
|
103 |
/* (no Javadoc) |
|
104 |
* @see org.cresques.cts.IProjection#drawGrid(java.awt.Graphics2D, org.cresques.geo.ViewPortData) |
|
105 |
*/ |
|
106 |
public void drawGrid(Graphics2D g, ViewPortData vp) { |
|
107 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
108 |
|
|
109 |
} |
|
110 |
|
|
111 |
public void setGridColor(Color c) { gridColor = c;} |
|
112 |
public Color getGridColor() { return gridColor; } |
|
75 |
public IDatum getDatum() { |
|
76 |
return datum; |
|
77 |
} |
|
113 | 78 |
|
114 |
/* (no Javadoc) |
|
115 |
* @see org.cresques.cts.IProjection#toGeo(java.awt.geom.Point2D) |
|
116 |
*/ |
|
117 |
public Point2D toGeo(Point2D pt) { |
|
118 |
if (getGeogCS() == geogCS) return pt; |
|
119 |
else { |
|
120 |
CoordTrans ct = new CoordTrans(this, toGeo()); |
|
121 |
return ct.convert(pt, null); |
|
122 |
} |
|
123 |
} |
|
79 |
public CoordinateSystem getCS() { |
|
80 |
if (projCS != null) { |
|
81 |
return projCS; |
|
82 |
} |
|
124 | 83 |
|
125 |
/* (no Javadoc) |
|
126 |
* @see org.cresques.cts.IProjection#fromGeo(java.awt.geom.Point2D, java.awt.geom.Point2D) |
|
127 |
*/ |
|
128 |
public Point2D fromGeo(Point2D gPt, Point2D mPt) { |
|
129 |
// TODO Ap?ndice de m?todo generado autom?ticamente |
|
130 |
return null; |
|
131 |
} |
|
132 |
|
|
133 |
public double getScale(double minX, double maxX, double w, double dpi) { |
|
134 |
double scale = 0D; |
|
135 |
if (projCS == null) { // Es geogr?fico; calcula la escala. |
|
136 |
scale = (maxX - minX)* // grados |
|
137 |
// 1852.0 metros x minuto de meridiano |
|
138 |
(dpi / 2.54 * 100.0 * 1852.0 * 60.0)/ // px / metro |
|
139 |
w; // pixels |
|
140 |
} |
|
141 |
return scale; |
|
142 |
} |
|
84 |
return geogCS; |
|
85 |
} |
|
143 | 86 |
|
87 |
public CoordinateSystem getGeogCS() { |
|
88 |
if (geogCS != null) { |
|
89 |
return geogCS; |
|
90 |
} |
|
144 | 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 |
} |
|
145 | 167 |
} |
Also available in: Unified diff