rogeriolino / doctrine-geojson

此包已被废弃,不再维护。没有建议的替代包。

GeoJson Doctrine 模型

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 模型

要求

  • PHP 5.4+
  • Doctrine 2.4+

使用

保存

  <?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();

检索

  <?php

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

JSON 输出

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