I have a collection of GeoJSON features as Polygon & MultiPolygon which are saved in MongoDB. Many among them are in rectangular or square shape, while others are odd shaped. How can I find all the four corner (top left, top right, bottom left and bottom right) points if that feature is in rectangular or square shape?
I first tried to filter those features which has only five co-ordinates, so that those points will be corner co-ordinates essentially. But some of them are having more than five co-ordinates but as shape they are rectangle or square. Check below given feature examples. First is odd shaped feature, second is rectangle with redundant points and third is rectangle with 4+1 points.
I checked TurfJS, but didn't find any helpful method. BBox gives me non-rotated rectangle, which is not useful because it can also give bbox for non-rectangular shape also.
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
-102.61383274599996,
32.37585257400008
],
[
-102.61764297999997,
32.375000929000066
],
[
-102.62239479299996,
32.388750307000066
],
[
-102.60775890199994,
32.392205895000075
],
[
-102.60566771099997,
32.392699906000075
],
[
-102.60510962499995,
32.39093294600008
],
[
-102.61772064899998,
32.387951290000046
],
[
-102.61383274599996,
32.37585257400008
]
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
-102.59602204999999,
32.36491866700004
],
[
-102.59952111499996,
32.37500140000003
],
[
-102.60087906199999,
32.378914276000046
],
[
-102.58443896599994,
32.38292495700006
],
[
-102.58184811899997,
32.37500015000006
],
[
-102.57980711899995,
32.36875659300006
],
[
-102.59602204999999,
32.36491866700004
]
]
]
]
}
},
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "MultiPolygon",
"coordinates": [
[
[
[
-102.62506373399998,
32.34304188700003
],
[
-102.64139887699997,
32.33901489700003
],
[
-102.64604796299994,
32.352882700000066
],
[
-102.62962431499994,
32.35679300500004
],
[
-102.62506373399998,
32.34304188700003
]
]
]
]
}
}
]
}
https://bl.ocks.org/Xyroid/raw/800dafa55111ce139b8158c62f858c98/