# Regular grid for whole planet

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 (n main loop) and North (in nested loop) using 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 ~510 squared meters. So, the total number of cells should be about 4 billion. What is wrong? What should I do to solve the problem correctly?

• It isn't possible to create a rectangular grid that covers the Earth, because the Earth isn't rectangular. Each polygon is a spheroidal trapezoid. – Vince Nov 16 '18 at 17:46
• Translate meters into fractional degrees 350 m = 0.003149748... – Cyril Nov 17 '18 at 16:29
• The cells with a size of 350x350 meters with your limitations should be greater than 6,168,787,341, if I'm not mistaken :-), these are rough calculations of cells measuring 360x170 degrees ... – Cyril Nov 17 '18 at 17:00
• crosspost: stackoverflow.com/questions/53342859/… – scai Nov 19 '18 at 7:06