LukasKroess
LukasKroess

Reputation: 357

Calculate shape from WMS BBOX in projection

I want to write a little wms service in php, querying polygons from a mariadb database and use it with leaflet.

leaflet.js together with proj4leaflet.js calls my service with a BBOX parameter, supplying X and Y of the northwestern point and X and Y for the southeastern point. Out of these two parameters, the wms service is supposed to calculate the shape that is to be covered by this call.

Usually, if the points in the coordinate system were in perfect 90 degree angles to each other, you could easily calcualte the area with these four points:

X1,Y1  X2,Y1  X2,Y2  X1,Y2

however, this does not account for the 'skew' of CRS:25832 and I end up having annoying gaps in my grid.

My next approach, was to find the northeast point mathematically, like so (pseudo)

DIST = DISTANCE(POINT(X1,Y1), POINT(X2,Y2)) / SQRT(2);
NE = POINT(X1 + DIST, Y2 + DIST)

(and doing the same for the southwestern point).

The resulting grid has way smaller gaps, but is still far from perfect.

How would I calculate the actual corner points of the diamond(?) shape of a map tile?

Ideally, this could be done entierly in sql, using virtual columns, but I guess I could live with a php solution.

Edit:

here are some picutes of my actual data, to illustrate my problem. Squares 1,2,3 and 4 should line up perfectly, but don't.

enter image description here

On closer inspection, you see, that SE of 1 matches up with NW of 4 (pink), because these points get indicated by leaflet.

enter image description here

Points SW of 2 (purple) and NE of 3 (blue) should also be on the exact same position, but aren't.

Upvotes: 0

Views: 74

Answers (0)

Related Questions