rogeriolino/doctrine-geojson

This package is abandoned and no longer maintained. No replacement package was suggested.

GeoJson Doctrine Models

dev-master 2014-05-16 14:29 UTC

This package is auto-updated.

Last update: 2023-03-15 23:58:48 UTC


README

GeoJson Doctrine Models

Requirements

  • PHP 5.4+
  • Doctrine 2.4+

Usage

Saving

  <?php
  
  $feature = new Feature();
  $feature->add(new Property('name', 'Rogerio Lino'));
  $feature->setGeometry(
    (new Geometry('Point'))
      ->add(new Coordinate(-40, -20, 0))
  );
  
  $entityManager->persist($feature);
  $entityManager->flush();

Retrieving

  <?php

  $features = $entityManager
                    ->getRepository('RogerioLino\Doctrine\GeoJson\Feature')
                    ->findAll();
  echo json_encode(new FeatureCollection($features));

JSON Output

  {
    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "Point",
                "coordinates": [
                    -40,
                    -20,
                    0
                ]
            },
            "properties": {
                "name": "Rogerio Lino"
            }
        }
    ]
  }