MapScript Documentation (Re: [Mapserver-users] Re: problem getting bounds of poly shape)

Lowell Filak lfilak at medinaco.org
Thu Sep 25 16:52:51 EDT 2003


The tcheck.pl sample does the same thing but I have not tested it in 4 yet.
Try "undef $lineObj;" before doing the queryByShape, I noticed it in the
tcheck.pl code and don't remember if it is there for just such an issue
or if this is something new in 4.
HTH
Lowell

The following message was sent by "Puneet Kishor"
<pkishor at geoanalytics.com> on Thu, 25 Sep 2003 15:00:55 -0500.

> Hi Lowell,
> 
> Thanks for you reply.
> 
> > -----Original Message-----
> > From: Lowell Filak [mailto:lfilak at medinaco.org] 
> ..
> > The code you sent before actually constructed a shapeObj instead of a
> > rectObj for the queryByRect.
> > This is probably a legal thing to do but I just have to ask - are you
> > sure the queryByRect is producing the correct result?
> 
> 
> Yeah, I think I mistyped the code in my email message, however, the
> problem still exists. Here is what I do... I create a circle shape with
> its origin on the mouse click, and use it to select features from
> another layer. I have $x0, $y0, and $radius (in map units, of course).
> 
> my $idlayerObj = getLayerByName("somelayer");
> my $shpObj = new mapscript::shapeObj($mapscript::MS_SHAPE_POLYGON);
> my $lineObj = new mapscript::lineObj();
> my $pointObj = new mapscript::pointObj();
> # make a circle
> for (my $i = 0; $i <= 360; $i = $i + 10) {
>   $pointObj->{x} = $x0 + (cos($i * (22 / 7) / 180) * $radius);
>   $pointObj->{y} = $y0 - (sin($i * (22 / 7) / 180) * $radius);
>   $lineObj->add($pointObj);
> }
> $shpObj->add($lineObj);
> $idlayerObj->queryByShape($mapObj, $shpObj);
> my $numbyshape = $idlayerObj->{resultcache}->{numresults};
> 
> The above results in $numbyshape equal to several hundred. That is wrong
> given my data. So, I do the following --
> 
> $shpObj->setBounds;
> my $rectObj = $shpObj->{bounds};
> $idlayerObj->queryByRect($mapObj, $rectObj);
> my $numbyrect = $idlayerObj->{resultcache}->{numresults};
> 
> This results in $numbyrect being the more correct 10 or 12.
> 
> Yup, the latter is correct... The data are essentially parcel centroids
> being selected in a 200 ft radius of the mouse click... 10-12 parcels
> within a 400 feet diameter circle makes sense. Not only the latter
> selection is correct, the shape and the selected points also draw
> correctly... The circle with 10-12 centroids within that circle.
> 
> Strange.
> 
> 
> 
> ..
> > > 
> > > I've added this in the bz as an enhancement request. Part of the
> > problem is that us 
> > > non-developers still have to first figure out whether or not our
> > problem lies with us 
> > > screwing up or with the code. We can only do that via the list. Of
> > course, once it is 
> > > determined that indeed the problem is a "bug" then it can 
> > be added to
> > the zilla.
> > > 
> > > 
> > > For example, I am still having a problem with queryByShape, and I
> > don't know if I am 
> > > doing something wrong or if this is a bug.
> > > 
> > > My problem is thus --
> > > 
> > > creating an shapeObj and then using it to queryByShape 
> > against a layer
> > returns way 
> > > more results than should.
> > > 
> > > getting the bounds of the above shape and creating a 
> > rectObj and then
> > using 
> > > queryByRect against the same layer returns the correct number of
> > results (way less 
> > > than that returned by queryByShape).
> > > 
> > > now, I have to first determine if I am doing something 
> > obviously wrong
> > or if this is a 
> > > bug. Then I can act accordingly.
> > > 
> > > Many thanks.
> > > 
> > > _______________________________________________
> > > Mapserver-users mailing list
> > > Mapserver-users at lists.gis.umn.edu
> > > http://lists.gis.umn.edu/mailman/listinfo/mapserver-users
> > 
> > 
> 
> _______________________________________________
> Mapserver-users mailing list
> Mapserver-users at lists.gis.umn.edu
> http://lists.gis.umn.edu/mailman/listinfo/mapserver-users




More information about the mapserver-users mailing list