The Doctrine2-Spatial library allows you to use spatial methods on your MySQL and PostGIS database.
- Symfony Install
- Symfony Configuration
- Common Methods (also included in MySQL and PostGreSQL)
- MySQL Methods
- PostGreSQL Methods
The following SQL/OpenGIS types have been implemented as PHP objects and accompanying Doctrine types:
- Point
- LineString
- Polygon
- MultiPoint
- MultiLineString
- MultiPolygon
Similar to Geometry but SRID value is always used (SRID supported in PostGIS only), and accepts only valid "geographic" coordinates.
- Point
- LineString
- Polygon
There is support for both WKB/WKT and EWKB/EWKT return values. Currently only WKT/EWKT is used in statements.
A DQL AST walker is included which when used with the following DQL functions will return the appropriate Geometry type object from queries instead of strings:
- AsText
- ST_AsText
- AsBinary
- ST_AsBinary
Use method names in queries
$query = $this->em->createQuery('SELECT AsText(StartPoint(l.lineString)) MyLineStringEntity l');
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'CrEOF\Spatial\ORM\Query\GeometryWalker');
$result = $query->getResult();
Or within an expression
$queryBuilder = $manager->createQueryBuilder();
$queryBuilder
->select("id, ST_AsText(things.geometry) as geometry")
->from("geometryOfThings", "things")
->where(
$queryBuilder->expr()->eq(
sprintf("ST_Intersects(things.geometry, ST_SetSRID(ST_GeomFromGeoJSON('%s'), 4326))", $geoJsonPolygon),
$queryBuilder->expr()->literal(true)
)
);
$results = $queryBuilder->getQuery()->getResult();