svn-gvsig-desktop / tags / v1_0_2_Build_892 / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / core / util / UnitUtils.java @ 10278
History | View | Annotate | Download (4.39 KB)
1 | 6108 | azabala | /*
|
---|---|---|---|
2 | * Created on 29-jun-2006
|
||
3 | *
|
||
4 | * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
||
5 | *
|
||
6 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
7 | *
|
||
8 | * This program is free software; you can redistribute it and/or
|
||
9 | * modify it under the terms of the GNU General Public License
|
||
10 | * as published by the Free Software Foundation; either version 2
|
||
11 | * of the License, or (at your option) any later version.
|
||
12 | *
|
||
13 | * This program is distributed in the hope that it will be useful,
|
||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
16 | * GNU General Public License for more details.
|
||
17 | *
|
||
18 | * You should have received a copy of the GNU General Public License
|
||
19 | * along with this program; if not, write to the Free Software
|
||
20 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
21 | *
|
||
22 | * For more information, contact:
|
||
23 | *
|
||
24 | * Generalitat Valenciana
|
||
25 | * Conselleria d'Infraestructures i Transport
|
||
26 | * Av. Blasco Ib??ez, 50
|
||
27 | * 46010 VALENCIA
|
||
28 | * SPAIN
|
||
29 | *
|
||
30 | * +34 963862235
|
||
31 | * gvsig@gva.es
|
||
32 | * www.gvsig.gva.es
|
||
33 | *
|
||
34 | * or
|
||
35 | *
|
||
36 | * IVER T.I. S.A
|
||
37 | * Salamanca 50
|
||
38 | * 46005 Valencia
|
||
39 | * Spain
|
||
40 | *
|
||
41 | * +34 963163400
|
||
42 | * dac@iver.es
|
||
43 | */
|
||
44 | /* CVS MESSAGES:
|
||
45 | *
|
||
46 | * $Id$
|
||
47 | * $Log$
|
||
48 | 9711 | caballero | * Revision 1.3.2.4 2007-01-12 13:25:53 caballero
|
49 | * unidades de mapa y medida
|
||
50 | *
|
||
51 | * Revision 1.3.2.3 2006/12/22 10:15:07 caballero
|
||
52 | 9450 | caballero | * unidades de mapa y de medida
|
53 | *
|
||
54 | * Revision 1.3.2.2 2006/12/21 18:21:52 azabala
|
||
55 | 9425 | azabala | * Bug fixed: change getMapUnits for getDistanceUnits
|
56 | *
|
||
57 | * Revision 1.3.2.1 2006/11/15 00:08:17 jjdelcerro
|
||
58 | 8765 | jjdelcerro | * *** empty log message ***
|
59 | *
|
||
60 | * Revision 1.4 2006/09/15 10:42:54 caballero
|
||
61 | * extensibilidad de documentos
|
||
62 | *
|
||
63 | * Revision 1.3 2006/08/29 07:56:30 cesar
|
||
64 | 6880 | cesar | * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
65 | *
|
||
66 | * Revision 1.2 2006/08/29 07:21:09 cesar
|
||
67 | 6878 | cesar | * Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
|
68 | *
|
||
69 | * Revision 1.1 2006/06/29 17:30:36 azabala
|
||
70 | 6108 | azabala | * first version in cvs
|
71 | *
|
||
72 | *
|
||
73 | */
|
||
74 | package com.iver.cit.gvsig.geoprocess.core.util; |
||
75 | |||
76 | import org.cresques.cts.IProjection; |
||
77 | import org.cresques.cts.gt2.CSUTM; |
||
78 | |||
79 | import com.iver.andami.PluginServices; |
||
80 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
81 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.view.gui.View; |
82 | 6108 | azabala | |
83 | /**
|
||
84 | * Utility methods to manage distances
|
||
85 | * (conversion from user entries to internal units,
|
||
86 | 9450 | caballero | * verifying if projection is planar or we are
|
87 | 6108 | azabala | * working with geographic coordinates, etc.)
|
88 | * @author azabala
|
||
89 | *
|
||
90 | */
|
||
91 | public class UnitUtils { |
||
92 | 9450 | caballero | |
93 | 6108 | azabala | public static final double EARTH_RADIUS = 6378137d; |
94 | |||
95 | /**
|
||
96 | * For computing with geodetic coordinates:
|
||
97 | * returns the angular measure (in radians)
|
||
98 | 9450 | caballero | * for a distance over the earth along a
|
99 | 6108 | azabala | * meridiam.
|
100 | * Because this consideration is an approximation,
|
||
101 | * we consideer the eart like an sphere (not an
|
||
102 | * ellipsoid)
|
||
103 | * @param dist distance in meters
|
||
104 | * @return arc of meridian whose length is the specified
|
||
105 | * distance
|
||
106 | */
|
||
107 | public static double toSexaAngularMeasure(double dist){ |
||
108 | /*
|
||
109 | * dist = 6378km(terrestrial radius) -> 2PI
|
||
110 | * passed distance -> incognite
|
||
111 | */
|
||
112 | return Math.toDegrees((2 * Math.PI * dist)/EARTH_RADIUS); |
||
113 | } |
||
114 | 9450 | caballero | |
115 | |||
116 | 6108 | azabala | |
117 | 9425 | azabala | /**
|
118 | * Converts a distance entered by user in the GUI in the same distance
|
||
119 | * in internal units (measure units)
|
||
120 | *
|
||
121 | * */
|
||
122 | 6108 | azabala | public static double getInInternalUnits(double userEntryDistance){ |
123 | 9450 | caballero | // VCN he modificado esto a como creo que deber?a de estar, as? tiene en cuenta para calcular la distancia tanto las unidades
|
124 | //en las que se encuentra la cartograf?a como las unidades de medida seleccionadas por el usuario.
|
||
125 | int distanceUnits = ((View)PluginServices. |
||
126 | getMDIManager(). |
||
127 | getActiveWindow()).getMapControl().getViewPort().getDistanceUnits(); |
||
128 | 6108 | azabala | int mapUnits = ((View)PluginServices. |
129 | getMDIManager(). |
||
130 | 9450 | caballero | getActiveWindow()).getMapControl().getViewPort().getMapUnits(); |
131 | 9711 | caballero | double distInInternalUnits = (userEntryDistance/MapContext.CHANGEM[mapUnits]) * MapContext.CHANGEM[distanceUnits];
|
132 | 6108 | azabala | /*
|
133 | * if layer's projections is in geographics
|
||
134 | coords, pass distance to a angular measure
|
||
135 | */
|
||
136 | IProjection proj = ((View)PluginServices.
|
||
137 | getMDIManager(). |
||
138 | 6880 | cesar | getActiveWindow()). |
139 | 6108 | azabala | getMapControl(). |
140 | getViewPort(). |
||
141 | getProjection(); |
||
142 | if( (proj != null) && !(proj instanceof CSUTM)){ |
||
143 | distInInternalUnits = |
||
144 | 9450 | caballero | UnitUtils.toSexaAngularMeasure(distInInternalUnits); |
145 | 6108 | azabala | } |
146 | return distInInternalUnits;
|
||
147 | } |
||
148 | 9450 | caballero | |
149 | |||
150 | |||
151 | |||
152 | |||
153 | |||
154 | 6108 | azabala | } |