huh -- Didn't realize that MySQL's spatial functions weren't fully
implemented.  MBRContains is drawing a rectangle around your polygon and
using that to check your points, so it won't miss any points -- there won't
be any false negatives.

Here is a MySQL function from the mysql forum comments that will should do
point in polygon tests.
http://dev.mysql.com/doc/refman/5.1/en/functions-that-test-spatial-relationships-between-geometries.html

CREATE FUNCTION myWithin(p POINT, poly POLYGON) RETURNS INT(1) DETERMINISTIC
BEGIN
DECLARE n INT DEFAULT 0;
DECLARE pX DECIMAL(9,6);
DECLARE pY DECIMAL(9,6);
DECLARE ls LINESTRING;
DECLARE poly1 POINT;
DECLARE poly1X DECIMAL(9,6);
DECLARE poly1Y DECIMAL(9,6);
DECLARE poly2 POINT;
DECLARE poly2X DECIMAL(9,6);
DECLARE poly2Y DECIMAL(9,6);
DECLARE i INT DEFAULT 0;
DECLARE result INT(1) DEFAULT 0;
SET pX = X(p);
SET pY = Y(p);
SET ls = ExteriorRing(poly);
SET poly2 = EndPoint(ls);
SET poly2X = X(poly2);
SET poly2Y = Y(poly2);
SET n = NumPoints(ls);
WHILE i<n DO
SET poly1 = PointN(ls, (i+1));
SET poly1X = X(poly1);
SET poly1Y = Y(poly1);
IF ( ( ( ( poly1X <= pX ) && ( pX < poly2X ) ) || ( ( poly2X <= pX ) && ( pX
< poly1X ) ) ) && ( pY > ( poly2Y - poly1Y ) * ( pX - poly1X ) / ( poly2X -
poly1X ) + poly1Y ) ) THEN
SET result = !result;
END IF;
SET poly2X = poly1X;
SET poly2Y = poly1Y;
SET i = i + 1;
END WHILE;
RETURN result;
End;

Usage:

SET @point = PointFromText('POINT(5 5)') ;
SET @polygon = PolyFromText('POLYGON((0 0,10 0,10 10,0 10))') ;
SELECT myWithin(@point, @polygon) AS result ;


On Sat, May 15, 2010 at 11:59 AM, laxmidi1994 <[email protected]>wrote:

> Hi Paul,
>
> Thank you for the message.
>
> Unfortunately, I'm already set up in mySQL; and I don't know Postgre
> and PostGIS.
>
> Does anyone know if MBRContains produces false positives only or are
> there false negatives, as well? I'm thinking about using a php
> function on the results of MBRContains to weed out any false
> positives. From what I gather, the php function is more accurate, but
> it runs slower. If MBRContains produces false negatives, then this
> plan won't work.
>
> Thanks,
>
> -Laxmidi
>
>
> On May 15, 8:30 am, Paul Hastings <[email protected]> wrote:
> > On 5/15/2010 8:23 AM, laxmidi1994 wrote:
> >
> > > I started playing with the MBRContains function in mySQL and I
> >
> > as far as i can remember mySQL's "spatial" functions rely on simple
> bounding
> > boxes. postGIS would be a better choice.
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> "Google Maps API For Flash" group.
> > To post to this group, send email to
> [email protected].
> > To unsubscribe from this group, send email to
> [email protected]<google-maps-api-for-flash%[email protected]>
> .
> > For more options, visit this group athttp://
> groups.google.com/group/google-maps-api-for-flash?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps API For Flash" group.
> To post to this group, send email to
> [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-maps-api-for-flash%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-maps-api-for-flash?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API For Flash" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api-for-flash?hl=en.

Reply via email to