Any solution to foreach the making of polygon ? #103
Answered
by
saibotk
StringNameEqualsThejazzman
asked this question in
Q&A
-
Hi, I'm developping an app where the customer can draw a polygon on openstreetmap, but the thing is that I don't know how many corner there will be on the polygon so I have to somehow foreach through the coordinates to make a polygon like this : $polygon = Polygon::make([
LineString::make([
Point::makeGeodetic(1, 1),
Point::makeGeodetic(2, 2),
Point::makeGeodetic(3, 3),
Point::makeGeodetic(1, 1),
]),
]); I have tried this but I knew it will not work $polygon = Polygon::make([
LineString::make([
foreach ($feature['geometry']['coordinates'][0] as $coordinate){
Point::makeGeodetic(1, 1),
Point::makeGeodetic(2, 2),
Point::makeGeodetic(3, 3),
Point::makeGeodetic(1, 1),
}
]),
]); Can someone help me ? |
Beta Was this translation helpful? Give feedback.
Answered by
saibotk
Dec 27, 2024
Replies: 1 comment 1 reply
-
@StringNameEqualsThejazzman Sorry for the late reply. You need to create the array of points outside of the polygon creation. Something like this, hope this helps :) $points = [];
foreach ($feature['geometry']['coordinates'][0] as $coordinate) {
$points[] = Point::makeGeodetic($coordinate[0], $coordinate[1]);
}
$polygon = Polygon::make([
LineString::make($points),
]); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
StringNameEqualsThejazzman
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@StringNameEqualsThejazzman Sorry for the late reply.
You need to create the array of points outside of the polygon creation.
Something like this, hope this helps :)