[mapserver-users] Intersection of rectangle and circle

P Kishor punk.kish at gmail.com
Sat May 10 09:51:10 EDT 2008


On 5/10/08, Sucharita Samuel <iworktech.sucharita at gmail.com> wrote:
>   Hi Kishore,
>
>   I hope the following explanation will make the problem clear to you,
>
>   I have a map image (of India with states marked on it. Each state is a
> feature). When the user clicks on any position of the map, I draw a circle
> of 5km radius around the clicked point. Now  I want to find out the the
> states that are completely covered by the circle, and the percentage of the
> other states that lie inside the circle.
>
>  I have drawn the circle using a bounding rectangle. Now the problem is, if
> there is a very small state that lies in any four corners of the rectangle,
> but not actually inside the circle, my algorithm considers it to be lying
> inside the circle as the state actually lies within the boundaries of the
> bounding rectangle.
>
>  I need to find out the states that actually lie inside the circle, the
> states that are completely excluded and the percentage of states that
> partially lie inside the circle(and not the bounding rectangle)
>
> Can You help me with this?

Sorry, I can't help you with this, but I am pretty sure you cannot
solve the above problem with just MapServer. You will either need to
script a solution, or use PostGIS to be able to determine poly-in-poly
as well as % overlap. For what you want to do, PostGIS would be the
most appropriate tool as even scripting would be complicated. If I
recall correctly, someone on the PostGIS list was asking recently
about determining % overlap of polys. You can search the PostGIS
archives for that thread.

Using the bounding box is applicable only for simplistic solutions,
and it won't work for the scenario that you are describing above.



>
> Thanks,
> Sucharita
>
>
> On Fri, May 9, 2008 at 6:41 PM, P Kishor <punk.kish at gmail.com> wrote:
> > Let's clarify a few things first --
> >
> >
> > On 5/9/08, Sucharita Samuel <iworktech.sucharita at gmail.com> wrote:
> > > Hi friends,
> > > I need to find the intersection of a rectangle and circle.
> >
> > what exactly do you need to find?
> >  - the points at which they intersect?
> >  - whether or not they intersect?
> >  - the overlapping area of their intersection?
> >  - whether the circle is contained in the rect?
> >  - whether the rect is contained in the circle?
> >
> >
> >
> >
> > > As you
> > >  must be aware that a  circle in mapserver terminology is a shapeobject
> > > drawn
> > >  using the upper left and bottom right co-ordinates of a rectangle.
> >
> > I am now aware of that at all. My MapServer is extremely rusty, but I
> > remember drawing circles using MapScript and an equation that provided
> > the center of the circle and the radius. As you can see, there are
> > more than one ways to do it.
> >
> >
> >
> > >      In the above case I get the intersection of two rectangles, but as
> the
> > >  circle lies inside the rectangle, i am not able to find whether my
> first
> > >  rectangle intersects with the bottom corner of the rectangle(that
> contains
> > >  the circle), which is not part of the circle.
> > >
> >
> > once again, your question is not clear. If a circle 'C' lies inside
> > rectangle R, then the minimum bounding rectangle (MBR) of the circle
> > 'C' (which is always a square) will lie completely within 'R'.
> > Depending on your definition of intersection, there may or may not be
> > any intersection at all.
> >
> >
> >
> > > I am using ASP.NET. Any solution in this case would be of great help.
> > >
> >
> >
> > ASP.NET is irrelevant here. Figure out clearly what you want to
> > achieve, solve the problem as an algorithm problem, then you can
> > implement it in any language you want to use.
> >
> > As is, at least to me, your question is not clear at all.
> >
> >
> > > Thanks in advance,
> > > Sucharita
> > >
> > >
> > _______________________________________________
> > mapserver-users mailing list
> > mapserver-users at lists.osgeo.org
> > http://lists.osgeo.org/mailman/listinfo/mapserver-users
> >
>
>


-- 
Puneet Kishor


More information about the mapserver-users mailing list