WIP: Add GeoImage (georeferenced image)
This commit is contained in:
parent
e5810d94c6
commit
726772ed75
21
src/Controller/GeoImageController.php
Normal file
21
src/Controller/GeoImageController.php
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Controller;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
use Symfony\Component\Routing\Attribute\Route;
|
||||||
|
use App\Entity\GeoImage;
|
||||||
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
|
|
||||||
|
class GeoImageController extends AbstractController
|
||||||
|
{
|
||||||
|
#[Route('/geoimage', name: 'app_geo_image')]
|
||||||
|
public function index(EntityManagerInterface $em): JsonResponse
|
||||||
|
{
|
||||||
|
$repo = $em->getRepository(GeoImage::class);
|
||||||
|
$geoImages = $repo->findAllWithGeometry();
|
||||||
|
|
||||||
|
return $this->json($geoImages);
|
||||||
|
}
|
||||||
|
}
|
68
src/Entity/GeoImage.php
Normal file
68
src/Entity/GeoImage.php
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Entity;
|
||||||
|
|
||||||
|
use App\Repository\GeoImageRepository;
|
||||||
|
use Doctrine\DBAL\Types\Types;
|
||||||
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
|
use JsonSerializable;
|
||||||
|
|
||||||
|
#[ORM\Entity(repositoryClass: GeoImageRepository::class)]
|
||||||
|
#[ORM\Table(name: 'geo_immagine_catasto')]
|
||||||
|
class GeoImage implements JsonSerializable
|
||||||
|
{
|
||||||
|
#[ORM\Id]
|
||||||
|
#[ORM\GeneratedValue]
|
||||||
|
#[ORM\Column]
|
||||||
|
private ?int $id = null;
|
||||||
|
|
||||||
|
#[ORM\Column(length: 255)]
|
||||||
|
private ?string $filename = null;
|
||||||
|
|
||||||
|
#[ORM\Column(type: Types::JSON, name: 'poligono')]
|
||||||
|
private ?string $polygon = null;
|
||||||
|
|
||||||
|
public function getId(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId(string $id): static
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFilename(): ?string
|
||||||
|
{
|
||||||
|
return $this->filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFilename(string $filename): static
|
||||||
|
{
|
||||||
|
$this->filename = $filename;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPolygon(): ?string
|
||||||
|
{
|
||||||
|
return $this->polygon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPolygon(string $polygon): static
|
||||||
|
{
|
||||||
|
$this->polygon = $polygon;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize(): mixed
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'filename' => $this->filename,
|
||||||
|
'polygon' => $this->polygon,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
74
src/Repository/GeoImageRepository.php
Normal file
74
src/Repository/GeoImageRepository.php
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Repository;
|
||||||
|
|
||||||
|
use App\Entity\GeoImage;
|
||||||
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
||||||
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends ServiceEntityRepository<GeoImage>
|
||||||
|
*/
|
||||||
|
class GeoImageRepository extends ServiceEntityRepository
|
||||||
|
{
|
||||||
|
public function __construct(ManagerRegistry $registry)
|
||||||
|
{
|
||||||
|
parent::__construct($registry, GeoImage::class);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns all geoimages with associated geometry (polygon)
|
||||||
|
* as GeoJSON
|
||||||
|
* @return GeoImage[]
|
||||||
|
*/
|
||||||
|
public function findAllWithGeometry()
|
||||||
|
{
|
||||||
|
$conn = $this->getEntityManager()->getConnection();
|
||||||
|
|
||||||
|
$sql = "SELECT
|
||||||
|
id,
|
||||||
|
filename,
|
||||||
|
ST_AsGeoJSON(poligono) as polygon
|
||||||
|
FROM geo_immagine_catasto
|
||||||
|
";
|
||||||
|
|
||||||
|
$results = $conn->executeQuery($sql)
|
||||||
|
->fetchAllAssociative();
|
||||||
|
|
||||||
|
$entities = [];
|
||||||
|
foreach ($results as $result) {
|
||||||
|
$geoimage = new GeoImage();
|
||||||
|
$geoimage->setId($result['id']);
|
||||||
|
$geoimage->setFilename($result['filename']);
|
||||||
|
$geoimage->setPolygon($result['polygon']);
|
||||||
|
$entities[] = $geoimage;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $entities;
|
||||||
|
}
|
||||||
|
|
||||||
|
// /**
|
||||||
|
// * @return GeoImage[] Returns an array of GeoImage objects
|
||||||
|
// */
|
||||||
|
// public function findByExampleField($value): array
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('g')
|
||||||
|
// ->andWhere('g.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->orderBy('g.id', 'ASC')
|
||||||
|
// ->setMaxResults(10)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// public function findOneBySomeField($value): ?GeoImage
|
||||||
|
// {
|
||||||
|
// return $this->createQueryBuilder('g')
|
||||||
|
// ->andWhere('g.exampleField = :val')
|
||||||
|
// ->setParameter('val', $value)
|
||||||
|
// ->getQuery()
|
||||||
|
// ->getOneOrNullResult()
|
||||||
|
// ;
|
||||||
|
// }
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user