Reputation: 3465
I have a LineString
geometry feature with weight in GeoJSON. Now I want to determine coordinates of 4 vertices of that rectangle. I know how to calculate on plane geometry by using line equation. But on geographic geometry, I'm new. I already read how to calculate one unit of latitude and longitude decimal degree as well as metres per pixel but I'm still confused how to add them to a given point to calculate wanted points. My problem is like this:
Given:
Result: Coordinates of 4 vertices of rectangle
For example: Two point of LineString
A (10.767008,106.665884)
B (10.767715,106.667151)
Weight of LineString
is 6 pixels at zoom level 18
I can calculate width of rectangle (distance between these two points), broadth of rectangle (number of metres per pixel, then multiply). How can I use them to calculate 4 vertices' coordinates of this rectangle?
All of my calculated cases are on small scale (part of one street of a city) so I think altitude can be excluded
Upvotes: 0
Views: 719
Reputation: 5927
It sounds like you want to get the "extent" of your linestring (a.k.a. the "bounding box" of your linestring). You can use turf.js' turf-extent function to get the extent of your GeoJSON linestring. That extent will be the rectangle you're looking for, as a GeoJSON polygon. You can then use other turf.js functions on that polygon to get the width, length, area, etc
Upvotes: 1