gvsig-geoprocess / org.gvsig.geoprocess / trunk / org.gvsig.geoprocess / org.gvsig.geoprocess.algorithm / org.gvsig.geoprocess.algorithm.buffer / src / main / java / org / gvsig / geoprocess / algorithm / buffer / AbstractDistance.java @ 467
History | View | Annotate | Download (3.55 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2012 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 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., 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.gvsig.geoprocess.algorithm.buffer; |
25 |
|
26 |
import org.cresques.cts.IProjection; |
27 |
import org.gvsig.fmap.dal.feature.Feature; |
28 |
import org.gvsig.fmap.mapcontext.MapContext; |
29 |
|
30 |
/**
|
31 |
* Abstract distance implementation.
|
32 |
*
|
33 |
* @author gvSIG Team
|
34 |
* @version $Id$
|
35 |
*/
|
36 |
public abstract class AbstractDistance implements IDistance { |
37 |
|
38 |
public static final double EARTH_RADIUS = 6378137d; |
39 |
protected int numberOfRings = 1; |
40 |
protected Feature feature = null; |
41 |
|
42 |
public void setFeature(Feature feature) { |
43 |
this.feature = feature;
|
44 |
} |
45 |
|
46 |
/**
|
47 |
* For computing with geodetic coordinates:
|
48 |
* returns the angular measure (in radians)
|
49 |
* for a distance over the earth along a
|
50 |
* meridiam.
|
51 |
* Because this consideration is an approximation,
|
52 |
* we consideer the eart like an sphere (not an
|
53 |
* ellipsoid)
|
54 |
*
|
55 |
* @param dist
|
56 |
* distance in meters
|
57 |
* @return arc of meridian whose length is the specified
|
58 |
* distance
|
59 |
*/
|
60 |
private double toSexaAngularMeasure(double dist) { |
61 |
/*
|
62 |
* dist = 6378km(terrestrial radius) -> 2PI
|
63 |
* passed distance -> incognite
|
64 |
*/
|
65 |
return Math.toDegrees((2 * Math.PI * dist) / EARTH_RADIUS); |
66 |
} |
67 |
|
68 |
/**
|
69 |
* Converts a distance entered by user in the GUI in the same distance
|
70 |
* in internal units (measure units)
|
71 |
*/
|
72 |
protected double getInInternalUnits(double userEntryDistance, |
73 |
IProjection proj, int distanceUnits, int mapUnits) { |
74 |
|
75 |
/* double[] trans2Meter = MapContext.getDistanceTrans2Meter();
|
76 |
double distInInternalUnits =
|
77 |
(userEntryDistance / trans2Meter[mapUnits])
|
78 |
* trans2Meter[distanceUnits];
|
79 |
|
80 |
if ((proj != null) && !(proj.isProjected()))
|
81 |
distInInternalUnits = toSexaAngularMeasure(distInInternalUnits);
|
82 |
|
83 |
return distInInternalUnits;*/
|
84 |
|
85 |
/*
|
86 |
* En caso de que el sistema de referencia sea proyectado se usa la distancia
|
87 |
* que el usuario ha definido, ya que esta se supone en metros. En caso de que
|
88 |
* las coordenadas sean en geogr?ficas se toma la distancia que el usuario ha
|
89 |
* definido en metros en el ecuador. Esto supone una desviaci?n a medida que
|
90 |
* nos alejamos del ecuador. Una posible soluci?n ser?a obtener esa distancia
|
91 |
* para la posici?n en el planeta en la que se encuentra la cartograf?a en la
|
92 |
* proyecci?n en la que est? definida.
|
93 |
*/
|
94 |
|
95 |
if ((proj != null) && !(proj.isProjected())) |
96 |
return userEntryDistance / 111352D; |
97 |
return userEntryDistance;
|
98 |
} |
99 |
|
100 |
public void setNumberOfRings(int n) { |
101 |
numberOfRings = n; |
102 |
} |
103 |
|
104 |
} |