2016-03-20 2 views
2

マップ内の四角形内のすべてのポイントを選択するDQLクエリを作成したいと思います。矩形は、左上の点と右下の点によって定義されます。詳細はlinkを参照してください。ジオ空間ポイントを取得するためのDQLクエリst_within矩形

$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"); 

私は取得していますエラーは次のとおりです:

そうするために、私はこのDQLクエリを書いたあなたの情報については

[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 FROを実行中に例外が発生しましたM0_.km AS AS_2、m0_.km AS km_3、m0_.slug AS slug_4、m0_.title AS title_5、m0_.description AS description_6、M0_.description AS description_6、 m0_.address ASアドレス_7、m0_.isPublished AS isPublished_8、m0_.delegation AS delegation_9、m0_.lat AS lat_10、m0_.lng AS lng_11、m0_.date AS日付_12、m0_.count ASカウント_13、AsBinary(m0_.geom)AS geom_14 MotorsAds FROM m0_ WHEREのST_Within(?m0_.geom、エンベロープ(ラインストリング(?)))= paramsは[{}、{}]とm0_.date DESC)dctrn_result BY 1 ORDER)dctrn_table」:

SQLSTATE [22007]:無効なdatetime形式:1367パーシング中に不正な非幾何学的な ''10 .090792984009 36.837170993382' '値が見つかりました

答えて

1

$qb = $this->em->createQueryBuilder() 
     ->select("m") 
     ->from($this->getEntityClassName(), "m") 
     ->where(
      $this->em->createQueryBuilder()->expr()->eq(
        sprintf("ST_Within(m.geom, envelope(linestring(point(:topleftX,:topleftY), point(:bottomrightX,:bottomrightY))))"), 
        $this->em->createQueryBuilder()->expr()->literal(true) 
       ) 
     ) 
     ->setParameter(":topleftX", $topleftX) 
     ->setParameter(":topleftY", $topleftY) 
     ->setParameter(":bottomrightX", $bottomrightX) 
     ->setParameter(":bottomrightY", $bottomrightY) 
     ->orderBy("m.date", "DESC"); 
2

彼:

$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"); 

は、私は、ドキュメントからそれを取った:以下のソリューションは、クエリ点をDQLするPHPのポイントあなたの変換の問題を防ぐことができますhttps://github.com/creof/doctrine2-spatial/blob/master/doc/index.md

+0

ありがとうございます。私はあなたの答えです。私は私の質問を更新する。あなたはコメントしてもらえますか? –

+0

あなたが提案した解決策の問題点の変換です....以下は私のソリューションです。ありがとう@ミロ再び –

+0

グッドジョブ、アミン – Miro