Project

General

Profile

« Previous | Next » 

Revision 3050

Added by perry about 18 years ago

fixed point centroid calculation to reflect bboxs that cross the dateline

View differences:

src/edu/ucsb/nceas/metacat/spatial/SpatialDocument.java
319 319

  
320 320
    PrecisionModel precModel = new PrecisionModel(); // default: Floating point
321 321
    GeometryFactory geomFac = new GeometryFactory( precModel, featureSchema.srid );
322
    Float w;
323
    Float s;
324
    Float e;
325
    Float n;
322 326

  
323 327
    PreparedStatement pstmt = null;
324 328
    ResultSet rs = null;
......
328 332
    if ( west.size() == south.size() && south.size() == east.size() && east.size() == north.size() ) {
329 333
        for (int i = 0; i < west.size(); i++) {
330 334

  
335
            w = (Float)west.elementAt(i);
336
            s = (Float)south.elementAt(i);
337
            e = (Float)east.elementAt(i);
338
            n = (Float)north.elementAt(i);
339

  
331 340
            // Check if it's actually a valid point
332
            if ( (Float)west.elementAt(i) == (float)0.0 &&
333
                 (Float)east.elementAt(i) == (float)0.0 && 
334
                 (Float)north.elementAt(i) == (float)0.0 &&
335
                 (Float)south.elementAt(i) == (float)0.0 ) {
341
            if (  w == 0.0 && s == 0.0 && e == 0.0 && n == 0.0) {
342
                 log.warn("        Invalid or empty coodinates ... skipping");
343
                 continue;
344
            }
336 345

  
337
                log.warn("        Invalid or empty coodinates ... skipping");
338
                continue;
346
            Double xCenter;
347
            Double yCenter;
348

  
349
            // Handle the case of crossing the dateline and poles
350
            // Assumes all coordinates are confined to -180 -90 180 90
351
            Float dl = new Float("180.0");
352
            Float _dl = new Float("-180.0");
353
            Float pl = new Float("90.0");
354
            Float _pl = new Float("-90.0");
355

  
356
            if ( w > e && s > n ) {
357
                log.info( "Crosses both the dateline and the poles .. " );
358

  
359
                xCenter = ((float)360.0 - w + e)/ (Double)2.0 + w;
360
                if( xCenter > 180 )
361
                    xCenter = xCenter - 360;
362
                yCenter = ( (float)180.0 + n - s )/ (Double)2.0 + s;
363
                if( yCenter > 90 )
364
                    yCenter = yCenter - 180; 
365

  
366
            } else if ( w > e ) {
367
                log.info( "Crosses the dateline .. " );
368

  
369
                xCenter = ((float)360.0 - w + e)/ (Double)2.0 + w;
370
                if( xCenter > 180 )
371
                    xCenter = xCenter - 360;
372
                yCenter = ( s + n ) / (Double) 2.0;
373

  
374
            } else if ( s > n ) {
375
                log.info( "Crosses the poles .. " );
376

  
377
                xCenter = ( w + e ) / (Double) 2.0;
378
                yCenter = ( (float)180.0 + n - s )/ (Double)2.0 + s;
379
                if( yCenter > 90 )
380
                    yCenter = yCenter - 180; 
381

  
382
            } else {
383
                // Just a standard point that can be calculated by the average coordinates
384
                xCenter = ( w + e ) / (Double) 2.0;
385
                yCenter = ( s + n ) / (Double) 2.0;
339 386
            }
340 387

  
341
            Double xCenter = ( (Float)west.elementAt(i) + (Float)east.elementAt(i) ) / (Double) 2.0;
342
            Double yCenter = ( (Float)south.elementAt(i) + (Float)north.elementAt(i) ) / (Double) 2.0;
343 388
            points.add( geomFac.createPoint( new Coordinate( xCenter, yCenter)) );
344 389
        }
345 390
    } else {

Also available in: Unified diff