How to use Doctrine2 to work with GeoSpatial Queries using PostGIS?

I have an open application based on Postgres and PostGIS.

I tried Google for several hours, but could not find documentation that could show some basic geospatial things, like the distance between two points using Doctrine2. The inability to use ORM is a big deal for me in terms of defining my database of choice.

Can someone show me a basic example of how you can tell by showing all the points within a radius of, say, 10 miles with Doctrine?

+6
source share
2 answers

, , Doctrine 2 ( 2. 2+) Postgis. , - PHP, :

http://web.archive.org/web/20161118060448/http://blog.fastre.info:80/2012/02/doctrine2-2-2-et-types-geographiques/

, :

  1. geojson postgis (json php json_decode)
  2. Point

:

  1. Point WKT. WKT, JSON? Postgis ST_GeogFromWKT, () ST_GeogFromGeoJson.
  2. .

DQL, "" DQL-. , , .

namespace Progracqteur\WikipedaleBundle\Resources\Doctrine\Functions;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;

/**
*
* @author Julien Fastré <julien arobase fastre point info>
*/
class Covers extends FunctionNode {

    private $polygon = null;
    private $point = null;


    public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker) {
        return 'ST_Covers('.$this->polygon->dispatch($sqlWalker).', '.$this->point->dispatch($sqlWalker).')';
    }

    public function parse(\Doctrine\ORM\Query\Parser $parser) {

        $parser->match(Lexer::T_IDENTIFIER);
        $parser->match(Lexer::T_OPEN_PARENTHESIS);

        $this->polygon = $parser->StringExpression();

        $parser->match(Lexer::T_COMMA);

        $this->point = $parser->StringPrimary();

        $parser->match(Lexer::T_CLOSE_PARENTHESIS);

    }
}

app/config/config.yml:

        dql:
          string_functions:
            covers: Progracqteur\WikipedaleBundle\Resources\Doctrine\Functions\Covers

: , , 'ST_FromWKT', WKT getSql ( __toString?). , , .

: ($entity-> getPolygon() postgis - - angular .)

$em->createQuery('SELECT p from MyEntity p where covers(:polygon, p.geom) = true)
            ->setParameter('polygon', $entity->getPolygon());
+6

, , .

:

https://github.com/djlambert/doctrine2-spatial

Postgis MySQL.

Postgis:

  • ST_Area
  • ST_AsBinary
  • ST_AsText
  • ST_Centroid
  • ST_ClosestPoint
  • ST_Contains
  • ST_ContainsProperly
  • ST_CoveredBy
  • ST_Covers
  • ST_Crosses
  • ST_Disjoint
  • ST_Distance
  • ST_Envelope
  • ST_GeomFromText
  • ST_Length
  • ST_LineCrossingDirection
  • ST_StartPoint
  • ST_Summary
+3

All Articles