TransWikia.com

Visualizing bounding box as polygon

Geographic Information Systems Asked by user3044923 on May 6, 2021

I try to make plugin in QGIS that compare 2 bounding box data, ex:

(-32.61442167739459, -32.017601026186576, 13.015663782506067, 13.428145228091406)

and

(-38.6102467739459, -38.017601026186576, 33.01563382506067, 33.624945228091406)

and want to picture it in a square or polygon like shape.

Does QGIS have a module in Plugin that can do such a thing?

2 Answers

Yes, it's the QuickWKT plugin (WKT = "Well-Known Text"). The bounding box would be treated as a polygon, and WKT would look like:

'POLYGON(x1 y1, x1 y2, x2 y2, x2 y1, x1 y1)'

Note that any polygon shape is possible, but coordinates following this model will generate a rectangle, which is what you want for a bounding box. You can't get away specifying only two corners, as you have in the question, you have to specify all four corners, and the first and last coordinates have to be the same. That's how WKT indicates that the polygon is closed.

A screenshot with the WKT for your first example:

QuickWKT with Well-Known Text for a rectangle in WGS84.

Answered by Lee Hachadoorian on May 6, 2021

See https://shapely.readthedocs.io/en/latest/manual.html#shapely.geometry.box

>>> import shapely.geometry
>>> bbox = (-125.056143, 31.8679566, -112.9017855, 42.4407224)
>>> polygon = shapely.geometry.box(*bbox, ccw=True)
>>> polygon
<shapely.geometry.polygon.Polygon object at 0x7fb070a9bf60>
>>> polygon.bounds
(-125.056143, 31.8679566, -112.9017855, 42.4407224)
>>> polygon.wkt
'POLYGON ((-112.9017855 31.8679566, -112.9017855 42.4407224, -125.056143 42.4407224, -125.056143 31.8679566, -112.9017855 31.8679566))'

For the example data given:

>>> bbox1 = (-32.61442167739459, -32.017601026186576, 13.015663782506067, 13.428145228091406)
>>> bbox2 = (-38.6102467739459, -38.017601026186576, 33.01563382506067, 33.624945228091406)
>>> polygon1 = shapely.geometry.box(*bbox1, ccw=True)
>>> polygon2 = shapely.geometry.box(*bbox2, ccw=True)
>>> polygon1.bounds
(-32.61442167739459, -32.017601026186576, 13.015663782506067, 13.428145228091406)
>>> polygon2.bounds
(-38.6102467739459, -38.017601026186576, 33.01563382506067, 33.624945228091406)
>>> polygon1.wkt
'POLYGON ((13.01566378250607 -32.01760102618658, 13.01566378250607 13.42814522809141, -32.61442167739459 13.42814522809141, -32.61442167739459 -32.01760102618658, 13.01566378250607 -32.01760102618658))'
>>> polygon2.wkt
'POLYGON ((33.01563382506067 -38.01760102618658, 33.01563382506067 33.62494522809141, -38.6102467739459 33.62494522809141, -38.6102467739459 -38.01760102618658, 33.01563382506067 -38.01760102618658))'

Answered by Darren Weber on May 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP