View Full Version : How to determine Shapes inside another Shape

jasper7

10-11-2011, 05:37 AM

Hi all

I'm looking to see how I can in code, determine if any shape (Freeform) is fully or partial inside another shape (Circle)

I've developed all the code to draw Circles around Pushpins (Drive Distance), I need now to write the code to see what shapes are within (Fully or Partialy) in the Circle.

If not I will need to take another approach, and import all the Sites as Pins, which have there region (Shape Name) as a Field and then Read each Site inside the Circle and add any new Shape name to a list (Not my preffered solution)

Thanks

Steve

Winwaed

10-11-2011, 07:33 AM

The general case is very complicated - for example all of a vertices points can be inside a shape and yet they may still partially overlap.

You're comparing a shape to see if it is contained within a circle, which greatly simplifies things. Simply measure the distance from each vertex of the shape to the centre of the circle. If the distances are all less than the radius of the circle, the shape *must* be inside the circle. If some are and some aren't, then it is partially inside.

This will work if your circle has a radius of less than a quarter of the Earth's circumference (I suspect this is at or beyond the MapPoint practical maximum), and if you do your geometry correctly (measure the distance using MapPoint's API or use the Haversine Formula - avoid Cartesian approximations, they'll bite you eventually!).

Richard

jasper7

10-11-2011, 07:53 AM

Richard, Thanks

I understand the masuring bit and comparing.

As I only need to find out if it any part of the Freeform is inside I can stop iterating the Vertex once the measure is less than the Radius.

I'll need to look up what a is Vertex etc and how to find them.

Concern I have with this method, is that at the moment I have 400 Circles and 160 Freeform shapes, with loads of handle points Wonder how hot the PCU will get crunching that lol.

Take it I would need to do each Circle against each FreeForm.

Have you any guidance on Vertex's

Steve

jasper7

10-11-2011, 12:59 PM

Richard

Many Thanks for the Solution, all programmed and woerking great out o excel

Cheers

Steve

intMeasure = oMap.Distance(oLocFreeFrmVert, oLocRadius)

If intMeasure < (oShpRadius.Width / 2) Then

blSA4InRadius = True

' After Interating through all Vertices in Shape if one is in Circle set True, Indicates to write out Shape Name to excel

End If

Winwaed

10-12-2011, 08:59 AM

Excellent!

Yes with that many shapes and circles, it could be slow. If you are happy using the Haversine Formula, you could store the circles in your code rather than querying them in MapPoint every time. This would speed things up but you would still have to iterate over all points in all freeform shapes.

Richard

Powered by vBulletin® Version 4.2.2 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.

Search Engine Friendly URLs by

vBSEO 3.6.1