1 /* -------------------------------------------------------------------
2 GeoVISTA Center (Penn State, Dept. of Geography)
3 Java source file for the class ProjectionEquidistantConic
4 Copyright (c), 2002, GeoVISTA Center
5 All Rights Reserved.
6 Original Author: Frank Hardisty
7 $Author: hardisty $
8 $Id: ProjectionEquidistantConic.java,v 1.4 2003/05/16 15:54:04 hardisty Exp $
9 $Date: 2003/05/16 15:54:04 $
10 Reference: Document no:
11 ___ ___
12 ------------------------------------------------------------------- *
13 */
14 package edu.psu.geovista.app.map;
15
16 import java.awt.*;
17 import java.awt.geom.*;
18
19
20 /***
21 * put your documentation comment here
22 */
23 public class ProjectionEquidistantConic implements Projection {
24 private double centralMeridian = Double.NaN;
25 private double standardParallelOne = Double.NaN;
26 private double standardParallelTwo = Double.NaN;
27 private double centralLatitude = Double.NaN;
28
29 /*
30 * Coordinates should be passed in as radians.
31 * The projected values are returned in radians as well.
32 * The second argument can be null, or not. If it is not, that Point2D will
33 * returned by the method
34 */
35 public Point2D.Double project(double lat, double longVal, Point2D.Double pt) {
36 if (Double.isNaN(centralLatitude) || Double.isNaN(centralMeridian) ||
37 Double.isNaN(standardParallelOne) ||
38 Double.isNaN(standardParallelOne)) {
39 throw new IllegalStateException(
40 "ProjectionEquidistantConic needs to have " +
41 "member variables set.");
42 }
43
44 if (pt == null) {
45 pt = new Point2D.Double();
46 }
47
48 this.projectLongitudeLatititudeRadians(longVal, lat, this.centralMeridian,
49 this.standardParallelOne,
50 this.standardParallelTwo,
51 this.centralLatitude, pt);
52
53 //pt.setLocation(longVal, lat);
54 return pt;
55 }
56
57 /*
58 * array[0] = X
59 * array[1] = Y
60 *
61 */
62 public static void projectLongitudeLatititudeRadians(double longitudeRadians,
63 double latitudeRadians,
64 double centralMeridian,
65 double standardParallelOne,
66 double standardParallelTwo,
67 double centralLatitude,
68 Point2D.Double pt) {
69 //This small check re-adjusts all longitude values depending on the placement of the central meridian.
70 if (centralMeridian < 0) {
71 //A check to see if each longitude value is west of the central meridian.
72 //Thus, those meridians in the eastern hemisphere that are greater than pi distance away from
73 //the central meridian are subtracted from 2 * pi. These longitude values are now within -pi to +pi ranage.
74 if (Math.abs(longitudeRadians - centralMeridian) > Math.PI) {
75 //Using -90 as the central meridian
76 //e.g., Abs(100 - (-90)) = 190; which is greater than 180
77 longitudeRadians = longitudeRadians - (2 * Math.PI);
78
79 //Thus, (100 - 360) = -260; which is within the +pi to -pi range.
80 }
81 }
82
83 if (centralMeridian > 0) {
84 // A check to see if each longitude value is east of the central meridian.
85 // Thus, those meridians in the western hemisphere that are greater than pi distance away from
86 // the central meridian are added to 2 * pi. These longitude values are now within -pi to +pi ranage.
87 if ((longitudeRadians - centralMeridian) > Math.PI) {
88 // Using 90 as the central meridian
89 // e.g., Abs(-100 - (90)) = 190; which is greater than 180
90 longitudeRadians = longitudeRadians + (2 * Math.PI);
91
92 // Thus, (-100 + 360) = 260; which is within the +pi to -pi range.
93 }
94 }
95
96 double eQConic_n;
97 double eQConic_G;
98 double eQConic_P;
99 double eQConic_Po;
100 double eQConic_Theta;
101
102
103 // The first step in calculating the Equidistant Conic x and y plotting coordinates
104 // requires solving for several intermediate values.
105 eQConic_n = (Math.cos(standardParallelOne) -
106 Math.cos(standardParallelTwo)) / (standardParallelTwo -
107 standardParallelOne);
108 eQConic_G = (Math.cos(standardParallelOne) / eQConic_n) +
109 standardParallelOne;
110 eQConic_Po = 0.65 * (eQConic_G - centralLatitude);
111 eQConic_P = 0.65 * (eQConic_G - latitudeRadians);
112 eQConic_Theta = eQConic_n * (longitudeRadians - centralMeridian);
113
114 // Defining the Equidistant Conic projection plotting coordinates
115 double eQConic_Y = eQConic_Po - (eQConic_P * (Math.cos(eQConic_Theta)));
116 double eQConic_X = eQConic_P * Math.sin(eQConic_Theta);
117
118
119 //double[] xY = new double[2];
120 pt.x = eQConic_X;
121 pt.y = eQConic_Y;
122
123 //return pt;
124 }
125
126 public void setCentralMeridian(double centralMeridian) {
127 this.centralMeridian = centralMeridian;
128 }
129
130 public double getCentralMeridian() {
131 return this.centralMeridian;
132 }
133
134 public void setStandardParallelOne(double standardParallelOne) {
135 this.standardParallelOne = standardParallelOne;
136 }
137
138 public double getStandardParallelOne() {
139 return this.standardParallelOne;
140 }
141
142 public void setStandardParallelTwo(double standardParallelTwo) {
143 this.standardParallelTwo = standardParallelTwo;
144 }
145
146 public double getStandardParallelTwo() {
147 return this.standardParallelTwo;
148 }
149
150 public void setCentralLatitude(double centralLatitude) {
151 this.centralLatitude = centralLatitude;
152 }
153
154 public double getCentralLatitude() {
155 return this.centralLatitude;
156 }
157
158 public Shape transform(Shape shpIn) {
159 PathIterator pit = shpIn.getPathIterator(null);
160 GeneralPath gep = new GeneralPath(shpIn);
161
162 System.out.println("hi i'm here");
163
164 return shpIn;
165 }
166
167 /***
168 * DOCUMENT ME!
169 *
170 * @param s DOCUMENT ME!
171 *
172 * @return DOCUMENT ME!
173 */
174 public Shape project(Shape s) {
175
176 GeneralPath p = new GeneralPath();
177 float[] coords = { 0, 0, 0, 0, 0, 0 };
178 float first_x = 0;
179 float first_y = 0;
180 float first_tx = 0;
181 float first_ty = 0;
182 float prev_x = 0;
183 float prev_y = 0;
184 float prev_tx = 0;
185 float prev_ty = 0;
186 double x=0;
187 double y=0;
188 Point2D.Double pt = new Point2D.Double();
189
190 for (PathIterator iter = s.getPathIterator(null);
191 !iter.isDone();
192 iter.next()) {
193 switch (iter.currentSegment(coords)) {
194 case PathIterator.SEG_MOVETO:
195 first_x = coords[0];
196 first_y = coords[1];
197 x = Math.toRadians(first_x);
198 y = Math.toRadians(first_y);
199
200 this.project(y,x,pt);
201
202 first_x = (float)pt.getX();
203 first_y = (float)pt.getY();
204 p.moveTo(first_x,first_y);
205 break;
206
207 case PathIterator.SEG_LINETO:
208 first_x = coords[0];
209 first_y = coords[1];
210 x = Math.toRadians(first_x);
211 y = Math.toRadians(first_y);
212 this.project(y,x,pt);
213
214 first_x = (float)pt.getX();
215 first_y = (float)pt.getY();
216 p.lineTo(first_x,first_y);
217 break;
218
219 case PathIterator.SEG_QUADTO:
220 throw new IllegalArgumentException("Projection doesn't know what to do with this");
221
222
223 case PathIterator.SEG_CUBICTO:
224 throw new IllegalArgumentException("Projection doesn't know what to do with this");
225
226 case PathIterator.SEG_CLOSE:
227 p.closePath();
228 break;
229 }
230 }
231
232 return p;
233 }
234 }
This page was automatically generated by Maven