Changeset 33867 for other-projects
- Timestamp:
- 2020-01-23T21:12:17+13:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/maori-lang-detection/src/org/greenstone/atea/CountryCodeCountsMapData.java
r33858 r33867 358 358 Double west = lng - half_width; 359 359 Double south = lat; 360 361 List<Position> pts = recalculateAreaIfLarge(count, HISTOGRAM_WIDTH, countryCode, lat, lng, north, south, east, west); 362 360 363 /* 361 364 System.err.println("For country " + countryCode + ":"); … … 364 367 System.err.println("east = " + east); 365 368 System.err.println("west = " + west + "\n"); 369 System.err.println("-------------"); 366 370 */ 371 372 List<List<Position>> outerList = new LinkedList<List<Position>>(); 373 if(pts != null) { 374 outerList.add(pts); 375 } else { 376 377 378 List<Position> points = new LinkedList<Position>(); 379 outerList.add(points); 380 381 points.add(new Position(west, south)); // Position(lng, lat) not Position(lat, lng) 382 points.add(new Position(west, north)); 383 points.add(new Position(east, north)); 384 points.add(new Position(east, south)); 385 } 386 387 Geometry rectangle = new Polygon(outerList); 388 389 // Coords: a List of List of Positions, see https://ngageoint.github.io/simple-features-geojson-java/docs/api/ 390 // https://www.here.xyz/api/concepts/geojsonbasics/#polygon 391 392 return rectangle; 393 } 394 395 private List<Position> recalculateAreaIfLarge(final int count, final int HISTOGRAM_WIDTH, String countryCode, 396 final Double lat, final Double lng, 397 Double north, Double south, Double east, Double west) { 398 boolean recalculated = false; 399 367 400 // Check if we're dealing with very large numbers, in which case, we can have follow off the longitude edges 368 401 // Max longitude values are -180 to 180. So a max of 360 units between them. (Max latitude is -90 to 90) … … 371 404 // and the South pole has a latitude of -90°." 372 405 if((east + Math.abs(west)) > 360 || east > 180 || west < -180) { 373 half_width = HISTOGRAM_WIDTH/2; // reset half_width 406 System.err.println("For country " + countryCode + ":"); 407 System.err.println("north = " + north); 408 System.err.println("south = " + south); 409 System.err.println("east = " + east); 410 System.err.println("west = " + west + "\n"); 411 412 int half_width = HISTOGRAM_WIDTH/2; // reset half_width 374 413 375 414 double v_tmp_count = Math.sqrt(count); … … 377 416 //v_tmp_count = Math.ceil(v_tmp_count); 378 417 double h_tmp_count = v_tmp_count; 379 380 /* 418 System.err.println("count = " + count); 419 System.err.println("v = " + v_tmp_count); 420 System.err.println("h = " + h_tmp_count); 421 System.err.println("lat = " + lat); 422 System.err.println("lng = " + lng + "\n"); 423 424 if(h_tmp_count > 90) { // 360 max width, of which each longitude 425 // is 4 units (horizontal factor = 4, and half-width is half 426 // of that). So max width/h_tmp_count allowed 90 => 360 427 // longitude on map (-180 to 180). 428 // Put the excess h_tmp_count into v_tmp_count and ensure 429 // that does not go over 90+90 = 180 max. Vertical_factor is 1. 430 431 System.err.println("Out of longitude range. Attempting to compensate..."); 432 433 double diff = h_tmp_count - 80.0; // actually 90 wraps on geojson tools, 80 doesn't 434 h_tmp_count -= diff; 435 v_tmp_count = (count/h_tmp_count); 436 437 if(v_tmp_count > 180 || h_tmp_count > 90) { 438 System.err.println("Warning: still exceeded max latitude and/or longitude range"); 439 } 440 441 } 442 381 443 System.err.println("Recalculating polygon for country with high count: " + countryCode + "."); 382 444 System.err.println("count = " + count); … … 385 447 System.err.println("lat = " + lat); 386 448 System.err.println("lng = " + lng + "\n"); 387 */449 388 450 389 451 north = lat + v_tmp_count; … … 419 481 420 482 // Hopefully we don't exceed +90/-90 lat and +/-180 longitude 421 /* 422 System.err.println("north = " + north); 483 484 recalculated = true; 485 486 487 } else if(west < -140.0) { 488 // past -140 west, the edges don't wrap well in geotools, so shift any points more west/negative than -140: 489 490 double diff = -140.0 - west; 491 west = -140.0; 492 east += diff; 493 494 recalculated = true; 495 } 496 497 if(recalculated) { 498 System.err.println("\nnorth = " + north); 423 499 System.err.println("south = " + south); 424 500 System.err.println("east = " + east); 425 501 System.err.println("west = " + west); 426 */ 427 } 428 429 List<List<Position>> outerList = new LinkedList<List<Position>>(); 430 List<Position> points = new LinkedList<Position>(); 431 outerList.add(points); 432 433 434 points.add(new Position(west, south)); // Position(lng, lat) not Position(lat, lng) 435 points.add(new Position(west, north)); 436 points.add(new Position(east, north)); 437 points.add(new Position(east, south)); 438 439 440 Geometry rectangle = new Polygon(outerList); 441 442 // Coords: a List of List of Positions, see https://ngageoint.github.io/simple-features-geojson-java/docs/api/ 443 // https://www.here.xyz/api/concepts/geojsonbasics/#polygon 444 445 return rectangle; 502 503 504 List<Position> points = new LinkedList<Position>(); 505 506 points.add(new Position(west, south)); // Position(lng, lat) not Position(lat, lng) 507 points.add(new Position(west, north)); 508 points.add(new Position(east, north)); 509 points.add(new Position(east, south)); 510 511 return points; 512 } 513 514 return null; 446 515 } 447 516
Note:
See TracChangeset
for help on using the changeset viewer.