# Changeset 33858

Show
Ignore:
Timestamp:
22.01.2020 19:31:09 (4 weeks ago)
Message:

Fixes to the code committed yesterday: correct calculation of the rectangle for a country with high count value.

Files:
1 modified

Unmodified
Removed
• ## other-projects/maori-lang-detection/src/org/greenstone/atea/CountryCodeCountsMapData.java

r33853 r33858
347347    // to grow northwards.
348348    Double north = lat + (vertical_factor * count);
349
349
350350    while (north > 90) {
351351        // recalculate north after decreasing histogram's vertical growth

358358    Double west = lng - half_width;
359359    Double south = lat;
360
360    /*
361    System.err.println("For country " + countryCode + ":");
362    System.err.println("north = " + north);
363    System.err.println("south = " + south);
364    System.err.println("east = " + east);
365    System.err.println("west = " + west + "\n");
366    */
361367    // Check if we're dealing with very large numbers, in which case, we can have follow off the longitude edges
362     // Max longitude values are -180 to 180. So a max of 360 units between them.
368    // Max longitude values are -180 to 180. So a max of 360 units between them. (Max latitude is -90 to 90)
369    // "Longitude is in the range -180 and +180 specifying coordinates west and east of the Prime Meridian, respectively.
370    // For reference, the Equator has a latitude of 0Â°, the North pole has a latitude of 90Â° north (written 90Â° N or +90Â°),
371    // and the South pole has a latitude of -90Â°."
363372    if((east + Math.abs(west)) > 360 || east > 180 || west < -180) {
364373        half_width = HISTOGRAM_WIDTH/2; // reset half_width
365374
366375        double v_tmp_count = Math.sqrt(count);
367         double h_tmp_count = Math.floor(v_tmp_count);
368         v_tmp_count = Math.ceil(v_tmp_count);
376        //double h_tmp_count = Math.floor(v_tmp_count);
377        //v_tmp_count = Math.ceil(v_tmp_count);
378        double h_tmp_count = v_tmp_count;
369379
370380        /*
371         System.err.println("HERE, count = " + count);
372         System.err.println("HERE, v = " + v_tmp_count);
373         System.err.println("HERE, h = " + h_tmp_count);
374         System.err.println("HERE, lat = " + lat);
375         System.err.println("HERE, lng = " + lng + "\n");
381        System.err.println("Recalculating polygon for country with high count: " + countryCode + ".");
382        System.err.println("count = " + count);
383        System.err.println("v = " + v_tmp_count);
384        System.err.println("h = " + h_tmp_count);
385        System.err.println("lat = " + lat);
386        System.err.println("lng = " + lng + "\n");
376387        */
377
388
378389        north = lat + v_tmp_count;
379390        south = lat;
380         east = lng + (h_tmp_count/2 * half_width); // a certain width, half_width, represents one unit in the x axis
381         west = lng - (h_tmp_count/2 * half_width);
382
391        east = lng + (h_tmp_count * half_width); // a certain width, half_width, represents one unit in the x axis
392        west = lng - (h_tmp_count * half_width);
393
394        /*
395    System.err.println("north = " + north);
396    System.err.println("south = " + south);
397    System.err.println("east = " + east);
398    System.err.println("west = " + west + "\n");
399        */
400
383401        if(north > 90) {
384402        // centre vertically on lat

388406
389407        if(west < -180.0) {
390         double h_diff = lng - 180.0; // the country's longitude (lng) is h_diff from the western edge
391         west = 180.0; // maximise western edge
392         east = h_tmp_count - h_diff/half_width;// then grow the remainder of h_tmp_count in the opposite (eastern) direction
408        double h_diff = -180.0 - west; // west is a larger negative value than -180, so subtracting west from -180 produces a positive h_diff value
409        west = -180.0; // set to extreme western edge
410        east = east + h_diff;
393411        }
394412        else if(east > 180.0) {
395         double h_diff = 180.0 - lng; // the country's longitude (lng) is h_diff from the eastern edge
413        double h_diff = east - 180.0; // the country's longitude (lng) is h_diff from the eastern edge
396414        east = 180.0; // maximise eastern edge
397         west = -1 * (h_tmp_count - (h_diff/half_width)); // then grow the remainder of h_tmp_count in the opposite (western) direction
415        west = west - h_diff; // then grow the remainder of h_tmp_count in the opposite (western/negative) direction
398416        }
399417
400         // CAN'T centre on country, (lat,lng), as we don't know whether either of lat or lng has gone past the edge
401         //north = lat + (v_tmp_count/2);
402         //south = lat - (v_tmp_count/2);
403         //east = lng + (h_tmp_count/2);
404         //west = lng - (h_tmp_count/2);
405
406         // hopefully we don't exceed +90/-90 lat and +/-180 longitude
407         // "Longitude is in the range -180 and +180 specifying coordinates west and east of the Prime Meridian, respectively.
408         // For reference, the Equator has a latitude of 0Â°, the North pole has a latitude of 90Â° north (written 90Â° N or +90Â°),
409         // and the South pole has a latitude of -90Â°."
410
418        // NOTE: Can't centre on country, (lat,lng), as we don't know whether either of lat or lng has gone past the edge
419
420        // Hopefully we don't exceed +90/-90 lat and +/-180 longitude
411421        /*
412422        System.err.println("north = " + north);