diff --git a/src/Controller/GeoImageController.php b/src/Controller/GeoImageController.php new file mode 100644 index 0000000..ef66755 --- /dev/null +++ b/src/Controller/GeoImageController.php @@ -0,0 +1,21 @@ +getRepository(GeoImage::class); + $geoImages = $repo->findAllWithGeometry(); + + return $this->json($geoImages); + } +} diff --git a/src/Entity/GeoImage.php b/src/Entity/GeoImage.php new file mode 100644 index 0000000..b4063ca --- /dev/null +++ b/src/Entity/GeoImage.php @@ -0,0 +1,68 @@ +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, + ]; + } +} diff --git a/src/Repository/GeoImageRepository.php b/src/Repository/GeoImageRepository.php new file mode 100644 index 0000000..f4f41d3 --- /dev/null +++ b/src/Repository/GeoImageRepository.php @@ -0,0 +1,74 @@ + + */ +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() + // ; + // } +}