Skip to content

Commit

Permalink
[TM-1523] send to python overlap only intersecting polygons.
Browse files Browse the repository at this point in the history
  • Loading branch information
egrojMonroy committed Dec 2, 2024
1 parent 1b98f92 commit de2a7a8
Showing 1 changed file with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,43 @@ public function clipOverlappingPolygonsOfProjectBySite(string $uuid)
$user = Auth::user();
$sitePolygon = Site::isUuid($uuid)->first();
$projectId = $sitePolygon->project_id ?? null;

if (! $projectId) {
return response()->json(['error' => 'Project not found for the given site UUID.'], 404);
}

$polygonUuids = GeometryHelper::getProjectPolygonsUuids($projectId);

if (empty($polygonUuids)) {
return response()->json(['message' => 'No polygons found for the project.'], 204);
}

$allPolygonUuids = [];
foreach ($polygonUuids as $uuid) {
$polygonOverlappingExtraInfo = CriteriaSite::forCriteria(PolygonService::OVERLAPPING_CRITERIA_ID)
->where('polygon_id', $uuid)
->first()
->extra_info ?? null;

if ($polygonOverlappingExtraInfo) {
$decodedInfo = json_decode($polygonOverlappingExtraInfo, true);
$polygonUuidsOverlapping = array_map(function ($item) {
return $item['poly_uuid'] ?? null;
}, $decodedInfo);
$polygonUuidsFiltered = array_filter($polygonUuidsOverlapping);

array_unshift($polygonUuidsFiltered, $uuid);
$allPolygonUuids = array_merge($allPolygonUuids, $polygonUuidsFiltered);
}
}

$uniquePolygonUuids = array_unique($allPolygonUuids);

if (empty($uniquePolygonUuids)) {
return response()->json(['message' => 'No overlapping polygons found for the project.'], 204);
}
$delayedJob = DelayedJob::create();
$job = new FixPolygonOverlapJob($delayedJob->id, $polygonUuids, $user->id);
$job = new FixPolygonOverlapJob($delayedJob->id, $uniquePolygonUuids, $user->id);
dispatch($job);

return new DelayedJobResource($delayedJob);
Expand Down

0 comments on commit de2a7a8

Please sign in to comment.