[mapserver-users] How to draw a circle with a centroid and radius

P Kishor punk.kish at gmail.com
Mon May 12 09:46:38 EDT 2008


Sucharita,

Did you read some of the things I wrote in my reply to you? Look below
for more...

On 5/12/08, Sucharita Samuel <iworktech.sucharita at gmail.com> wrote:
> Hi Friends,
>                I am really stuck up with this for a long time now. As far as
> I have googled, I have found that to draw a circle, either using a mapfile
> or dynamically using a mapscript, the circle has to be defined by two set of
> points of its bounding rectangle. The image that I get on my screen is a
> circle (because the layer is defined as a circle), but to draw this circle,
> a set of two points is used which ultimately is a line. I will provide my
> code sample below,
>
> DrawCircle(double x, double y, double dRadius)
> {
>          double minx = x - dRadius;
>          double miny = y + dRadius;
>          double maxx = x + dRadius;
>          double maxy = y - dRadius;
>
>          //upper left corner of the bounding rectangle
>           pointObj oPointMin = pixel2point(new pointObj(minx, miny, 0, 0));
>
>         //lower right corner of the bounding rectangle
>          pointObj oPointMax = pixel2point(new pointObj(maxx, maxy, 0, 0));
>
>          lineObj oLine = new lineObj();
>          oLine.add(oPointMin);
>          oLine.add(oPointMax);
>          shapeObj oShp = new
> shapeObj((int)MS_SHAPE_TYPE.MS_SHAPE_LINE);
>           oShp.add(oLine);
>
>         // Creation of a temporary layer (for circle)
>                        layerObj oTempLayer = new layerObj(map);
>                         oTempLayer.name = "UserCircle";
>                         oTempLayer.status = 1;
>                          oTempLayer.type = MS_LAYER_TYPE.MS_LAYER_CIRCLE;
>                         classObj oTempClass = new classObj(oTempLayer);
>                         styleObj oStyle = new styleObj(oTempClass);
>                          oStyle.outlinecolor.setRGB(0, 0, 0);
>                         oStyle.color.setRGB(255, 227, 255);
>                         oTempLayer.addFeature(oShp);
>
>          In the last line, I add the shape object to the temporary layer and
> then draw that layer which thus gives me a circle. But now, I want to find
> the intersection of this circle with the underlying layer features which I
> am unable to do, as the circle is not actually a circle or polygon that will
> give me the intersection and thus the area of intersection.
>
> The link
> http://lists.dmsolutions.ca/pipermail/mapserver-users/2004-March/016983.html
>  has a code sample to draw a circle with polygon but that code doesn't seem
> to work because it does not give me a circle but some other shaped polygon.

That shape is indeed a circle. Think about it... a circle is a polygon
with points that lie on the circumference. Right? There are infinite
such points, so the more points you draw the smoother will be your
circle. Of course, too many points becomes pointless because a coarse
circle can be good enough for one's purpose. The code that is
referenced in the email above uses a 10 degrees increment to place 37
points on the circle's circumference (the last point is the same as
the first point).

Ok, that takes care of the circle. Your problem doesn't end with
creating a circle. You want to find out the percentage overlap with a
polygon. My MapServer/MapScript knowledge is extremely rusty, but I am
not sure there is any way to do that with MapServer. It may be
possible with MapScript (I am actually writing some poly-on-poly
routines in Perl, but they are difficult to do). To do a poly-on-poly
overlay, you will likely have to implement PostGIS.

You have been asking this question for a while on this list and you
haven't really received any definitive answer other than mine. Maybe
you should start with determining the capabilities of
MapServer/MapScript first to evaluate if that can solve your problem.



>
>
> Friends, please help me with this problem.
>
> Thanks,
> Sucharita.
>
> _______________________________________________
>  mapserver-users mailing list
>  mapserver-users at lists.osgeo.org
>  http://lists.osgeo.org/mailman/listinfo/mapserver-users
>
>


-- 
Puneet Kishor http://punkish.eidesis.org/
Nelson Institute for Environmental Studies http://www.nelson.wisc.edu/
Open Source Geospatial Foundation (OSGeo) http://www.osgeo.org/


More information about the mapserver-users mailing list