Changeset 33853

Show
Ignore:
Timestamp:
21.01.2020 21:58:29 (6 weeks ago)
Author:
ak19
Message:

Handling map coordinates that are horizontally excessive (beyond allowed longitudes of -180 and 180). With the code now dealing with both points too far north (beyond allowed latitude of 90) and too far east or west, the code generating the geojson map data can now deal with very large count values as when dealing with numPages rather than the smaller numSites.

Files:
1 modified

Legend:

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

    r33812 r33853  
    1212import java.util.List; 
    1313import java.util.Map; 
     14 
     15//import java.lang.Math; //automatically imported apparently 
    1416 
    1517import org.apache.commons.csv.*; 
     
    328330 
    329331    // create rectangular "histogram" for each country code 
    330     private Geometry toPolygon(JsonObject json, int count, int HISTOGRAM_WIDTH) { 
     332    private Geometry toPolygon(JsonObject json, final int count, final int HISTOGRAM_WIDTH) { 
    331333    int half_width = HISTOGRAM_WIDTH/2; 
    332334    double vertical_factor = 1.0; 
    333335     
    334     Double lng = json.get("lng").getAsDouble(); 
    335     Double lat = json.get("lat").getAsDouble(); 
     336    final Double lng = json.get("lng").getAsDouble(); 
     337    final Double lat = json.get("lat").getAsDouble(); 
    336338 
    337339    String countryCode = json.get("countrycode").getAsString(); 
     
    345347    // to grow northwards. 
    346348    Double north = lat + (vertical_factor * count); 
     349     
    347350    while (north > 90) { 
    348351        // recalculate north after decreasing histogram's vertical growth 
     
    355358    Double west = lng - half_width; 
    356359    Double south = lat; 
     360         
     361    // 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. 
     363    if((east + Math.abs(west)) > 360 || east > 180 || west < -180) { 
     364        half_width = HISTOGRAM_WIDTH/2; // reset half_width 
     365         
     366        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); 
     369 
     370        /* 
     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"); 
     376        */ 
     377 
     378        north = lat + v_tmp_count; 
     379        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 
     383        if(north > 90) { 
     384        // centre vertically on lat 
     385        north = lat + (v_tmp_count/2); 
     386        south = lat - (v_tmp_count/2); 
     387        } 
     388 
     389        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 
     393        }        
     394        else if(east > 180.0) { 
     395        double h_diff = 180.0 - lng; // the country's longitude (lng) is h_diff from the eastern edge 
     396        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 
     398        } 
     399         
     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 
     411        /* 
     412        System.err.println("north = " + north); 
     413        System.err.println("south = " + south); 
     414        System.err.println("east = " + east); 
     415        System.err.println("west = " + west); 
     416        */ 
     417    } 
    357418     
    358419    List<List<Position>> outerList = new LinkedList<List<Position>>();