PHP code example of utafitilabs / postgis-bundle

1. Go to this page and download the library: Download utafitilabs/postgis-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

utafitilabs / postgis-bundle example snippets


// config/bundles.php
return [
    // ...
    UtafitiLabs\PostGISBundle\UtafitiLabsPostGISBundle::class => ['all' => true],
];

use Doctrine\ORM\Mapping as ORM;

class Area
{
    // Generic geometry — accepts any shape, SRID 4326, diff-clean.
    #[ORM\Column(type: 'geometry')]
    public ?string $footprint = null;   // GeoJSON string in, GeoJSON string out

    // Typed — PostGIS enforces the shape via the typmod, still diff-clean.
    #[ORM\Column(type: 'multipolygon')]
    public ?string $boundary = null;    // geometry(MultiPolygon,4326)
}

$em->createQuery(
    'SELECT COUNT(a.id) FROM App\Entity\Area a
     WHERE ST_Intersects(a.boundary, ST_GeomFromGeoJSON(:poly)) = true'
)->setParameter('poly', $geoJsonPolygon)->getSingleScalarResult();

use UtafitiLabs\PostGISBundle\Repository\SpatialEntityRepository;

final class AreaRepository extends SpatialEntityRepository {}   // that's all

$areas->findStIntersecting($geoJson);        // GiST-backed ST_Intersects
$areas->stAreaKm2(['source' => 'wdpa']);     // geodesic km², findBy-style criteria