In QGIS you can use "Extract nodes" to first get the corner points of your polygons. Then, using "Export/Add geometry columns" you can add x and y coordinates to those points. The results will be four lines of data though.
Another way is to copy paste the geometries from QGIS' map window into a text editor. You'll get the WKT representation of the polygons, e.g.
wkt_geom
POLYGON((-0.971664 0.453443,-0.516714 0.827044,-0.245552 0.432353,-1.001793 -0.224462,-0.971664 0.453443))
You can use minimum_bounding_rectangle()
function in Finding minimum-area-rectangle for given points?
For your GeoJSON text, to get "minimum area bounding rectangle (MABR)":
import numpy as np
data = {"type":"FeatureCollection",
"features":[{"type":"Feature",
"properties":{"osm_id":"1269601",
"type":"multipolygon",
"leisure":"pitch",
"sport":"soccer"},
"geometry":{
"type":"Polygon",
"coordinates":[[
[6.6131123,46.5124914],
[6.6129421,46.5125385],
[6.6127998,46.5125783],
[6.6126291,46.512626],
[6.6125308,46.5124593],
[6.6127016,46.5124121],
[6.6128452,46.5123724],
[6.6130153,46.5123244],
[6.6131123,46.5124914]]
]
}
}
]
}
# polygons can have holes, so, ["coordinates"][0] gives you boundary of polygon.
# If you have multipolygon, ["coordinates"][0][0] gives you the first polygon boundary.
geom = data["features"][0]["geometry"]["coordinates"][0]
mabr = minimum_bounding_rectangle(np.array(geom))
# OUT:
#array[[ 6.6131123 , 46.5124914 ],
# [ 6.61306213, 46.51231129],
# [ 6.6125308 , 46.5124593 ],
# [ 6.61258097, 46.51263941]]
data2 = dict(data) # copy data to data2
data2["features"][0]["geometry"]["coordinates"][0] = mabr.tolist()
Now, data2
is GeoJSON text with MABR of polygon. But it is always 'great equal' than source polygon. So, you can think of scaling down polygon by rate of source_polygon_area/mabr_area
.
Best Answer
One of the obvious solutions is this:
where radius of circles equals to Line_Length/sqrt(2). Four points shown will make a square. Unfortunately it gets tricky when each buffer intersects more than one buffer:
So, you have one diagonal of square, simply compute 2nd perpendicular to 1st using clone of your lines. Note you don't need to compute mid point. Simply use:
to call expression on field Shape of cloned table. You might need to start editing session first if clone sits in GDB.
Merge 2 line feature classes and dissolve to multipart using initial line id. Picture below shows minimum bounding geometries of dissolved lines:
Yes, I've misread the question in your hyperlink, unless he wanted rectangle but square.