-1

I've got the whole world divided into polygons (GEOJSON - FeatureCollection - MultiPolygon). Those polygons are FIRs (Flight Information Regions). Placed a LineString on the map I need to understand through which polygons it passes through. The LineString represents the flight plan of an aircraft.

I'm including a screenshot to better represent how it works:

enter image description here

I wonder what would be the best way to find all those polygons.

This is my FIR Feature Collection: enter image description here

I've got multiple lines, so they are added as a GEOJSON MultiLineString, but in the end each one is a LineString.

So far the idea that I have is to use https://turfjs.org/docs/#along and call it every N amount of distance (e.g. 10 km) and call MapBox QueryRenderedFeatures (https://docs.mapbox.com/mapbox-gl-js/api/map/#map#queryrenderedfeatures) to get each feature, but I'm not sure if that's the best approach, I've got issues with that function and I'm not sure if it will work if some of the polygons are not in the screen view for long routes.

I would appreciate any help or indication, I tried to find more information on it, but I'm not sure if I'm searching for it correctly, it seems like something people have experienced in the past.

Adam M.
  • 1,071
  • 1
  • 7
  • 23

1 Answers1

0

So, if you find yourself in a situation where you need to calculate what Polygon or MultiPolygon are being passed through by a LineString, then here is the solution that I came with and which worked for me:

  1. Assure your coordinates are of type LineString, use https://turfjs.org/docs/#lineString if necessary
  2. Create an array of coordinates along that line https://turfjs.org/docs/#along, for e.g. starting from the beginning, loop every N kilometers/miles, until the end of the LineString
  3. Loop your polygons https://turfjs.org/docs/#pointsWithinPolygon to see which points are within it, if there is at least one point, it means that the line crossed it.

I hope this will help anyone in the future. I hope someone else will be able to share any more elegant solutions if there are any.

Adam M.
  • 1,071
  • 1
  • 7
  • 23