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 / cts / gt2 / CoordSys.java @ 42464
History | View | Annotate | Download (6.87 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40455 | jjdelcerro | *
|
4 | 40559 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40455 | jjdelcerro | *
|
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 | 40559 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40455 | jjdelcerro | * 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 | 40559 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40455 | jjdelcerro | *
|
21 | 40559 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40455 | jjdelcerro | */
|
24 | package org.cresques.impl.cts.gt2; |
||
25 | |||
26 | import java.awt.Color; |
||
27 | import java.awt.Graphics2D; |
||
28 | import java.awt.geom.Point2D; |
||
29 | import java.awt.geom.Rectangle2D; |
||
30 | |||
31 | import org.cresques.cts.ICoordTrans; |
||
32 | import org.cresques.cts.IDatum; |
||
33 | import org.cresques.cts.IProjection; |
||
34 | import org.cresques.geo.ViewPortData; |
||
35 | import org.geotools.cs.CoordinateSystem; |
||
36 | import org.geotools.cs.CoordinateSystemFactory; |
||
37 | import org.geotools.cs.GeographicCoordinateSystem; |
||
38 | import org.geotools.cs.ProjectedCoordinateSystem; |
||
39 | import org.opengis.referencing.FactoryException; |
||
40 | |||
41 | 42464 | fdiaz | import org.gvsig.fmap.crs.CRSFactory; |
42 | 40455 | jjdelcerro | |
43 | 42464 | fdiaz | |
44 | 40455 | jjdelcerro | /**
|
45 | * Sistema de Coordenadas (Proyecci?n).
|
||
46 | * @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
||
47 | */
|
||
48 | public class CoordSys implements IProjection { |
||
49 | private static final Color basicGridColor = new Color(64, 64, 64, 128); |
||
50 | protected CoordinateSystemFactory csFactory = CoordinateSystemFactory.getDefault();
|
||
51 | protected CSDatum datum = null; |
||
52 | protected GeographicCoordinateSystem geogCS = null; |
||
53 | protected ProjectedCoordinateSystem projCS = null; |
||
54 | protected String abrev = ""; |
||
55 | Color gridColor = basicGridColor;
|
||
56 | |||
57 | public CoordSys(CSDatum datum) {
|
||
58 | this.datum = datum;
|
||
59 | this.geogCS = new GeographicCoordinateSystem(datum.getName(null), datum.getDatum()); |
||
60 | } |
||
61 | |||
62 | public CoordSys(String wkt) { |
||
63 | try {
|
||
64 | //((GeographicCoordinateSystem)
|
||
65 | CoordinateSystem cs = CoordinateSystemFactory.getDefault().createFromWKT(wkt); |
||
66 | // ).getHorizontalDatum();
|
||
67 | if (cs instanceof GeographicCoordinateSystem) |
||
68 | geogCS = (GeographicCoordinateSystem) cs; |
||
69 | if (cs instanceof ProjectedCoordinateSystem) { |
||
70 | projCS = (ProjectedCoordinateSystem) cs; |
||
71 | geogCS = projCS.getGeographicCoordinateSystem(); |
||
72 | } |
||
73 | datum = new CSDatum(geogCS.getHorizontalDatum());
|
||
74 | } catch (FactoryException e) {
|
||
75 | // TODO Auto-generated catch block
|
||
76 | e.printStackTrace(); |
||
77 | } |
||
78 | } |
||
79 | |||
80 | /**
|
||
81 | * Crea un nuevo CoordSys geogr?fico a partir de uno proyectado.
|
||
82 | * Si el actual es geogr?fico retorna el mismo.
|
||
83 | * @return
|
||
84 | */
|
||
85 | public CoordSys toGeo() {
|
||
86 | CoordSys coordSys = new CoordSys((CSDatum) getDatum());
|
||
87 | |||
88 | if (geogCS != null) { |
||
89 | coordSys.geogCS = this.geogCS;
|
||
90 | } else {
|
||
91 | coordSys.geogCS = projCS.getGeographicCoordinateSystem(); |
||
92 | } |
||
93 | |||
94 | return coordSys;
|
||
95 | } |
||
96 | |||
97 | public IDatum getDatum() {
|
||
98 | return datum;
|
||
99 | } |
||
100 | |||
101 | public CoordinateSystem getCS() {
|
||
102 | if (projCS != null) { |
||
103 | return projCS;
|
||
104 | } |
||
105 | |||
106 | return geogCS;
|
||
107 | } |
||
108 | |||
109 | public CoordinateSystem getGeogCS() {
|
||
110 | if (geogCS != null) { |
||
111 | return geogCS;
|
||
112 | } |
||
113 | |||
114 | return projCS.getGeographicCoordinateSystem();
|
||
115 | } |
||
116 | |||
117 | /* (no Javadoc)
|
||
118 | * @see org.cresques.cts.IProjection#createPoint(double, double)
|
||
119 | */
|
||
120 | public Point2D createPoint(double x, double y) { |
||
121 | return new Point2D.Double(x, y); |
||
122 | } |
||
123 | |||
124 | public String toString() { |
||
125 | if (projCS != null) { |
||
126 | return projCS.toString();
|
||
127 | } |
||
128 | |||
129 | return geogCS.toString();
|
||
130 | } |
||
131 | |||
132 | public void setAbrev(String abrev) { |
||
133 | this.abrev = abrev;
|
||
134 | } |
||
135 | |||
136 | public String getAbrev() { |
||
137 | return abrev;
|
||
138 | } |
||
139 | |||
140 | /* (no Javadoc)
|
||
141 | * @see org.cresques.cts.IProjection#drawGrid(java.awt.Graphics2D, org.cresques.geo.ViewPortData)
|
||
142 | */
|
||
143 | public void drawGrid(Graphics2D g, ViewPortData vp) { |
||
144 | // TODO Ap?ndice de m?todo generado autom?ticamente
|
||
145 | } |
||
146 | |||
147 | public void setGridColor(Color c) { |
||
148 | gridColor = c; |
||
149 | } |
||
150 | |||
151 | public Color getGridColor() { |
||
152 | return gridColor;
|
||
153 | } |
||
154 | |||
155 | /* (no Javadoc)
|
||
156 | * @see org.cresques.cts.IProjection#toGeo(java.awt.geom.Point2D)
|
||
157 | */
|
||
158 | public Point2D toGeo(Point2D pt) { |
||
159 | //TODO VCN Esto si no lo comento no me trasforma el punto en coordenadas geogr?ficas.
|
||
160 | // if (getGeogCS() == geogCS) {
|
||
161 | // return pt;
|
||
162 | // } else {
|
||
163 | CoordTrans ct = new CoordTrans(this, toGeo()); |
||
164 | |||
165 | return ct.convert(pt, null); |
||
166 | // }
|
||
167 | } |
||
168 | |||
169 | /* (no Javadoc)
|
||
170 | * @see org.cresques.cts.IProjection#fromGeo(java.awt.geom.Point2D, java.awt.geom.Point2D)
|
||
171 | */
|
||
172 | public Point2D fromGeo(Point2D gPt, Point2D mPt) { |
||
173 | // TODO Ap?ndice de m?todo generado autom?ticamente
|
||
174 | return null; |
||
175 | } |
||
176 | |||
177 | public double getScale(double minX, double maxX, double w, double dpi) { |
||
178 | double scale = 0D; |
||
179 | |||
180 | if (projCS == null) { // Es geogr?fico; calcula la escala. |
||
181 | scale = ((maxX - minX) * // grados
|
||
182 | |||
183 | // 1852.0 metros x minuto de meridiano
|
||
184 | (dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro |
||
185 | w; // pixels
|
||
186 | } |
||
187 | |||
188 | return scale;
|
||
189 | } |
||
190 | public Rectangle2D getExtent(Rectangle2D extent,double scale,double wImage,double hImage,double mapUnits,double distanceUnits,double dpi) { |
||
191 | double w =0; |
||
192 | double h =0; |
||
193 | double wExtent =0; |
||
194 | double hExtent =0; |
||
195 | if (projCS!=null) { |
||
196 | w = ((wImage / dpi) * 2.54);
|
||
197 | h = ((hImage / dpi) * 2.54);
|
||
198 | wExtent =w * scale*distanceUnits/ mapUnits; |
||
199 | hExtent =h * scale*distanceUnits/ mapUnits; |
||
200 | |||
201 | }else {
|
||
202 | w = ((wImage / dpi) * 2.54);
|
||
203 | h = ((hImage / dpi) * 2.54);
|
||
204 | wExtent =(w*scale*distanceUnits)/ (mapUnits*1852.0*60.0); |
||
205 | hExtent =(h*scale*distanceUnits)/ (mapUnits*1852.0*60.0); |
||
206 | } |
||
207 | double xExtent = extent.getCenterX() - wExtent/2; |
||
208 | double yExtent = extent.getCenterY() - hExtent/2; |
||
209 | Rectangle2D rec=new Rectangle2D.Double(xExtent,yExtent,wExtent,hExtent); |
||
210 | return rec;
|
||
211 | } |
||
212 | public boolean isProjected() { |
||
213 | return projCS != null; |
||
214 | } |
||
215 | |||
216 | public ICoordTrans getCT(IProjection dest) {
|
||
217 | return new CoordTrans(this, (CoordSys) dest); |
||
218 | } |
||
219 | |||
220 | public String getFullCode() { |
||
221 | return getAbrev();
|
||
222 | } |
||
223 | 42464 | fdiaz | |
224 | 40455 | jjdelcerro | public Object clone() throws CloneNotSupportedException { |
225 | return CRSFactory.getCRS( this.getFullCode() ); |
||
226 | } |
||
227 | |||
228 | 42464 | fdiaz | /* (non-Javadoc)
|
229 | * @see org.cresques.cts.IProjection#export(java.lang.String)
|
||
230 | */
|
||
231 | @Override
|
||
232 | public String export(String format) { |
||
233 | // TODO Auto-generated method stub
|
||
234 | return null; |
||
235 | } |
||
236 | |||
237 | 40455 | jjdelcerro | } |