Skip to content

Commit

Permalink
Expose les géométries Litteralis dans le flux CIFS (#960)
Browse files Browse the repository at this point in the history
* Expose les géométries Litteralis au CIFS

* Expose les géométries Litteralis au CIFS

* Update tests/Integration/Infrastructure/Controller/Api/get-regulations-expected-result.xml
  • Loading branch information
florimondmanca authored Sep 23, 2024
1 parent bf372f8 commit 473a4be
Show file tree
Hide file tree
Showing 16 changed files with 257 additions and 49 deletions.
2 changes: 2 additions & 0 deletions src/Application/Cifs/PolylineMakerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@

interface PolylineMakerInterface
{
public function attemptMergeLines(string $geometry): ?string;

public function getPolylines(string $geometry): array;
}
12 changes: 10 additions & 2 deletions src/Application/Regulation/Query/GetCifsIncidentsQueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,16 @@ public function __invoke(GetCifsIncidentsQuery $query): array
/** @var Location $location */
foreach ($measure->getLocations() as $location) {
$locationId = $location->getUuid();
$street = $location->getNamedStreet() ? $location->getNamedStreet()->getRoadName() : $location->getNumberedRoad()->getRoadNumber();
$polylines = $this->polylineMaker->getPolylines($location->getGeometry());
$street = $location->getCifsStreetLabel();

$geometry = $location->getGeometry();

if ($location->getRawGeoJSON()) {
// Simplify the geometry to a (MULTI)LINESTRING with deduplicated segments.
$geometry = $this->polylineMaker->attemptMergeLines($geometry);
}

$polylines = $this->polylineMaker->getPolylines($geometry);

foreach ($incidentPeriods as $incidentPeriod) {
foreach ($polylines as $polyline) {
Expand Down
13 changes: 13 additions & 0 deletions src/Domain/Regulation/Location/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public function getRawGeoJSON(): ?RawGeoJSON
return $this->rawGeoJSON;
}

public function getCifsStreetLabel(): string
{
if ($this->namedStreet) {
return $this->namedStreet->getRoadName();
}

if ($this->numberedRoad) {
return $this->numberedRoad->getRoadNumber();
}

return $this->rawGeoJSON->getLabel();
}

public function update(string $roadType, ?string $geometry): void
{
$this->roadType = $roadType;
Expand Down
12 changes: 12 additions & 0 deletions src/Infrastructure/Cifs/PolylineMaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ public function __construct(
) {
}

public function attemptMergeLines(string $geometry): ?string
{
$row = $this->em
->getConnection()
->fetchAssociative(
'SELECT ST_AsGeoJSON(ST_LineMerge(:geom)) AS geom',
['geom' => $geometry],
);

return $row['geom'] ?? $geometry;
}

public function getPolylines(string $geometry): array
{
$rows = $this->em
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,19 @@ public function load(ObjectManager $manager): void
label: 'Zone Olympique',
);

$litteralisLocation1 = new Location(
'066e984f-4746-78f8-8000-dce555b28604',
$this->getReference('litteralisMeasure'),
roadType: RoadTypeEnum::RAW_GEOJSON->value,
geometry: '{"type":"MultiLineString","coordinates":[[[3.023890325,50.570177599],[3.023850386,50.570151247]],[[3.023890325,50.570177599],[3.024458944,50.570503315]],[[3.024458944,50.570503315],[3.024500711,50.570527945]],[[3.024500711,50.570527945],[3.024501619,50.570528488]],[[3.024501619,50.570528488],[3.025116052,50.570901355]],[[3.025116052,50.570901355],[3.02515503,50.570929555]],[[3.023850386,50.570151247],[3.02384667,50.570148629]],[[3.023475742,50.569868822],[3.023440948,50.569835923]],[[3.023475742,50.569868822],[3.02384667,50.570148629]],[[3.02515503,50.570929555],[3.025159053,50.570932711]],[[3.025159053,50.570932711],[3.025653937,50.571355649]],[[3.025653937,50.571355649],[3.02569009,50.57138952]],[[3.02569009,50.57138952],[3.025691455,50.571390856]],[[3.025691455,50.571390856],[3.026131049,50.571842058]],[[3.026131049,50.571842058],[3.026159516,50.571877523]],[[3.023440948,50.569835923],[3.02343789,50.569832708]],[[3.023149663,50.569492048],[3.023119275,50.569455721]],[[3.023149663,50.569492048],[3.02343789,50.569832708]],[[3.022717354,50.568969715],[3.023119183,50.56945561]],[[3.023119275,50.569455721],[3.023119183,50.56945561]],[[3.026159516,50.571877523],[3.02616073,50.571879188]],[[3.02616073,50.571879188],[3.027150974,50.57338937]]]}',
);

$litteralisLocation1RawGeoJSON = new RawGeoJSON(
uuid: '066e9850-3f1e-7735-8000-dacea1fe4ff1',
location: $litteralisLocation1,
label: 'ROUTE 147 (NOYELLES-LÈS-SECLIN) DU PR7 +779 AU PR8 +413',
);

$manager->persist($namedStreetTypicalMeasureLocation1);
$manager->persist($namedStreetTypicalMeasureLocation2);
$manager->persist($namedStreetTypicalMeasureLocation3);
Expand Down Expand Up @@ -289,6 +302,8 @@ public function load(ObjectManager $manager): void
$manager->persist($cifsLocationDepartmentalRoad);
$manager->persist($rawGeoJSONLocation);
$manager->persist($rawGeoJSON);
$manager->persist($litteralisLocation1);
$manager->persist($litteralisLocation1RawGeoJSON);
$manager->flush();

$this->addReference('typicalMeasureLocation1', $typicalMeasureLocation1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public function load(ObjectManager $manager): void
new \DateTime('2023-01-06'),
);

$litteralisMeasure = new Measure(
'066e984c-9939-76ed-8000-d070d574f378',
$this->getReference('litteralisRegulationOrder'),
MeasureTypeEnum::NO_ENTRY->value,
new \DateTime('2023-06-01'),
);

$manager->persist($typicalMeasure);
$manager->persist($typicalMeasureToRemove);
$manager->persist($publishedMeasure);
Expand All @@ -88,6 +95,7 @@ public function load(ObjectManager $manager): void
$manager->persist($cifsMeasure);
$manager->persist($outDatedCifsMeasure);
$manager->persist($rawGeoJSONMeasure);
$manager->persist($litteralisMeasure);

$this->addReference('typicalMeasure', $typicalMeasure);
$this->addReference('typicalMeasureToRemove', $typicalMeasureToRemove);
Expand All @@ -97,6 +105,7 @@ public function load(ObjectManager $manager): void
$this->addReference('cifsMeasure', $cifsMeasure);
$this->addReference('outDatedCifsMeasure', $outDatedCifsMeasure);
$this->addReference('rawGeoJSONMeasure', $rawGeoJSONMeasure);
$this->addReference('litteralisMeasure', $litteralisMeasure);

$manager->flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ public function load(ObjectManager $manager): void
endDate: new \DateTimeImmutable('2020-06-10'),
);

$litteralisRegulationOrder = new RegulationOrder(
uuid: '066e9849-f802-7a4c-8000-845f47c4b0de',
identifier: '117374#24-A-0473',
category: RegulationOrderCategoryEnum::ROAD_MAINTENANCE->value,
description: 'Arrêté de voirie (URL : https://dl.sogelink.fr/?iX5UN3GL)',
startDate: new \DateTimeImmutable('2023-06-03'),
endDate: new \DateTimeImmutable('2023-11-10'),
);

$manager->persist($typicalRegulationOrder);
$manager->persist($publishedRegulationOrder);
$manager->persist($regulationOrderDuplicate);
Expand All @@ -127,6 +136,7 @@ public function load(ObjectManager $manager): void
$manager->persist($regulationOrderCifs);
$manager->persist($outDatedRegulationOrderCifs);
$manager->persist($rawGeoJSONRegulationOrder);
$manager->persist($litteralisRegulationOrder);
$manager->flush();

$this->addReference('typicalRegulationOrder', $typicalRegulationOrder);
Expand All @@ -140,5 +150,6 @@ public function load(ObjectManager $manager): void
$this->addReference('regulationOrderCifs', $regulationOrderCifs);
$this->addReference('outDatedRegulationOrderCifs', $outDatedRegulationOrderCifs);
$this->addReference('rawGeoJSONRegulationOrder', $rawGeoJSONRegulationOrder);
$this->addReference('litteralisRegulationOrder', $litteralisRegulationOrder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ final class RegulationOrderRecordFixture extends Fixture implements DependentFix
public const UUID_NO_MEASURES = '0650037d-3e90-7a99-8000-a2099e71ae4a';
public const UUID_CIFS = '0654905d-6771-75d8-8000-d523184d0b55';
public const UUID_RAWGEOJSON = '06672e5e-8322-739f-8000-9ebfcd86e29a';
public const UUID_LITTERALIS = '066e9849-1457-7a1e-8000-3142ece4a7de';

public function load(ObjectManager $manager): void
{
Expand Down Expand Up @@ -138,6 +139,15 @@ public function load(ObjectManager $manager): void
$this->getReference('mainOrg'),
);

$litteralisRegulationOrderRecord = new RegulationOrderRecord(
self::UUID_LITTERALIS,
RegulationOrderRecordSourceEnum::LITTERALIS->value,
RegulationOrderRecordStatusEnum::PUBLISHED->value,
$this->getReference('litteralisRegulationOrder'),
new \DateTime('2024-09-05'),
$this->getReference('mainOrg'),
);

$manager->persist($typicalRegulationOrderRecord);
$manager->persist($publishedRegulationOrderRecord);
$manager->persist($regulationOrderRecordDuplicate);
Expand All @@ -149,6 +159,7 @@ public function load(ObjectManager $manager): void
$manager->persist($regulationOrderRecordCifs);
$manager->persist($outDatedRegulationOrderRecordCifs);
$manager->persist($rawGeoJSONRegulationOrderRecord);
$manager->persist($litteralisRegulationOrderRecord);
$manager->flush();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public function findRegulationOrdersForCifsIncidentFormat(
'roc.status = :status',
'ro.endDate >= :today',
'loc.geometry IS NOT NULL',
'loc.roadType NOT IN (:excludedRoadTypes)',
'loc.roadType NOT IN (:excludedRoadTypes) OR (loc.roadType = :rawGeoJSONRoadType AND roc.source = :litteralisSource)',
$allowedSources ? 'roc.source in (:allowedSources)' : null,
$excludedIdentifiers ? 'ro.identifier NOT IN (:excludedIdentifiers)' : null,
$allowedLocationIds ? 'loc.uuid IN (:allowedLocationIds)' : null,
Expand All @@ -266,6 +266,9 @@ public function findRegulationOrdersForCifsIncidentFormat(
'measureType' => MeasureTypeEnum::NO_ENTRY->value,
'today' => $this->dateUtils->getNow(),
'excludedRoadTypes' => [RoadTypeEnum::RAW_GEOJSON->value],
// Allow RawGeoJSON locations only for Litteralis source
'rawGeoJSONRoadType' => RoadTypeEnum::RAW_GEOJSON->value,
'litteralisSource' => RegulationOrderRecordSourceEnum::LITTERALIS->value,
])
->orderBy('loc.uuid') // Predictable order
->getQuery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,20 @@
<thursday>08:00-10:00</thursday>
</schedule>
</incident>

<incident id="117374#24-A-0473:066e984f-4746-78f8-8000-dce555b28604:0bcb384fcd11044587345fd9456a3ac8:0">
<creationtime>2024-09-05T00:00:00+00:00</creationtime>
<type>ROAD_CLOSED</type>
<description>ROUTE 147 (NOYELLES-LÈS-SECLIN) DU PR7 +779 AU PR8 +413 : circulation interdite tous les jours pour tous les véhicles</description>
<street>ROUTE 147 (NOYELLES-LÈS-SECLIN) DU PR7 +779 AU PR8 +413</street>
<direction>BOTH_DIRECTIONS</direction>
<polyline>50.568969715 3.022717354 50.56945561 3.023119183 50.569455721 3.023119275 50.569492048 3.023149663 50.569832708 3.02343789 50.569835923 3.023440948 50.569868822 3.023475742 50.570148629 3.02384667 50.570151247 3.023850386 50.570177599 3.023890325 50.570503315 3.024458944 50.570527945 3.024500711 50.570528488 3.024501619 50.570901355 3.025116052 50.570929555 3.02515503 50.570932711 3.025159053 50.571355649 3.025653937 50.57138952 3.02569009 50.571390856 3.025691455 50.571842058 3.026131049 50.571877523 3.026159516 50.571879188 3.02616073 50.57338937 3.027150974</polyline>
<starttime>2023-06-03T00:00:00+00:00</starttime>
<endtime>2023-11-10T00:00:00+00:00</endtime>
<source>
<reference>dialog.beta.gouv.fr</reference>
<name>DiaLog</name>
<url>http://localhost/api/regulations/cifs.xml</url>
</source>
</incident>
</incidents>
Loading

0 comments on commit 473a4be

Please sign in to comment.