Statistics
| Revision:

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 @ 245

History | View | Annotate | Download (2.58 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

    
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

    
40
    /**
41
     * For computing with geodetic coordinates:
42
     * returns the angular measure (in radians)
43
     * for a distance over the earth along a
44
     * meridiam.
45
     * Because this consideration is an approximation,
46
     * we consideer the eart like an sphere (not an
47
     * ellipsoid)
48
     * 
49
     * @param dist
50
     *            distance in meters
51
     * @return arc of meridian whose length is the specified
52
     *         distance
53
     */
54
    private double toSexaAngularMeasure(double dist) {
55
        /*
56
         * dist = 6378km(terrestrial radius) -> 2PI
57
         * passed distance -> incognite
58
         */
59
        return Math.toDegrees((2 * Math.PI * dist) / EARTH_RADIUS);
60
    }
61

    
62
    /**
63
     * Converts a distance entered by user in the GUI in the same distance
64
     * in internal units (measure units)
65
     */
66
    protected double getInInternalUnits(double userEntryDistance,
67
        IProjection proj, int distanceUnits, int mapUnits) {
68

    
69
        double[] trans2Meter = MapContext.getDistanceTrans2Meter();
70
        double distInInternalUnits =
71
            (userEntryDistance / trans2Meter[mapUnits])
72
                * trans2Meter[distanceUnits];
73

    
74
        if ((proj != null) && !(proj.isProjected()))
75
            distInInternalUnits = toSexaAngularMeasure(distInInternalUnits);
76

    
77
        return distInInternalUnits;
78
    }
79

    
80
}