Rev

Rev 1822 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | Bug Tracker

Rev 1822 Rev 2655
Line 2... Line 2...
2
2
3
import java.util.ArrayList;
3
import java.util.ArrayList;
-
 
4
-
 
5
import org.etsi.adapter.TERFactory;
4
6
5
/**
7
/**
6
 * @desc
8
 * @desc
7
 * @see To validate GPS location: http://www.gps-coordinates.net
9
 * @see To validate GPS location: http://www.gps-coordinates.net
8
 */
10
 */
Line 33... Line 35...
33
       
35
       
34
    }
36
    }
35
   
37
   
36
    @Override
38
    @Override
37
    public boolean isLocationInsideEllipticArea(final WGS84 p_location, final ArrayList<WGS84> p_ellipticArea) {
39
    public boolean isLocationInsideEllipticArea(final WGS84 p_location, final ArrayList<WGS84> p_ellipticArea) {
38
//        System.out.println(">>> Positioning.isLocationInsideEllipticArea: " + p_location);
40
//        TERFactory.getInstance().logDebug(">>> Positioning.isLocationInsideEllipticArea: " + p_location);
39
       
41
       
40
        // TODO: implement it
42
        // TODO: implement it
41
        // Do not forget aboout passing throw 0 meridian
43
        // Do not forget aboout passing throw 0 meridian
42
        return false;
44
        return false;
43
    }
45
    }
44
46
45
    @Override
47
    @Override
46
    public boolean isLocationInsidePolygonalArea(final WGS84 p_location, final ArrayList<WGS84> p_polygonalArea) {
48
    public boolean isLocationInsidePolygonalArea(final WGS84 p_location, final ArrayList<WGS84> p_polygonalArea) {
47
//        System.out.println(">>> Positioning.isLocationInsidePolygonalArea: " + p_location + ", " + p_polygonalArea);
49
//        TERFactory.getInstance().logDebug(">>> Positioning.isLocationInsidePolygonalArea: " + p_location + ", " + p_polygonalArea);
48
       
50
       
49
        // TODO: Check passing throw 0 meridian and Equador
51
        // TODO: Check passing throw 0 meridian and Equador
50
       
52
       
51
        double angle = 0;
53
        double angle = 0;
52
        int poleNum = p_polygonalArea.size();
54
        int poleNum = p_polygonalArea.size();
Line 62... Line 64...
62
                0
64
                0
63
            );
65
            );
64
            angle += calcAngle(delta1, delta2);
66
            angle += calcAngle(delta1, delta2);
65
        } // End of 'for' statement
67
        } // End of 'for' statement
66
       
68
       
67
//        System.out.println("<<< Positioning.isLocationInsidePolygonalArea: " + (boolean)((Math.abs(angle) < Math.PI) ? false : true));
69
//        TERFactory.getInstance().logDebug("<<< Positioning.isLocationInsidePolygonalArea: " + (boolean)((Math.abs(angle) < Math.PI) ? false : true));
68
        return (boolean)((Math.abs(angle) < Math.PI) ? false : true);
70
        return (boolean)((Math.abs(angle) < Math.PI) ? false : true);
69
    }
71
    }
70
72
71
    @Override
73
    @Override
72
    public boolean isLocationInsidePolygonalAreas(final WGS84 p_location, final ArrayList< ArrayList<WGS84> > p_polygonalAreas) {
74
    public boolean isLocationInsidePolygonalAreas(final WGS84 p_location, final ArrayList< ArrayList<WGS84> > p_polygonalAreas) {
73
//        System.out.println(">>> Positioning.isLocationInsidePolygonalAreas: " + p_location);
75
//        TERFactory.getInstance().logDebug(">>> Positioning.isLocationInsidePolygonalAreas: " + p_location);
74
       
76
       
75
        for (int index = 0; index < p_polygonalAreas.size(); index++) {
77
        for (int index = 0; index < p_polygonalAreas.size(); index++) {
76
            if (isLocationInsidePolygonalArea(p_location, p_polygonalAreas.get(index))) {
78
            if (isLocationInsidePolygonalArea(p_location, p_polygonalAreas.get(index))) {
77
                return true;
79
                return true;
78
            }
80
            }
Line 81... Line 83...
81
        return false; // Not found
83
        return false; // Not found
82
    }
84
    }
83
85
84
    @Override
86
    @Override
85
    public boolean isLocationInsideCircularArea(final WGS84 p_location, final WGS84 p_center, final int p_radius) {
87
    public boolean isLocationInsideCircularArea(final WGS84 p_location, final WGS84 p_center, final int p_radius) {
86
//        System.out.println(">>> Positioning.isLocationInsideCircularArea: " + p_location + ", " + p_center + ", " + p_radius);
88
//        TERFactory.getInstance().logDebug(">>> Positioning.isLocationInsideCircularArea: " + p_location + ", " + p_center + ", " + p_radius);
87
       
89
       
88
        // TODO: Check passing throw 0 meridian and Equador
90
        // TODO: Check passing throw 0 meridian and Equador
89
       
91
       
90
        double theta = p_center.getLongitude() - p_location.getLongitude();
92
        double theta = p_center.getLongitude() - p_location.getLongitude();
91
        double distance =
93
        double distance =
92
            Math.sin(dd2rad(p_center.getLatitude())) * Math.sin(dd2rad(p_location.getLatitude())) +
94
            Math.sin(dd2rad(p_center.getLatitude())) * Math.sin(dd2rad(p_location.getLatitude())) +
93
            Math.cos(dd2rad(p_center.getLatitude())) * Math.cos(dd2rad(p_location.getLatitude())) * Math.cos(dd2rad(theta));
95
            Math.cos(dd2rad(p_center.getLatitude())) * Math.cos(dd2rad(p_location.getLatitude())) * Math.cos(dd2rad(theta));
94
        distance = rad2dd(Math.acos(distance));
96
        distance = rad2dd(Math.acos(distance));
95
        distance *= 60 * 1.1515 * 1.609344 /*Kilometers*/;
97
        distance *= 60 * 1.1515 * 1.609344 /*Kilometers*/;
96
//        System.out.println("Positioning.isLocationInsideCircularArea: distance=" + distance);
98
//        TERFactory.getInstance().logDebug("Positioning.isLocationInsideCircularArea: distance=" + distance);
97
       
99
       
98
//        System.out.println("<<< Positioning.isLocationInsideCircularArea: " + (boolean)(distance <= (p_radius / 1000.0)));
100
//        TERFactory.getInstance().logDebug("<<< Positioning.isLocationInsideCircularArea: " + (boolean)(distance <= (p_radius / 1000.0)));
99
        return (boolean)(distance <= (p_radius / 1000.0));
101
        return (boolean)(distance <= (p_radius / 1000.0));
100
    }
102
    }
101
   
103
   
102
    @Override
104
    @Override
103
    public boolean isValidPolygonArea(final ArrayList<WGS84> p_polygonalArea) {
105
    public boolean isValidPolygonArea(final ArrayList<WGS84> p_polygonalArea) {
104
//        System.out.println(">>> Positioning.isValidPolygonArea");
106
//        TERFactory.getInstance().logDebug(">>> Positioning.isValidPolygonArea");
105
       
107
       
106
        // Check if polygon coordinates are valid
108
        // Check if polygon coordinates are valid
107
        for (int i = 0; i < p_polygonalArea.size(); i++) {
109
        for (int i = 0; i < p_polygonalArea.size(); i++) {
108
            if (!p_polygonalArea.get(i).isValidPosition()) {
110
            if (!p_polygonalArea.get(i).isValidPosition()) {
109
                return false;
111
                return false;
Line 113... Line 115...
113
        return true;
115
        return true;
114
    }
116
    }
115
   
117
   
116
    @Override
118
    @Override
117
    public boolean isLocationInsideIdentifiedRegion(final int p_regionDictionary, final int p_regionId, final long p_localRegion, final WGS84 p_location) {
119
    public boolean isLocationInsideIdentifiedRegion(final int p_regionDictionary, final int p_regionId, final long p_localRegion, final WGS84 p_location) {
118
//        System.out.println(">>> Positioning.isLocationInsideIdentifiedRegion: " + p_regionDictionary + ", " + p_regionId + ", " + p_localRegion + ", " + p_location);
120
//        TERFactory.getInstance().logDebug(">>> Positioning.isLocationInsideIdentifiedRegion: " + p_regionDictionary + ", " + p_regionId + ", " + p_localRegion + ", " + p_location);
119
       
121
       
120
        return CountriesAreas.getInstance().isLocationInsideIdentifiedRegion(p_regionDictionary, p_regionId, p_localRegion, p_location);
122
        return CountriesAreas.getInstance().isLocationInsideIdentifiedRegion(p_regionDictionary, p_regionId, p_localRegion, p_location);
121
    }
123
    }
122
   
124
   
123
    @Override
125
    @Override
124
    public boolean isPolygonalRegionInside(final ArrayList<WGS84> p_parentArea, final ArrayList<WGS84> p_regionArea) {
126
    public boolean isPolygonalRegionInside(final ArrayList<WGS84> p_parentArea, final ArrayList<WGS84> p_regionArea) {
125
//        System.out.println(">>> Positioning.isPolygonalRegionInside: " + p_parentArea + ", " + p_regionArea);
127
//        TERFactory.getInstance().logDebug(">>> Positioning.isPolygonalRegionInside: " + p_parentArea + ", " + p_regionArea);
126
       
128
       
127
        for (int i = 0; i < p_regionArea.size(); i++) {
129
        for (int i = 0; i < p_regionArea.size(); i++) {
128
            if (!isLocationInsidePolygonalArea(p_regionArea.get(i), p_parentArea)) {
130
            if (!isLocationInsidePolygonalArea(p_regionArea.get(i), p_parentArea)) {
129
                return false;
131
                return false;
130
            }
132
            }
Line 132... Line 134...
132
       
134
       
133
        return true;
135
        return true;
134
    }
136
    }
135
   
137
   
136
    private double calcAngle(final WGS84 p_origin, final WGS84 p_end) {
138
    private double calcAngle(final WGS84 p_origin, final WGS84 p_end) {
137
//        System.out.println(">>> calcAngle: " + p_origin.getLatitude() + " - " + p_origin.getLongitude() + " - " + p_end.getLatitude() + " - " + p_end.getLongitude());
139
//        TERFactory.getInstance().logDebug(">>> calcAngle: " + p_origin.getLatitude() + " - " + p_origin.getLongitude() + " - " + p_end.getLatitude() + " - " + p_end.getLongitude());
138
        double theta1 = Math.atan2(p_origin.getLatitude(), p_origin.getLongitude());
140
        double theta1 = Math.atan2(p_origin.getLatitude(), p_origin.getLongitude());
139
//        System.out.println("Angle2D: theta1=" + theta1);
141
//        TERFactory.getInstance().logDebug("Angle2D: theta1=" + theta1);
140
        double theta2 = Math.atan2(p_end.getLatitude(), p_end.getLongitude());
142
        double theta2 = Math.atan2(p_end.getLatitude(), p_end.getLongitude());
141
//        System.out.println("Angle2D: theta2=" + theta2);
143
//        TERFactory.getInstance().logDebug("Angle2D: theta2=" + theta2);
142
        double dtheta = theta2 - theta1;
144
        double dtheta = theta2 - theta1;
143
//        System.out.println("calcAngle: dtheta" + dtheta);
145
//        TERFactory.getInstance().logDebug("calcAngle: dtheta" + dtheta);
144
        while (dtheta > Math.PI) {
146
        while (dtheta > Math.PI) {
145
            dtheta -= TWOPI;
147
            dtheta -= TWOPI;
146
        } // End of 'while' statement
148
        } // End of 'while' statement
147
        while (dtheta < -Math.PI) {
149
        while (dtheta < -Math.PI) {
148
            dtheta += TWOPI;
150
            dtheta += TWOPI;
149
        } // End of 'while' statement
151
        } // End of 'while' statement
150
       
152
       
151
//        System.out.println("<<< calcAngle: " + dtheta);
153
//        TERFactory.getInstance().logDebug("<<< calcAngle: " + dtheta);
152
        return dtheta;
154
        return dtheta;
153
    }
155
    }
154
   
156
   
155
    /**
157
    /**
156
     * @desc Convert a decimal degrees value into a decimal radian
158
     * @desc Convert a decimal degrees value into a decimal radian