I want to create a grid spawning the whole globe. The grid is used to measure a density value by counting the number of certain spatial objects in each grid cell.
To create the grid, I have created multiline polygons, both using a script of my own, and the function suggested here: How to create a regular polygon grid in PostGIS? . Both algorithms loop from -90 .. 90 , -180 .. 180 in a fixed step size creating the multiline polygons.
I have two problems.
First, adjacent cells share a separating line, making objects on it counting towards two or more cells. I could subtract a very small value from corners, but this risks loosing objects when they come to lay exactly on the original line. The question is thus if there is a constant for the absolute minimum step value that I could use to guarantee that one point exactly lays next to another with no space inbetween.
Second, it seems the algorithm generates invalid geometries. e.g when I compute the square meters of a grid (for the density)
SELECT ST_Area(ST_GeographyFromText('POLYGON((-15 0,-15 5,-10 5,-10 0,-15 0))'))
throws an error
ptarray_area_spheroid: cannot handle ptarray that crosses equator
If I avoid the geography type, and use a geometry there is no global projection that outputs the correct size of all grids. e.g
Select ST_Transform( ST_GeomFromEWKT('SRID=4326;POINT(-180 90 0)'), 32630 )
couldn't project point (-180 90 0): latitude or longitude exceeded limits (-14)
How could I generate a grid of valid geometries that covers the whole globe?