Closed mdorda closed 1 month ago
I agree that the :get_bbox()
handling is inconsistent. There are two reasons for that:
get_bbox()
existed before the advanced geometry handling, so in some sense it is a left-over.All of this doesn't mean that it wouldn't make sense to have an :envelope()
function that works on any geometry and returns the envelope.
All of this would be very easy to implement. Frankly the biggest problem with this is a question of data types. Usually (i.e. in PostGIS) the envelope function returns another geometry object. This would be great for importing into the database. But what if you need the values in Lua, in the same way get_bbox()
returns them? It is unclear to me what users want here and how best to handle that. Any suggestions?
I can only speak for myself. And I find it much more practical to return single values: xmin, ymin, xmax, ymax. You can still work with them. For example, increase the bbox according to the individual geometries in a multipolygon under certain conditions (which in effect means, to filter out some polygons from multipolygon and get bbox for them).
But there could be two methods: :envelope()
and :envelope_box()
to get Postgis format for example. I have never been good at naming.
Maybe follow PostGIS here. Have envelope()
returning a Polygon and then four additional functions X/Ymin/max
. Or would that require too much calling back and forth?
Sounds great to me. That would cover all my requirements.
The get_bbox()
function is now available for geometries. Give it a try.
Thank you! That was pretty fast :-) Works great. For example, you can now bbox over filtered geometry, for example ignoring parts of the geometry that are less than 0.1 of the total area.
local total_area = self.geometry:spherical_area()
for g in self.geometry:geometries() do
local area_ratio = g:spherical_area() / total_area
if area_ratio > 0.1 then
if xmin == nil then
xmin, ymin, xmax, ymax = g:get_bbox()
else
local gxmin, gymin, gxmax, gymax = g:get_bbox()
xmin = math.min(xmin, gxmin)
ymin = math.min(ymin, gymin)
xmax = math.max(xmax, gxmax)
ymax = math.max(ymax, gymax)
end
end
end
This is not a bug report, but rather a feature request, or a request for advice.
According to your documentation, method
:get_bbox()
is available for the parameter table (object). Which works great for the most cases. But I find it very limiting when I need to work with multipolygons.I need to add centroid and bboxes to all (multi)polygons. It seems to be very straightforward:
and then just call it when writting:
But it gets tricky when you need to work a bit more complex with multipolygons. Specifically: to get a centroid and bbox only from the largest part of the multipolygon.
It is easy for centroid:
But it cannot be done for bbox, becasue it is not a geometry method.
I admit that I have a very specific requirement, but purely from the logic of things,
:get_bbox()
seems to me to be a geometry thing and I would expect this method to be directly on geometry. Similar to:centroid()
or:area()
(documentation). It looks pretty inconsistent to me that way.Did I miss something? Is there any way to achieve this?
Thank you so much!