svn-gvsig-desktop / tags / v1_1_Build_1006 / libraries / libCq_CMS_praster / src / org / cresques / geo / EquidistantCylindrical.java @ 12458
History | View | Annotate | Download (6.96 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 |
package org.cresques.geo; |
36 |
|
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: 12458 $ $Date: 2007-07-02 13:52:44 +0200 (Mon, 02 Jul 2007) $
|
46 |
*/
|
47 |
public class EquidistantCylindrical { //extends AbstractMapProjection { |
48 |
|
49 |
/*47
|
50 |
48 /*** Creates new CylindricalEquidistantMapProjection * /
|
51 |
49 public EquidistantCylindricalMapProjection() {
|
52 |
50 setCenterCoordinate(new Point2D.Double(Math.PI, 0.0));
|
53 |
51 }
|
54 |
52
|
55 |
53 /***
|
56 |
54 * Get coordinate for a given location in radians
|
57 |
55 * @param loc Point2D Screen location
|
58 |
56 * @return Point2D Coordinate of the point in radians
|
59 |
57 * /
|
60 |
58 public Point2D getCoordinateForLocation(Point2D loc) {
|
61 |
59 Point2D.Double coordinate = new Point2D.Double(Double.NaN,
|
62 |
60 Double.NaN);
|
63 |
61 Point2D centerCoordinate = getCenterCoordinate();
|
64 |
62 Point2D centerPoint = getCenterPoint();
|
65 |
63 double radius = getRadius();
|
66 |
64
|
67 |
65 if (!Double.isNaN(loc.getX())) {
|
68 |
66 double x = loc.getX() - centerPoint.getX();
|
69 |
67 double y = loc.getY() - centerPoint.getY();
|
70 |
68 double latitude = y / radius;
|
71 |
69 double longitude = centerCoordinate.getX() + (x / radius);
|
72 |
70 coordinate.setLocation(longitude, latitude);
|
73 |
71 normalizeCoordinate(coordinate);
|
74 |
72 }
|
75 |
73
|
76 |
74 return coordinate;
|
77 |
75 }
|
78 |
76
|
79 |
77 /***
|
80 |
78 * Get location for specified coordinate in radians
|
81 |
79 * @param coordinate Point2D longitude and latitude of coordinate in radians
|
82 |
80 * @return Point2D Screen location of the coordinate
|
83 |
81 * /
|
84 |
82 public Point2D getLocationForCoordinate(Point2D coordinate) {
|
85 |
83 Point2D.Double location = new Point2D.Double(Double.NaN, Double.NaN);
|
86 |
84 Point2D centerPoint = getCenterPoint();
|
87 |
85 Point2D centerCoordinate = getCenterCoordinate();
|
88 |
86 double radius = getRadius();
|
89 |
87
|
90 |
88 if (!Double.isNaN(coordinate.getX())) {
|
91 |
89 double lonDiff = normalizeLongitude(coordinate.getX()
|
92 |
90 - centerCoordinate.getX());
|
93 |
91 double x = centerPoint.getX() + (radius * lonDiff);
|
94 |
92 double y = radius * coordinate.getY();
|
95 |
93 location.setLocation(x, y);
|
96 |
94 }
|
97 |
95
|
98 |
96 return location;
|
99 |
97 }
|
100 |
98
|
101 |
99 /***
|
102 |
100 * Get overlay grid for map
|
103 |
101 * @return mapOverlay GeneneralPath
|
104 |
102 * /
|
105 |
103 public GeneralPath getOverlayGridPath() {
|
106 |
104 GeneralPath overlayGridPath = new GeneralPath();
|
107 |
105 double radius = getRadius();
|
108 |
106 Point2D centerCoordinate = getCenterCoordinate();
|
109 |
107 Point2D centerPoint = getCenterPoint();
|
110 |
108 float mark = (float) (radius / 360.0);
|
111 |
109 double latLim = getLatitudeRange() / 2.0;
|
112 |
110 double overlayGridLatitudeIncrement = getOverlayGridLatitudeIncrement();
|
113 |
111 double overlayGridIncrement = getOverlayGridIncrement();
|
114 |
112 double overlayGridLongitudeIncrement
|
115 |
113 = getOverlayGridLongitudeIncrement();
|
116 |
114
|
117 |
115 // Create latitude lines
|
118 |
116 for (double lat = -latLim; lat <= latLim;
|
119 |
117 lat += overlayGridLatitudeIncrement) {
|
120 |
118 float y = (float) (radius * lat);
|
121 |
119
|
122 |
120 for (double lon = -Math.PI; lon <= Math.PI;
|
123 |
121 lon += overlayGridIncrement) {
|
124 |
122 double lonDiff = normalizeLongitude(lon
|
125 |
123 - centerCoordinate.getX());
|
126 |
124 float x = (float) (centerPoint.getX() + (radius * lonDiff));
|
127 |
125 overlayGridPath.moveTo(x - mark, y);
|
128 |
126 overlayGridPath.lineTo(x + mark, y);
|
129 |
127 overlayGridPath.moveTo(x, y - mark);
|
130 |
128 overlayGridPath.lineTo(x, y + mark);
|
131 |
129 }
|
132 |
130 }
|
133 |
131
|
134 |
132 // Create longitude lines
|
135 |
133 for (double lon = -Math.PI; lon <= Math.PI;
|
136 |
134 lon += overlayGridLongitudeIncrement) {
|
137 |
135 double lonDiff = normalizeLongitude(lon - centerCoordinate.getX());
|
138 |
136 float x = (float) (centerPoint.getX() + (radius * lonDiff));
|
139 |
137
|
140 |
138 for (double lat = -latLim; lat <= latLim;
|
141 |
139 lat += overlayGridIncrement) {
|
142 |
140 float y = (float) (radius * lat);
|
143 |
141 overlayGridPath.moveTo(x - mark, y);
|
144 |
142 overlayGridPath.lineTo(x + mark, y);
|
145 |
143 overlayGridPath.moveTo(x, y - mark);
|
146 |
144 overlayGridPath.lineTo(x, y + mark);
|
147 |
145 }
|
148 |
146 }
|
149 |
147
|
150 |
148 return overlayGridPath;
|
151 |
149 }
|
152 |
150
|
153 |
151 /***
|
154 |
152 * Get name of the projection
|
155 |
153 * @return ProjectionName
|
156 |
154 * /
|
157 |
155 public ProjectionName getProjectionName() {
|
158 |
156 return ProjectionName.EQUIDISTANT_CYLINDRICAL;
|
159 |
157 }
|
160 |
*/
|
161 |
} |