Statistics
| Revision:

svn-gvsig-desktop / tags / Root_CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / geo / EquidistantCylindrical.java @ 1732

History | View | Annotate | Download (6.67 KB)

1
/*
2
 * EquidistantCylindricalMapProjection.java
3
 *
4
 * Copyright (c) 2002, 2003, Raben Systems, Inc.
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions are met:
9
 *
10
 *    Redistributions of source code must retain the above copyright notice,
11
 *    this list of conditions and the following disclaimer.
12
 *
13
 *    Redistributions in binary form must reproduce the above copyright notice,
14
 *    this list of conditions and the following disclaimer in the documentation
15
 *    and/or other materials provided with the distribution.
16
 *
17
 *    Neither the name of Raben Systems, Inc. nor the names of its contributors
18
 *    may be used to endorse or promote products derived from this software
19
 *    without specific prior written permission.
20
 *
21
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
 * POSSIBILITY OF SUCH DAMAGE.
32
 *
33
 * Created on July 2, 2002, 3:45 PM
34
 */
35

    
36
package org.cresques.geo;
37

    
38
//package com.raben.projection.map;
39
//import java.awt.geom.Point2D;  
40
//import java.awt.geom.GeneralPath;
41
  
42
/***
43
 * Implementation ProjectionInterface for Equidistant Cylindrical map projection
44
 * @author  Vern Raben
45
 * @version $Revision: 1732 $ $Date: 2005-03-22 17:32:53 +0100 (Tue, 22 Mar 2005) $
46
 */
47
public class EquidistantCylindrical { //extends AbstractMapProjection {
48
/*47  
49
48      /*** Creates new CylindricalEquidistantMapProjection * /
50
49      public EquidistantCylindricalMapProjection() {
51
50          setCenterCoordinate(new Point2D.Double(Math.PI, 0.0));
52
51      }
53
52  
54
53      /***
55
54       * Get coordinate for a given location in radians
56
55       * @param loc Point2D Screen location
57
56       * @return Point2D Coordinate of the point in radians
58
57       * /
59
58      public Point2D getCoordinateForLocation(Point2D loc) {
60
59          Point2D.Double coordinate = new Point2D.Double(Double.NaN,
61
60              Double.NaN);
62
61          Point2D centerCoordinate = getCenterCoordinate();
63
62          Point2D centerPoint = getCenterPoint();
64
63          double radius = getRadius();
65
64          
66
65          if (!Double.isNaN(loc.getX())) {
67
66              double x = loc.getX() - centerPoint.getX();
68
67              double y = loc.getY() - centerPoint.getY();
69
68              double latitude = y / radius;
70
69              double longitude = centerCoordinate.getX() + (x / radius);
71
70              coordinate.setLocation(longitude, latitude);
72
71              normalizeCoordinate(coordinate);
73
72          }
74
73          
75
74          return coordinate;        
76
75      }
77
76      
78
77      /***
79
78       * Get location for specified coordinate in radians
80
79       * @param coordinate Point2D longitude and latitude of coordinate in radians
81
80       * @return Point2D Screen location of the coordinate
82
81       * /
83
82      public Point2D getLocationForCoordinate(Point2D coordinate) {
84
83          Point2D.Double location = new Point2D.Double(Double.NaN, Double.NaN);
85
84          Point2D centerPoint = getCenterPoint();
86
85          Point2D centerCoordinate = getCenterCoordinate();     
87
86          double radius = getRadius();
88
87          
89
88          if (!Double.isNaN(coordinate.getX())) {
90
89              double lonDiff = normalizeLongitude(coordinate.getX() 
91
90                  - centerCoordinate.getX());
92
91              double x = centerPoint.getX() + (radius * lonDiff);
93
92              double y = radius * coordinate.getY();
94
93              location.setLocation(x, y);
95
94          }
96
95          
97
96          return location;        
98
97      }
99
98      
100
99      /***
101
100      * Get overlay grid for map
102
101      * @return mapOverlay GeneneralPath
103
102      * /
104
103     public GeneralPath getOverlayGridPath() {
105
104         GeneralPath overlayGridPath = new GeneralPath();
106
105         double radius = getRadius();
107
106         Point2D centerCoordinate = getCenterCoordinate();
108
107         Point2D centerPoint = getCenterPoint();
109
108         float mark = (float) (radius / 360.0);
110
109         double latLim = getLatitudeRange() / 2.0;
111
110         double overlayGridLatitudeIncrement = getOverlayGridLatitudeIncrement();
112
111         double overlayGridIncrement = getOverlayGridIncrement();
113
112         double overlayGridLongitudeIncrement 
114
113             = getOverlayGridLongitudeIncrement();
115
114  
116
115         // Create latitude lines
117
116         for (double lat = -latLim; lat <= latLim; 
118
117                 lat += overlayGridLatitudeIncrement) {
119
118             float y = (float) (radius * lat);
120
119             
121
120             for (double lon = -Math.PI; lon <= Math.PI;
122
121                     lon += overlayGridIncrement) {
123
122                 double lonDiff = normalizeLongitude(lon
124
123                     - centerCoordinate.getX()); 
125
124                 float x = (float) (centerPoint.getX() + (radius * lonDiff));
126
125                 overlayGridPath.moveTo(x - mark, y);
127
126                 overlayGridPath.lineTo(x + mark, y);
128
127                 overlayGridPath.moveTo(x, y - mark);
129
128                 overlayGridPath.lineTo(x, y + mark);
130
129             }
131
130         }        
132
131   
133
132         // Create longitude lines
134
133         for (double lon = -Math.PI; lon <= Math.PI;
135
134                 lon += overlayGridLongitudeIncrement) {
136
135             double lonDiff = normalizeLongitude(lon - centerCoordinate.getX()); 
137
136             float x = (float) (centerPoint.getX() + (radius * lonDiff)); 
138
137             
139
138             for (double lat = -latLim; lat <= latLim; 
140
139                     lat += overlayGridIncrement) {
141
140                 float y = (float) (radius * lat);
142
141                 overlayGridPath.moveTo(x - mark, y);
143
142                 overlayGridPath.lineTo(x + mark, y);
144
143                 overlayGridPath.moveTo(x, y - mark);
145
144                 overlayGridPath.lineTo(x, y + mark);
146
145             }
147
146         }
148
147         
149
148         return overlayGridPath;        
150
149     }
151
150     
152
151     /***
153
152      * Get name of the projection
154
153      * @return ProjectionName
155
154      * /
156
155     public ProjectionName getProjectionName() {
157
156         return ProjectionName.EQUIDISTANT_CYLINDRICAL;
158
157     }
159
*/     
160
}