Changeset 33796


Ignore:
Timestamp:
2019-12-12T15:42:19+13:00 (4 years ago)
Author:
ak19
Message:

Instead of a hack for US' count being too great that its histogram goes past the max latitude North, added more general code to widen histograms in cases where the value of count produces too great a latitude North value for histograms, as other countries like France and China also needed the same solution.

File:
1 edited

Legend:

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

    r33794 r33796  
    8888    for(JsonElement obj : countryCountsJsonArray) {
    8989        JsonObject json = obj.getAsJsonObject();
    90         String countryCode = json.get("_id").getAsString();
     90        String countryCode = json.get("_id").getAsString().toUpperCase();
     91        // set the property back as uppercase and with property name "countrycode" instead of "_id"
     92        json.remove("_id");
     93        json.addProperty("countrycode", countryCode);
     94       
    9195        int count = (int)json.get("count").getAsDouble();
    9296       
     
    215219        JsonObject json = obj.getAsJsonObject();
    216220       
    217         String countryCode = json.get("_id").getAsString();
     221        String countryCode = json.get("countrycode").getAsString();
    218222        String region = json.get("region").getAsString();
    219223        int count = json.get("count").getAsInt();
     
    244248    Double lat = json.get("lat").getAsDouble();
    245249
    246     String countryCode = json.get("_id").getAsString();
    247 
    248     // US is a special case. Count is too high by a factor of 8.
    249     // So reduce height by twice that factor, and width by twice that factor too.
    250     // (A factor of 8 makes north at +125 too high for latitude,
    251     // see http://www.learnz.org.nz/sites/learnz.org.nz/files/lat-long-geo-data-01_0.jpg)
    252     if(countryCode.equals("US")) {
    253         half_width = 16 * half_width;
    254         vertical_factor = vertical_factor/16.0;
    255     }
     250    String countryCode = json.get("countrycode").getAsString();
     251
     252
     253    //create the 4 corners of the rectangle
     254    // West is negative, east is positive, south is negative, north is positive
     255    // See http://www.learnz.org.nz/sites/learnz.org.nz/files/lat-long-geo-data-01_0.jpg
     256    // But since the histograms grow vertically/northwards and we can't go past a latitude of 90,
     257    // to compensate, we increase the width of the histograms by the same factor as our inability
     258    // to grow northwards.
     259    Double north = lat + (vertical_factor * count);
     260    while (north > 90) {
     261        // recalculate north after decreasing histogram's vertical growth
     262        // by the same factor as we increase its width
     263        vertical_factor = vertical_factor/2.0;
     264        half_width = 2 * half_width;
     265        north = lat + (vertical_factor * count);
     266    }
     267    Double east = lng + half_width;
     268    Double west = lng - half_width;
     269    Double south = lat;
    256270   
    257271    List<List<Position>> outerList = new LinkedList<List<Position>>();
     
    259273    outerList.add(points);
    260274
    261     //create the 4 corners of the rectangle
    262     // West is negative, east is positive, south is negative, north is positive
    263     // See http://www.learnz.org.nz/sites/learnz.org.nz/files/lat-long-geo-data-01_0.jpg
    264     Double east = lng + half_width;
    265     Double west = lng - half_width;
    266     Double north = lat + (vertical_factor * count);
    267     Double south = lat;
     275   
    268276    points.add(new Position(west, south)); // Position(lng, lat) not Position(lat, lng)
    269277    points.add(new Position(west, north));
Note: See TracChangeset for help on using the changeset viewer.