Revision 3054
Added by perry about 18 years ago
src/edu/ucsb/nceas/metacat/spatial/SpatialDocument.java | ||
---|---|---|
49 | 49 |
import org.apache.log4j.Logger; |
50 | 50 |
|
51 | 51 |
/** |
52 |
|
|
52 | 53 |
* Class representing the spatial portions of an xml document |
53 | 54 |
* as a geotools Feature. |
54 | 55 |
*/ |
... | ... | |
251 | 252 |
} |
252 | 253 |
|
253 | 254 |
// Handle the case of crossing the dateline and poles |
255 |
// dateline crossing is valid |
|
256 |
// polar crossing is not ( so we swap north and south ) |
|
254 | 257 |
// Assumes all coordinates are confined to -180 -90 180 90 |
255 | 258 |
Float dl = new Float("180.0"); |
256 | 259 |
Float _dl = new Float("-180.0"); |
257 |
Float pl = new Float("90.0"); |
|
258 |
Float _pl = new Float("-90.0"); |
|
259 | 260 |
|
260 | 261 |
if ( w > e && s > n ) { |
261 |
log.info( "Crosses both the dateline and the poles .. split into 4 polygons" ); |
|
262 |
polygons.add( createPolygonFromBbox( geomFac, w, s, dl, pl ) ); |
|
263 |
polygons.add( createPolygonFromBbox( geomFac, w, _pl, dl, n ) ); |
|
264 |
polygons.add( createPolygonFromBbox( geomFac, _dl, s, e, pl ) ); |
|
265 |
polygons.add( createPolygonFromBbox( geomFac, _dl, _pl, e, n ) ); |
|
262 |
log.info( "Crosses both the dateline and the poles .. split into 2 polygons, swap n & s" ); |
|
263 |
polygons.add( createPolygonFromBbox( geomFac, w, n, dl, s ) ); |
|
264 |
polygons.add( createPolygonFromBbox( geomFac, _dl, n, e, s ) ); |
|
266 | 265 |
} else if ( w > e ) { |
267 | 266 |
log.info( "Crosses the dateline .. split into 2 polygons" ); |
268 | 267 |
polygons.add( createPolygonFromBbox( geomFac, w, s, dl, n ) ); |
269 | 268 |
polygons.add( createPolygonFromBbox( geomFac, _dl, s, e, n ) ); |
270 | 269 |
} else if ( s > n ) { |
271 |
log.info( "Crosses the poles .. split into 2 polygons" ); |
|
272 |
polygons.add( createPolygonFromBbox( geomFac, w, _pl, e, n ) ); |
|
273 |
polygons.add( createPolygonFromBbox( geomFac, w, s, e, pl ) ); |
|
270 |
log.info( "Crosses the poles .. swap north and south" ); |
|
271 |
polygons.add( createPolygonFromBbox( geomFac, w, n, e, s ) ); |
|
274 | 272 |
} else { |
275 | 273 |
// Just a standard polygon that fits nicely onto our flat earth |
276 | 274 |
polygons.add( createPolygonFromBbox( geomFac, w, s, e, n ) ); |
... | ... | |
349 | 347 |
// Handle the case of crossing the dateline and poles |
350 | 348 |
// Assumes all coordinates are confined to -180 -90 180 90 |
351 | 349 |
|
352 |
if ( w > e && s > n ) { |
|
353 |
log.info( "Crosses both the dateline and the poles .. " ); |
|
354 |
|
|
355 |
xCenter = ((float)360.0 - w + e)/ (Double)2.0 + w; |
|
356 |
if( xCenter > 180 ) |
|
357 |
xCenter = xCenter - 360; |
|
358 |
yCenter = ( (float)180.0 + n - s )/ (Double)2.0 + s; |
|
359 |
if( yCenter > 90 ) |
|
360 |
yCenter = yCenter - 180; |
|
361 |
|
|
362 |
} else if ( w > e ) { |
|
350 |
if ( w > e ) { |
|
363 | 351 |
log.info( "Crosses the dateline .. " ); |
364 |
|
|
365 | 352 |
xCenter = ((float)360.0 - w + e)/ (Double)2.0 + w; |
366 | 353 |
if( xCenter > 180 ) |
367 | 354 |
xCenter = xCenter - 360; |
368 | 355 |
yCenter = ( s + n ) / (Double) 2.0; |
369 |
|
|
370 |
} else if ( s > n ) { |
|
371 |
log.info( "Crosses the poles .. " ); |
|
372 |
|
|
373 |
xCenter = ( w + e ) / (Double) 2.0; |
|
374 |
yCenter = ( (float)180.0 + n - s )/ (Double)2.0 + s; |
|
375 |
if( yCenter > 90 ) |
|
376 |
yCenter = yCenter - 180; |
|
377 |
|
|
378 | 356 |
} else { |
379 | 357 |
// Just a standard point that can be calculated by the average coordinates |
380 | 358 |
xCenter = ( w + e ) / (Double) 2.0; |
Also available in: Unified diff
Fixed geometry logic to swap north and south if n < s