68 views (last 30 days)

Show older comments

I have geographic plotting data (lat lon or X Y in this case) for counties and for storm surge levels. I need to see if the storm surge probability lines come in contact with a given county. Here is what the data looks like.

This is the very last part of my thesis model so any help would be FANTASTIC! Thanks so much

Kenny

Image Analyst
on 24 Jan 2014

John D'Errico
on 19 Aug 2021

John D'Errico
on 19 Aug 2021

Edited: John D'Errico
on 19 Aug 2021

There is a simple solution. It involves two tests, both of which are essentially vectorized. In fact, now that I think of it, there are several solutions that will be adequate, and fairly efficient.

And it depends on exactly what you are looking to do.

Solution 1: (3 steps)

Test if any vertex of polygon 1 lies inside polygon 2. If any vertex does lie inside, then there is SOME intersection between the polygons.

Test if any vertex of polygon 2 lies inside polygon 1. THe same comment applies.

Test if there is any intersection of the edges of the two polygonal regions. You can do this efficiently using Doug Schwarz's intersections code, as found on the file exchange.

I'm not sure what exactly you need to do, IF there is some intersection.

Solution 2: (this uses polyshapes.)

Convert each polygon into a polyshape.

Compute the intersection of the two polyshapes. The result will be a new polyshape. If it is the null polyshape, then there was no intersection.

You can do other things using solution 2. For example, if you wish to test if polygon 1 is entirely inside polygon 2, then compute the area enclosed by polygon1. Next, compute the union of the two polyshapes, and the area of that. If that area is the same as the area of polyshape 1, then you know that polyshape 2 was entirely inside polyshape 1. Conversely, you can as easily test if 1 was inside 2, by computing the area of polyshape 2, and then comparing that to the union.

My guess is the polyshape solution is best, as it is simplest and may help you to do other computations.

Note that polyshapes were introduced in R2017b, so as long as you have a moderately recent release, you will have them.

Steven Lord
on 19 Aug 2021

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

Start Hunting!