@@ -1355,17 +1355,19 @@ public function deleteDocument(string $collection, string $id): bool
13551355 /**
13561356 * Handle distance spatial queries
13571357 *
1358+ * @param string $spatialAttributeType
13581359 * @param Query $query
13591360 * @param array<string, mixed> $binds
13601361 * @param string $attribute
13611362 * @param string $alias
13621363 * @param string $placeholder
13631364 * @return string
13641365 */
1365- protected function handleDistanceSpatialQueries (Query $ query , array &$ binds , string $ attribute , string $ alias , string $ placeholder ): string
1366+ protected function handleDistanceSpatialQueries (string $ spatialAttributeType , Query $ query , array &$ binds , string $ attribute , string $ alias , string $ placeholder ): string
13661367 {
13671368 $ distanceParams = $ query ->getValues ()[0 ];
1368- $ binds [": {$ placeholder }_0 " ] = $ this ->convertArrayToWKT ($ distanceParams [0 ]);
1369+ $ wkt = $ this ->convertArrayToWKT ($ distanceParams [0 ]);
1370+ $ binds [": {$ placeholder }_0 " ] = $ wkt ;
13691371 $ binds [": {$ placeholder }_1 " ] = $ distanceParams [1 ];
13701372
13711373 $ useMeters = isset ($ distanceParams [2 ]) && $ distanceParams [2 ] === true ;
@@ -1388,6 +1390,11 @@ protected function handleDistanceSpatialQueries(Query $query, array &$binds, str
13881390 }
13891391
13901392 if ($ useMeters ) {
1393+ $ wktType = $ this ->getSpatialTypeFromWKT ($ wkt );
1394+ $ attrType = strtolower ($ spatialAttributeType );
1395+ if ($ wktType != Database::VAR_POINT || $ attrType != Database::VAR_POINT ) {
1396+ throw new DatabaseException ('Distance in meters is not supported between ' .$ attrType . ' and ' . $ wkt );
1397+ }
13911398 return "ST_DISTANCE_SPHERE( {$ alias }. {$ attribute }, ST_GeomFromText(: {$ placeholder }_0), 6371000) {$ operator } : {$ placeholder }_1 " ;
13921399 }
13931400 return "ST_Distance( {$ alias }. {$ attribute }, ST_GeomFromText(: {$ placeholder }_0)) {$ operator } : {$ placeholder }_1 " ;
@@ -1396,14 +1403,15 @@ protected function handleDistanceSpatialQueries(Query $query, array &$binds, str
13961403 /**
13971404 * Handle spatial queries
13981405 *
1406+ * @param string $type
13991407 * @param Query $query
14001408 * @param array<string, mixed> $binds
14011409 * @param string $attribute
14021410 * @param string $alias
14031411 * @param string $placeholder
14041412 * @return string
14051413 */
1406- protected function handleSpatialQueries (Query $ query , array &$ binds , string $ attribute , string $ alias , string $ placeholder ): string
1414+ protected function handleSpatialQueries (string $ type , Query $ query , array &$ binds , string $ attribute , string $ alias , string $ placeholder ): string
14071415 {
14081416 switch ($ query ->getMethod ()) {
14091417 case Query::TYPE_CROSSES :
@@ -1418,7 +1426,7 @@ protected function handleSpatialQueries(Query $query, array &$binds, string $att
14181426 case Query::TYPE_DISTANCE_NOT_EQUAL :
14191427 case Query::TYPE_DISTANCE_GREATER_THAN :
14201428 case Query::TYPE_DISTANCE_LESS_THAN :
1421- return $ this ->handleDistanceSpatialQueries ($ query , $ binds , $ attribute , $ alias , $ placeholder );
1429+ return $ this ->handleDistanceSpatialQueries ($ type , $ query , $ binds , $ attribute , $ alias , $ placeholder );
14221430
14231431 case Query::TYPE_INTERSECTS :
14241432 $ binds [": {$ placeholder }_0 " ] = $ this ->convertArrayToWKT ($ query ->getValues ()[0 ]);
@@ -1487,7 +1495,7 @@ protected function getSQLCondition(Query $query, array &$binds, array $attribute
14871495 $ attributeType = $ this ->getAttributeType ($ query ->getAttribute (), $ attributes );
14881496
14891497 if (in_array ($ attributeType , Database::SPATIAL_TYPES )) {
1490- return $ this ->handleSpatialQueries ($ query , $ binds , $ attribute , $ alias , $ placeholder );
1498+ return $ this ->handleSpatialQueries ($ attributeType , $ query , $ binds , $ attribute , $ alias , $ placeholder );
14911499 }
14921500
14931501 switch ($ query ->getMethod ()) {
@@ -1868,4 +1876,14 @@ public function getSupportForSpatialIndexOrder(): bool
18681876 {
18691877 return true ;
18701878 }
1879+
1880+ /**
1881+ * Does the adapter support calculating distance(in meters) between multidimension geometry(line, polygon,etc)?
1882+ *
1883+ * @return bool
1884+ */
1885+ public function getSupportForDistanceBetweenMultiDimensionGeometryInMeters (): bool
1886+ {
1887+ return false ;
1888+ }
18711889}
0 commit comments