gpt4 book ai didi

mysql - 获取矩形内地理空间点 st_dql 查询

转载 作者:行者123 更新时间:2023-11-29 01:53:06 25 4
gpt4 key购买 nike

我想编写 DQL 查询来选择 map 中矩形内的所有点。矩形由左上角点和右下角点定义。看这个link了解更多详情。

为此,我编写了这个 DQL 查询:

$qb = $this->em->createQueryBuilder()
->select("m")
->from($this->getEntityClassName(), "m")
->where("ST_Within(m.geom, envelope(linestring(:topleft, :bottomright)))")
->setParameter(":topleft", $topleft)
->setParameter(":bottomright", $bottomright)
->orderBy("m.date", "DESC");

我得到的错误是:

[Syntax Error] line 0, col 110: Error: Expected =, <, <=, <>, >, >=, !=, got 'ORDER'

供您引用,我正在查询的实体具有定义如下的 geom 属性:

/**
* @var point $geom
* @ORM\Column(type="point", nullable=true)
*/
protected $geom;

请注意,SQL 查询运行良好。具体如下:

SELECT *FROM MotorsAds WHERE
st_within(point(lng, lat),
envelope(linestring(point(10.090792984008772,36.83717099338201 ),
point(10.310519546508772,36.749467295867646 ))))

我用于 DQL 数字函数(例如 st_within)的库是 creof/doctrine2-spatial .

准备接受任何解决该问题的建议。

谢谢,


问题更新

我尝试了您提出的解决方案如下:

    $qb = $this->em->createQueryBuilder()
->select("m")
->from($this->getEntityClassName(), "m")
->where(
$this->em->createQueryBuilder()->expr()->eq(
"ST_Within(m.geom, envelope(linestring(:topleft, :bottomright)))",
$this->em->createQueryBuilder()->expr()->literal(true)
)
)
->setParameter(":topleft", $topleft)
->setParameter(":bottomright", $bottomright)
->orderBy("m.date", "DESC");

所以,我得到的错误是:

执行'SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT id_0 FROM (SELECT m0_.id AS id_0, m0_.price AS price_1, m0_.year AS year_2, m0_.km AS km_3 时发生异常, m0_.slug AS slug_4, m0_.title AS title_5, m0_.description AS description_6, m0_.address AS address_7, m0_.isPublished AS isPublished_8, m0_.delegation AS delegation_9, m0_.lat AS lat_10, m0_.lng AS lng_11, m0_ .date AS date_12, m0_.count AS count_13, AsBinary(m0_.geom) AS geom_14 FROM MotorsAds m0_ WHERE ST_Within(m0_.geom, Envelope(LineString(?, ?))) = 1 ORDER BY m0_.date DESC) dctrn_result) dctrn_table' with params [{}, {}]:

SQLSTATE[22007]:无效的日期时间格式:1367 解析期间发现非法的非几何“10.090792984009 36.837170993382”值

最佳答案

试试这个:

$qb = $this->em->createQueryBuilder()
->select("m")
->from($this->getEntityClassName(), "m")
->where(
$queryBuilder->expr()->eq(
"ST_Within(m.geom, envelope(linestring(:topleft, :bottomright)))",
$queryBuilder->expr()->literal(true)
)
)
->setParameter(":topleft", $topleft)
->setParameter(":bottomright", $bottomright)
->orderBy("m.date", "DESC");

我从文档中获取它:https://github.com/creof/doctrine2-spatial/blob/master/doc/index.md

关于mysql - 获取矩形内地理空间点 st_dql 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36114843/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com