# Does inpolygon work for latitudes and longitudes on the surface of the earth?

20 views (last 30 days)
Rob Dean on 23 Sep 2019
Edited: Bruno Luong on 28 Sep 2020
Just wondering if inpolygon will work correctly if using lat/lons on the surface of the earth for the points and polygons. Or would they need to be mapped to 2D/cartesian points?

Bruno Luong on 23 Sep 2019
A polygon in lat/lon will NOT map to a "polygon" on the sphere. A "polygon" on the sphere composed by edges that are grand circles - geodesic of the sphere (and the sum of the angles of the corners > 360 degree), which in turns is NOT a polygon in a cartesian space.

Jared Hoy on 28 Sep 2020
I need to detemine if a point on the surface of the sphere is within a region on the surface of the sphere. From what is stated here, inpolygon will not work for this? I figured that inpolygon was simply determining if the coordinates of the point exceeded the values of the coordinates of the region boundaries. I dont see why this wouldn't work for a signed latitude and a longitude. If possible, could you please explain a little more why this does not work, I am not quite following.
Would there be a better tool for this? Would "ingeoquad" be better?
Thanks
Bruno Luong on 28 Sep 2020
Because a constant latitude line is NOT a great circle.
If you take a fly from europe to US/canada (or the opposite) between 2 cities that have the same latitude, you'll see the air-plane goes north to halfway then go south. It doesn't have a constant latitude on the trajectory.
If you plot a "polygon" by enlarge on the left/right airplane route on the earth surface by - said 10 km from each side - the airplane trajectory in inside this "polygon".
However if you enlarge the polygone projected on the earth longitude/latitude map of the destination/arrival by a straight line on the 2D map, the air-plane will goes out (since it goes north, the latitude is increasing for half way).
So no you cannot use in-polygon directly on longitude/latitude 2D map.
This happens if you have you polygone vertexes that are far-away so that the earth radius is not negligible.
Obviously "ingeoquad" suffers the same drawback. However at least it specifieds what it does and returns.
If you want to know how a polygonal differs from a lon/lat quadrant, takes a look at this spherical Voronoi diagram, each cell is a polygon ohn sphere, NOT a latitude longitude quadrant.
BTW topologically there is no sense to speak about inside/outside a polygon of a sphere. Take a polygonal as the equator, whet is the inside? half-spehere north side? south side? Any polygonal divide earth surface in 2 parts, each is bounded (granted there is one larger than other in term of area), but if you cut something similar to euler spiral it quite hard to tell what is inside, what is outside.

Sean de Wolski on 28 Sep 2020
You need to project lat/lon into x/y using an appropriate projection for the region you're focused on. Then inpolygon (or polyshape) can be used. Before that, you may want to use interpm to create many points along the boundaries.
https://www.mathworks.com/help/releases/R2020b/map/ref/projcrs.projfwd.html

R2019b

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!