我试图用postgis来找到一个以米为单位的点周围的东西。
我在Symfony 6.3.7,教义包2.10,postresql 13和postgis 3.0我还安装了jsor bundle用于教义扩展,这是我的conf:
orm:
dql:
string_functions:
ST_DWithin: Jsor\Doctrine\PostGIS\Functions\ST_DWithin
ST_SetSRID: Jsor\Doctrine\PostGIS\Functions\ST_SetSRID
ST_POINT: Jsor\Doctrine\PostGIS\Functions\ST_Point
ST_GeomFromText: Jsor\Doctrine\PostGIS\Functions\ST_GeomFromText
ST_Transform: Jsor\Doctrine\PostGIS\Functions\ST_Transform
geometry: Jsor\Doctrine\PostGIS\Functions\Geometry
geography: Jsor\Doctrine\PostGIS\Functions\Geography
字符串
我的数据库中有两个带有经度和纬度的参数。我创建了一个DoctrineMigration,并使用以下请求来创建一个点列。我选择SRID 4326,因为它似乎是一个常见的参数,但它可能不适合我的情况
$this->addSql('CREATE EXTENSION IF NOT EXISTS postgis;');
$this->addSql('ALTER TABLE myTable ADD point geometry(GEOMETRY, 4326)');
$this->addSql('UPDATE myTable SET point = ST_SetSRID(ST_Point(longitude, latitude), 4326)');
型
对于raw sql,像SELECT * FROM myTable WHERE ST_DWithin(ST_SetSRID(point, 4326)::geography, ST_GeomFromText('POINT(4.137325 46.691456)', 4326)::geography, 20000)
这样的东西似乎可以工作,但它可能没有优化。
我正在努力使用querybuilder来搜索一个给定区域内的元素。我想按接近度排序。
我该怎么做?
1条答案
按热度按时间toiithl61#
它最终创建了一个地理列而不是几何,以避免转换
字符串
对于查询,使用
$qb->expr()->eq
似乎可以让它工作。型