Openstreetmap rectangular grid for whole planet

93 views Asked by At

I`m trying to generate rectangular grid for whole world with fixed cell size in 350 meters (width and height are equals).

What i tried to do:

1) in main loop iterate trough longitude in range [-180; 180]

2) in nested loop iterate trough latitude in range [-85.06; 85.06] (Web mercator bounds)

3) increment cells bound to 350 meters on East (in main loop) and North (in nested loop) using Java GeographicLib Geodesic.WGS84.Direct().

Java code:

double lon_min = -180;
double lon_max = 180;
double lat_min = -85.06;
double lat_max = 85.06;

double lon_max_c = lon_min;
double lon_min_c = lon_min;

int grid_x = 0;
int grid_y = 0;
int cell_id = 0;

while(lon_max_c < lon_max)
{
    double lat_min_c = lat_min;
    double lat_max_c = lat_min;

    lon_min_c = lon_max_c;
    GeodesicData g = Geodesic.WGS84.Direct(lat_min_c, lon_min_c, 90, 350);

    boolean isXlast = g.lon2 > lon_max || (lon_min_c > 0 && g.lon2 < 0);
    lon_max_c = isXlast? lon_max : g.lon2;

    grid_y = 0;

    while(lat_max_c < lat_max)
    {
        lat_min_c = lat_max_c;

        GeodesicData g1 = Geodesic.WGS84.Direct(lat_min_c, lon_min_c, 0, 350);

        boolean isYlast = g1.lat2 > lat_max;
        lat_max_c = isYlast? lat_max : g1.lat2;

        System.out.print("\rid: " +  cell_id + " lon: " + lon_max_c + " lat: " + lat_max_c);

        grid_y = grid_y + 1;
        cell_id = cell_id + 1;
    }
    grid_x = grid_x + 1;
}

As a result, ~530 million cells were generated. Howewer, area of whole planet is ~510M squared kilometers. So, the total number of cells should be about 4 billion. I'm pretty new to geodesic math, so what is wrong? What should I do to generate this grid correctly?

1

There are 1 answers

0
reducing activity On

rectangular grid for whole world with fixed cell size in 350 meters (width and height are equals)

What you are trying to do is impossible as Earth is not a rectangle. See https://en.wikipedia.org/wiki/Map_projection for starting point to learn more.

While this effect can be ignored for small areas, on scale like "longitude in range [-180; 180]", "latitude in range [-85.06; 85.06]" ignoring it is not feasible.