无法在MySQL中的多边形内找到Point

时间:2018-09-21 05:36:01

标签: mysql geometry geospatial polygon point

因此,我一直试图知道某个坐标(点)是否在先前保存的多边形内,但是即使我在多边形内指定该点,也不会返回true。

我正在这样通过PHP和Mysql进行操作:

这是我的保存方式:

$bosquesDeLasLomas = [
            [-99.26297668187959, 19.398757625616238],
            [-99.25027373998506, 19.38920429315943],
            [-99.2321634647165, 19.40847230374557],
            [-99.23336509435518, 19.415191283307824],
            [-99.23559669225557, 19.415029383450623],
            [-99.23799995153291, 19.41187230400899],
            [-99.24186233251436, 19.411710400846623],
            [-99.25568107335909, 19.404424591699442],
        ];

        // Raw query formation for Polygon
        $arrayOfPoints = [];
        foreach( $bosquesDeLasLomas as $point ){
            $arrayOfPoints[] = new \Grimzy\LaravelMysqlSpatial\Types\Point($point[0], $point[1]);
        }
        // Closes the polygon for MySql
        $arrayOfPoints[] = $arrayOfPoints[0];
        $linestring = new \Grimzy\LaravelMysqlSpatial\Types\LineString($arrayOfPoints);
        // Defines RAW string
        $raw = "ST_GeomFromText('POLYGON(" .new \Grimzy\LaravelMysqlSpatial\Types\Polygon([$linestring]). ")')";

        $location = new \App\Location();
        $location->neighborhood = "Bosques de Las Lomas";
        $location->polygon = \DB::raw($raw);
        $location->save();

这是我查看位置的方式:

 $SQL = 'st_Contains(ST_GeomFromText("POINT('.$address_longitude.' '.$address_latitude.')"), polygon)';
        $isLocationAllowed = Location::whereRaw($SQL)->count();

我尝试使用其他查询,但始终返回0。

[2018-09-21 05:16:01] local.INFO: st_Contains(ST_GeomFromText("POINT('19.3868562, -99.254208')"), polygon)  
[2018-09-21 05:16:01] local.INFO: 0  
[2018-09-21 05:16:05] local.INFO: st_Contains(polygon,ST_GeomFromText("POINT('19.3868562, -99.254208')"))  
[2018-09-21 05:16:05] local.INFO: 0  
[2018-09-21 05:16:13] local.INFO: st_Contains(ST_GeomFromText("POINT('-99.254208, 19.3868562')"), polygon)  
[2018-09-21 05:16:13] local.INFO: 0  
[2018-09-21 05:16:16] local.INFO: st_Contains(polygon,ST_GeomFromText("POINT('-99.254208, 19.3868562')"))  
[2018-09-21 05:16:16] local.INFO: 0  
[2018-09-21 05:18:43] local.INFO: st_Contains(polygon,ST_GeomFromText("POINT('-99.254208, 19.3868562')"))  
[2018-09-21 05:18:43] local.INFO: 0  
[2018-09-21 05:23:37] local.INFO: st_Contains(polygon,ST_GeomFromText("POINT(-99.254208, 19.3868562)"))  
[2018-09-21 05:23:37] local.INFO: 0  
[2018-09-21 05:25:15] local.INFO: MBRContains(polygon,ST_GeomFromText("POINT(-99.254208, 19.3868562)"))  
[2018-09-21 05:25:15] local.INFO: 0  
[2018-09-21 05:27:53] local.INFO: st_Contains(polygon,ST_GeomFromText("19.3868562 -99.254208"))  
[2018-09-21 05:27:53] local.INFO: 0  
[2018-09-21 05:29:03] local.INFO: st_Contains(ST_GeomFromText("POINT(-99.254208, 19.3868562)"), polygon)  
[2018-09-21 05:29:03] local.INFO: 0  
[2018-09-21 05:29:17] local.INFO: st_Contains(polygon,ST_GeomFromText("POINT(-99.254208, 19.3868562)"))  
[2018-09-21 05:29:17] local.INFO: 0  
[2018-09-21 05:29:34] local.INFO: st_Contains(polygon,ST_GeomFromText("POINT(-99.254208 19.3868562)"))  
[2018-09-21 05:29:34] local.INFO: 0  
[2018-09-21 05:29:39] local.INFO: st_Contains(ST_GeomFromText("POINT(-99.254208 19.3868562)"), polygon)  
[2018-09-21 05:29:39] local.INFO: 0  

有人可以建议我吗?

0 个答案:

没有答案