diff --git a/app/Helpers/GeometryHelper.php b/app/Helpers/GeometryHelper.php new file mode 100644 index 000000000..69c575d68 --- /dev/null +++ b/app/Helpers/GeometryHelper.php @@ -0,0 +1,114 @@ +get(); + + if ($sitePolygons->isEmpty()) { + return null; // Return null if no polygons are found for the given projectUuid + } + + $polyIds = $sitePolygons->pluck('poly_id')->toArray(); + + $centroids = PolygonGeometry::selectRaw('ST_AsGeoJSON(ST_Centroid(geom)) AS centroid') + ->whereIn('uuid', $polyIds) + ->get(); + + if ($centroids->isEmpty()) { + return null; // Return null if no centroids are found + } + + $centroidCount = $centroids->count(); + $totalLatitude = 0; + $totalLongitude = 0; + + foreach ($centroids as $centroid) { + $centroidData = json_decode($centroid->centroid, true); + $totalLatitude += $centroidData['coordinates'][1]; + $totalLongitude += $centroidData['coordinates'][0]; + } + + $averageLatitude = $totalLatitude / $centroidCount; + $averageLongitude = $totalLongitude / $centroidCount; + + $centroidOfCentroids = json_encode([ + 'type' => 'Point', + 'coordinates' => [$averageLongitude, $averageLatitude], + ]); + + return $centroidOfCentroids; + } + + public function updateProjectCentroid(string $projectUuid) + { + try { + $centroid = $this->centroidOfProject($projectUuid); + + if ($centroid === null) { + Log::warning("Invalid centroid for projectUuid: $projectUuid"); + } + + $centroidArray = json_decode($centroid, true); + + $latitude = $centroidArray['coordinates'][1]; + $longitude = $centroidArray['coordinates'][0]; + + + Project::where('uuid', $projectUuid) + ->update([ + 'lat' => $latitude, + 'long' => $longitude, + ]); + + + Log::info("Centroid updated for projectUuid: $projectUuid"); + + return 'Centroids updated successfully!'; + } catch (\Exception $e) { + Log::error("Error updating centroid for projectUuid: $projectUuid"); + + return response()->json([ + 'message' => 'Error updating centroid', + 'error' => $e->getMessage(), + ], 500); + } + + } + + public static function getPolygonsBbox($polygonsIds) + { + $envelopes = PolygonGeometry::whereIn('uuid', $polygonsIds) + ->selectRaw('ST_ASGEOJSON(ST_Envelope(geom)) as envelope') + ->get(); + + $maxX = $maxY = PHP_INT_MIN; + $minX = $minY = PHP_INT_MAX; + + foreach ($envelopes as $envelope) { + $geojson = json_decode($envelope->envelope); + $coordinates = $geojson->coordinates[0]; + + foreach ($coordinates as $point) { + $x = $point[0]; + $y = $point[1]; + $maxX = max($maxX, $x); + $minX = min($minX, $x); + $maxY = max($maxY, $y); + $minY = min($minY, $y); + } + } + + $bboxCoordinates = [$minX, $minY, $maxX, $maxY]; + + return $bboxCoordinates; + } +} diff --git a/app/Http/Controllers/V2/Sites/SitePolygonDataController.php b/app/Http/Controllers/V2/Sites/SitePolygonDataController.php new file mode 100644 index 000000000..8254955cd --- /dev/null +++ b/app/Http/Controllers/V2/Sites/SitePolygonDataController.php @@ -0,0 +1,35 @@ +get(); + Log::info(json_encode($sitePolygons)); + + return $sitePolygons; + } + + public function getBboxOfCompleteSite($site) + { + try { + $sitePolygons = SitePolygon::where('site_id', $site)->get(); + $polygonsIds = $sitePolygons->pluck('poly_id'); + + $bboxCoordinates = GeometryHelper::getPolygonsBbox($polygonsIds); + + return response()->json(['bbox' => $bboxCoordinates]); + } catch (\Exception $e) { + Log::error($e->getMessage()); + + return response()->json(['error' => 'An error occurred while fetching the bounding box coordinates'], 404); + } + } +}; diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php index c346905f5..feae2f8e2 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundCreateGeometryController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\V2\Terrafund; +use App\Helpers\GeometryHelper; use App\Http\Controllers\Controller; use App\Models\V2\PolygonGeometry; use App\Models\V2\Projects\Project; @@ -117,6 +118,8 @@ public function insertGeojsonToDB(string $geojsonFilename) Log::info($returnSite) ; } } elseif ($feature['geometry']['type'] === 'MultiPolygon') { + $generalProperties = $feature['properties']; + Log::info("general properties multipolygon", $generalProperties); foreach ($feature['geometry']['coordinates'] as $polygon) { $singlePolygon = ['type' => 'Polygon', 'coordinates' => $polygon]; if (! $this->validatePolygonBounds($singlePolygon)) { @@ -124,7 +127,7 @@ public function insertGeojsonToDB(string $geojsonFilename) } $data = $this->insertSinglePolygon($singlePolygon, $srid); $uuids[] = $data['uuid']; - $returnSite = $this->insertSitePolygon($data['uuid'], $feature['properties'], $data['area']); + $returnSite = $this->insertSitePolygon($data['uuid'], $generalProperties, $data['area']); if ($returnSite) { Log::info($returnSite) ; } @@ -198,6 +201,7 @@ private function validateData(array $properties, array $fields): bool private function insertSitePolygon(string $polygonUuid, array $properties, float $area) { try { + Log::info('Inserting site polygon', ['properties' => $properties, 'polygonUuid' => $polygonUuid]); $fieldsToValidate = ['poly_name', 'plantstart', 'plantend', 'practice', 'target_sys', 'distr', 'num_trees']; $SCHEMA_CRITERIA_ID = 13; $validSchema = true; @@ -214,22 +218,23 @@ private function insertSitePolygon(string $polygonUuid, array $properties, float $sitePolygon = new SitePolygon(); $sitePolygon->project_id = $properties['project_id'] ?? null; - $sitePolygon->proj_name = $properties['proj_name'] ?? null; - $sitePolygon->org_name = $properties['org_name'] ?? null; - $sitePolygon->country = $properties['country'] ?? null; + // $sitePolygon->country = $properties['country'] ?? null; $sitePolygon->poly_id = $polygonUuid ?? null; $sitePolygon->poly_name = $properties['poly_name'] ?? null; $sitePolygon->site_id = $properties['site_id'] ?? null; - $sitePolygon->site_name = $properties['site_name'] ?? null; - $sitePolygon->poly_label = $properties['poly_label'] ?? null; + // $sitePolygon->poly_label = $properties['poly_label'] ?? null; $sitePolygon->plantstart = ! empty($properties['plantstart']) ? $properties['plantstart'] : null; $sitePolygon->plantend = ! empty($properties['plantend']) ? $properties['plantend'] : null; $sitePolygon->practice = $properties['practice'] ?? null; $sitePolygon->target_sys = $properties['target_sys'] ?? null; $sitePolygon->distr = $properties['distr'] ?? null; $sitePolygon->num_trees = $properties['num_trees'] ?? null; - $sitePolygon->est_area = $area ?? null; + $sitePolygon->calc_area = $area ?? null; $sitePolygon->save(); + if ($sitePolygon->project_id) { + $geometryHelper = new GeometryHelper(); + $geometryHelper -> updateProjectCentroid($sitePolygon->project_id); + } return null; } catch (\Exception $e) { @@ -651,7 +656,7 @@ public function validateEstimatedArea(Request $request) $projectId = $sitePolygon->project_id; $sumEstArea = SitePolygon::where('project_id', $projectId) - ->sum('est_area'); + ->sum('calc_area'); $project = Project::where('uuid', $projectId) ->first(); @@ -676,35 +681,102 @@ public function validateEstimatedArea(Request $request) return response()->json(['valid' => $valid, 'sum_area_project' => $sumEstArea, 'total_area_project' => $totalHectaresRestoredGoal, 'insertionSuccess' => $insertionSuccess], 200); } - public function getPolygonsAsGeoJSON() + public function getPolygonAsGeoJSON(Request $request) { - $limit = 2; - $polygons = PolygonGeometry::select(DB::raw('ST_AsGeoJSON(geom) AS geojson')) - ->orderBy('created_at', 'desc') - ->whereNotNull('geom') - ->limit($limit) - ->get(); - $features = []; - - foreach ($polygons as $polygon) { - $coordinates = json_decode($polygon->geojson)->coordinates; + try { + $uuid = $request->query('uuid'); + + $polygonGeometry = PolygonGeometry::where('uuid', $uuid) + ->select(DB::raw('ST_AsGeoJSON(geom) AS geojson')) + ->first(); + if (! $polygonGeometry) { + return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); + } + + $sitePolygon = SitePolygon::where('poly_id', $uuid)->first(); + if (! $sitePolygon) { + return response()->json(['message' => 'No site polygon found for the given UUID.'], 404); + } + + $properties = []; + $fieldsToValidate = [ + 'poly_name', + 'plantstart', + 'plantend', + 'practice', + 'target_sys', + 'distr', + 'num_trees', + 'uuid', + 'site_id' + ]; + foreach ($fieldsToValidate as $field) { + $properties[$field] = $sitePolygon->$field; + } + + $propertiesJson = json_encode($properties); + $feature = [ - 'type' => 'Feature', - 'geometry' => [ - 'type' => 'Polygon', - 'coordinates' => $coordinates, - ], - 'properties' => [], + 'type' => 'Feature', + 'geometry' => json_decode($polygonGeometry->geojson), + 'properties' => json_decode($propertiesJson), + ]; + + $featureCollection = [ + 'type' => 'FeatureCollection', + 'features' => [$feature], ]; - $features[] = $feature; + + return response()->json($featureCollection); + } catch (\Exception $e) { + return response()->json(['message' => 'Failed to generate GeoJSON.', 'error' => $e->getMessage()], 500); } - $geojson = [ - 'type' => 'FeatureCollection', - 'features' => $features, - ]; + } - // Return the GeoJSON data - return response()->json($geojson); + public function getAllPolygonsAsGeoJSON(Request $request) + { + try { + $siteUuid = $request->query('uuid'); + $polygonsUuids = SitePolygon::where('site_id', $siteUuid)->pluck('poly_id'); + $features = []; + foreach ($polygonsUuids as $polygonUuid) { + $feature = []; + $polygonGeometry = PolygonGeometry::where('uuid', $polygonUuid) + ->select(DB::raw('ST_AsGeoJSON(geom) AS geojson')) + ->first(); + if (! $polygonGeometry) { + return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); + } + + $sitePolygon = SitePolygon::where('poly_id', $polygonUuid)->first(); + if (! $sitePolygon) { + return response()->json(['message' => 'No site polygon found for the given UUID.'], 404); + } + + $properties = []; + $fieldsToValidate = ['poly_name', 'plantstart', 'plantend', 'practice', 'target_sys', 'distr', 'num_trees']; + foreach ($fieldsToValidate as $field) { + $properties[$field] = $sitePolygon->$field; + } + + $propertiesJson = json_encode($properties); + + $feature = [ + 'type' => 'Feature', + 'geometry' => json_decode($polygonGeometry->geojson), + 'properties' => json_decode($propertiesJson), + ]; + $features[] = $feature; + } + $featureCollection = [ + 'type' => 'FeatureCollection', + 'features' => $features, + ]; + + return response()->json($featureCollection); + } catch (\Exception $e) { + return response()->json(['message' => 'Failed to generate GeoJSON.', 'error' => $e->getMessage()], 500); + } } public function getAllCountryNames() diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php index b9c57ecf5..850a0f109 100644 --- a/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php +++ b/app/Http/Controllers/V2/Terrafund/TerrafundEditGeometryController.php @@ -2,11 +2,14 @@ namespace App\Http\Controllers\V2\Terrafund; +use App\Helpers\GeometryHelper; use App\Http\Controllers\Controller; use App\Models\V2\PolygonGeometry; +use App\Models\V2\Projects\Project; use App\Models\V2\Sites\SitePolygon; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Log; use Illuminate\Support\Str; class TerrafundEditGeometryController extends Controller @@ -26,18 +29,108 @@ public function getSitePolygonData(string $uuid) } } - public function updateGeometry(string $uuid, Request $request) + public function updateEstAreainSitePolygon($polygonGeometry, $geometry) { - $polygonGeometry = PolygonGeometry::where('uuid', $uuid)->first(); - if (! $polygonGeometry) { - return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); + try { + $sitePolygon = SitePolygon::where('poly_id', $polygonGeometry->uuid)->first(); + + if ($sitePolygon) { + $geojson = json_encode($geometry); + $areaSqDegrees = DB::selectOne("SELECT ST_Area(ST_GeomFromGeoJSON('$geojson')) AS area")->area; + $latitude = DB::selectOne("SELECT ST_Y(ST_Centroid(ST_GeomFromGeoJSON('$geojson'))) AS latitude")->latitude; + $unitLatitude = 111320; + $areaSqMeters = $areaSqDegrees * pow($unitLatitude * cos(deg2rad($latitude)), 2); + $areaHectares = $areaSqMeters / 10000; + + $sitePolygon->calc_area = $areaHectares; + $sitePolygon->save(); + + Log::info("Updated area for site polygon with UUID: $sitePolygon->uuid"); + } else { + Log::warning("Updating Area: Site polygon with UUID $polygonGeometry->uuid not found."); + } + } catch (\Exception $e) { + Log::error('Error updating area in site polygon: ' . $e->getMessage()); + } + } + + public function updateProjectCentroid($polygonGeometry) + { + try { + $sitePolygon = SitePolygon::where('poly_id', $polygonGeometry->uuid)->first(); + + if ($sitePolygon) { + $project = Project::where('uuid', $sitePolygon->project_id)->first(); + + if ($project) { + $geometryHelper = new GeometryHelper(); + $centroid = $geometryHelper->centroidOfProject($project->uuid); + + if ($centroid === null) { + Log::warning("Invalid centroid for project UUID: $project->uuid"); + } + } else { + Log::warning("Project with UUID $sitePolygon->project_id not found."); + } + } else { + Log::warning("Site polygon with UUID $polygonGeometry->uuid not found."); + } + } catch (\Exception $e) { + Log::error('Error updating project centroid: ' . $e->getMessage()); + } + } + + public function deletePolygonAndSitePolygon(string $uuid) + { + try { + $polygonGeometry = PolygonGeometry::where('uuid', $uuid)->first(); + if (! $polygonGeometry) { + return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); + } + $sitePolygon = SitePolygon::where('poly_id', $uuid)->first(); + $projectUuid = $sitePolygon->project_id; + if (! $projectUuid) { + return response()->json(['message' => 'No project found for the given UUID.'], 404); + } + if ($sitePolygon) { + Log::info("Deleting associated site polygon for UUID: $uuid"); + $sitePolygon->delete(); + } + $geometryHelper = new GeometryHelper(); + $geometryHelper->updateProjectCentroid($projectUuid); + $polygonGeometry->delete(); + Log::info("Polygon geometry and associated site polygon deleted successfully for UUID: $uuid"); + + return response()->json(['message' => 'Polygon geometry and associated site polygon deleted successfully.', 'uuid' => $uuid]); + } catch (\Exception $e) { + Log::error('An error occurred: ' . $e->getMessage()); + + // Return error response if an exception occurs + return response()->json(['error' => 'An error occurred: ' . $e->getMessage()], 500); } - $geometry = json_decode($request->input('geometry')); - $geom = DB::raw("ST_GeomFromGeoJSON('" . json_encode($geometry) . "')"); - $polygonGeometry->geom = $geom; - $polygonGeometry->save(); + } + + public function updateGeometry(string $uuid, Request $request) + { + try { + Log::info("Updating geometry for polygon with UUID: $uuid"); - return response()->json(['message' => 'Geometry updated successfully.', 'geometry' => $geometry, 'uuid' => $uuid]); + $polygonGeometry = PolygonGeometry::where('uuid', $uuid)->first(); + if (! $polygonGeometry) { + return response()->json(['message' => 'No polygon geometry found for the given UUID.'], 404); + } + $geometry = json_decode($request->input('geometry')); + $geom = DB::raw("ST_GeomFromGeoJSON('" . json_encode($geometry) . "')"); + $polygonGeometry->geom = $geom; + $polygonGeometry->save(); + Log::info('ABOUT TO CREATE'); + $this->updateEstAreainSitePolygon($polygonGeometry, $geometry); + $this->updateProjectCentroid($polygonGeometry); + + return response()->json(['message' => 'Geometry updated successfully.', 'geometry' => $geometry, 'uuid' => $uuid]); + } catch (\Exception $e) { + return response()->json(['error' => 'An error occurred: ' . $e->getMessage()], 500); + } } public function getPolygonGeojson(string $uuid) @@ -49,7 +142,7 @@ public function getPolygonGeojson(string $uuid) $geojsonData = json_decode($geometryQuery->select(DB::raw('ST_AsGeoJSON(geom) as geojson'))->first()->geojson, true); return response()->json([ - 'geojson' => $geojsonData, + 'geojson' => $geojsonData, ]); } @@ -67,7 +160,7 @@ public function updateSitePolygon(string $uuid, Request $request) 'practice' => 'nullable|string', 'distr' => 'nullable|string', 'num_trees' => 'nullable|integer', - 'est_area' => 'nullable|numeric', + 'calc_area' => 'nullable|numeric', 'target_sys' => 'nullable|string', ]); @@ -84,13 +177,13 @@ public function createSitePolygon(string $uuid, Request $request) { try { $validatedData = $request->validate([ - 'poly_name' => 'nullable|string', - 'plantstart' => 'nullable|date', - 'plantend' => 'nullable|date', - 'practice' => 'nullable|string', - 'distr' => 'nullable|string', - 'num_trees' => 'nullable|integer', - 'target_sys' => 'nullable|string', + 'poly_name' => 'nullable|string', + 'plantstart' => 'nullable|date', + 'plantend' => 'nullable|date', + 'practice' => 'nullable|string', + 'distr' => 'nullable|string', + 'num_trees' => 'nullable|integer', + 'target_sys' => 'nullable|string', ]); $polygonGeometry = PolygonGeometry::where('uuid', $uuid)->first(); @@ -102,14 +195,14 @@ public function createSitePolygon(string $uuid, Request $request) $areaSqMeters = $areaSqDegrees * pow(111320 * cos(deg2rad($latitude)), 2); $areaHectares = $areaSqMeters / 10000; $sitePolygon = new SitePolygon([ - 'poly_name' => $validatedData['poly_name'], - 'plantstart' => $validatedData['plantstart'], - 'plantend' => $validatedData['plantend'], - 'practice' => $validatedData['practice'], - 'distr' => $validatedData['distr'], - 'num_trees' => $validatedData['num_trees'], - 'est_area' => $areaHectares, // Assign the calculated area - 'target_sys' => $validatedData['target_sys'], + 'poly_name' => $validatedData['poly_name'], + 'plantstart' => $validatedData['plantstart'], + 'plantend' => $validatedData['plantend'], + 'practice' => $validatedData['practice'], + 'distr' => $validatedData['distr'], + 'num_trees' => $validatedData['num_trees'], + 'calc_area' => $areaHectares, // Assign the calculated area + 'target_sys' => $validatedData['target_sys'], ]); $sitePolygon->poly_id = $uuid; $sitePolygon->uuid = Str::uuid(); @@ -121,4 +214,17 @@ public function createSitePolygon(string $uuid, Request $request) return response()->json(['error' => 'An error occurred: ' . $e->getMessage()], 500); } } + + public function getPolygonBbox(string $uuid) + { + try { + $bboxCoordinates = GeometryHelper::getPolygonsBbox([$uuid]); + + return response()->json(['bbox' => $bboxCoordinates]); + } catch (\Exception $e) { + Log::error($e->getMessage()); + + return response()->json(['error' => 'An error occurred while fetching the bounding box coordinates'], 404); + } + } } diff --git a/app/Http/Controllers/V2/Terrafund/TerrafundPointsController.php b/app/Http/Controllers/V2/Terrafund/TerrafundPointsController.php new file mode 100644 index 000000000..a4fa2c996 --- /dev/null +++ b/app/Http/Controllers/V2/Terrafund/TerrafundPointsController.php @@ -0,0 +1,53 @@ +centroidOfProject($projectUuid); + + return $centroid; + } + + public function updateProjectCentroids() + { + $geometryHelper = new GeometryHelper(); // Instantiate GeometryHelper + + $projectUuids = Project::distinct()->pluck('uuid'); + + foreach ($projectUuids as $projectUuid) { + $centroid = $geometryHelper->centroidOfProject($projectUuid); + + if ($centroid === null) { + Log::warning("Invalid centroid for projectUuid: $projectUuid"); + + continue; + } + + $centroidArray = json_decode($centroid, true); + + $latitude = $centroidArray['coordinates'][1]; + $longitude = $centroidArray['coordinates'][0]; + + + Project::where('uuid', $projectUuid) + ->update([ + 'lat' => $latitude, + 'long' => $longitude, + ]); + + + Log::info("Centroid updated for projectUuid: $projectUuid"); + } + + return 'Centroids updated successfully!'; + } +} diff --git a/database/migrations/2024_04_22_145957_add_user_geospatial_fields.php b/database/migrations/2024_04_22_145957_add_user_geospatial_fields.php new file mode 100644 index 000000000..170af9746 --- /dev/null +++ b/database/migrations/2024_04_22_145957_add_user_geospatial_fields.php @@ -0,0 +1,29 @@ +string('program')->nullable(); + $table->string('country')->nullable(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('users', function (Blueprint $table) { + $table->dropColumn('program'); + $table->dropColumn('country'); + }); + } +}; diff --git a/database/migrations/2024_04_22_215000_add_column_lat_and_long_to_v2_project_table.php b/database/migrations/2024_04_22_215000_add_column_lat_and_long_to_v2_project_table.php new file mode 100644 index 000000000..dd29dd4cb --- /dev/null +++ b/database/migrations/2024_04_22_215000_add_column_lat_and_long_to_v2_project_table.php @@ -0,0 +1,33 @@ +decimal('lat', 10, 8)->nullable(); + $table->decimal('long', 11, 8)->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('v2_projects', function (Blueprint $table) { + $table->dropColumn('lat'); + $table->dropColumn('long'); + }); + } +}; diff --git a/database/migrations/2024_04_2_121238_create_sites_polygons.php b/database/migrations/2024_04_2_121238_create_sites_polygons.php index 8b5a227e1..782393534 100644 --- a/database/migrations/2024_04_2_121238_create_sites_polygons.php +++ b/database/migrations/2024_04_2_121238_create_sites_polygons.php @@ -18,22 +18,16 @@ public function up() $table->id(); $table->uuid('uuid')->unique(); $table->string('project_id')->nullable(); - $table->string('proj_name')->nullable(); $table->string('site_id')->nullable(); - $table->string('site_name')->nullable(); - $table->string('org_name')->nullable(); $table->string('poly_id')->nullable(); $table->string('poly_name')->nullable(); - $table->string('poly_label')->nullable(); $table->date('plantstart')->nullable(); $table->date('plantend')->nullable(); $table->string('practice')->nullable(); $table->string('target_sys')->nullable(); $table->string('distr')->nullable(); $table->integer('num_trees')->nullable(); - $table->float('est_area')->nullable(); - $table->date('date_modified')->nullable(); - $table->string('country')->nullable(); + $table->decimal('calc_area', 15, 2)->nullable(); $table->string('status')->nullable(); $table->string('created_by')->nullable(); $table->string('last_modified_by')->nullable(); diff --git a/routes/api_v2.php b/routes/api_v2.php index 426143a3e..fcef5cbe6 100644 --- a/routes/api_v2.php +++ b/routes/api_v2.php @@ -156,6 +156,7 @@ use App\Http\Controllers\V2\Sites\Monitoring\AdminUpdateSiteMonitoringController; use App\Http\Controllers\V2\Sites\Monitoring\ViewSiteMonitoringController; use App\Http\Controllers\V2\Sites\SoftDeleteSiteController; +use App\Http\Controllers\V2\Sites\SitePolygonDataController; use App\Http\Controllers\V2\Sites\ViewASitesMonitoringsController; use App\Http\Controllers\V2\Stages\DeleteStageController; use App\Http\Controllers\V2\Stages\IndexStageController; @@ -554,6 +555,8 @@ Route::get('/{site}/image/locations', SiteImageLocationsController::class); Route::delete('/{site}', SoftDeleteSiteController::class); Route::get('/{site}/export', ExportAllSiteDataAsProjectDeveloperController::class); + Route::get('/{site}/polygon', [SitePolygonDataController::class, 'getSitePolygonData']); + Route::get('/{site}/bbox', [SitePolygonDataController::class, 'getBboxOfCompleteSite']); }); Route::prefix('project-monitorings')->group(function () { @@ -607,8 +610,9 @@ Route::post('/upload-shapefile', [TerrafundCreateGeometryController::class, 'uploadShapefile']); Route::post('/upload-kml', [TerrafundCreateGeometryController::class, 'uploadKMLFile']); Route::post('/polygon/{uuid}', [TerrafundCreateGeometryController::class, 'processGeometry']); + Route::get('/geojson/complete', [TerrafundCreateGeometryController::class, 'getPolygonAsGeoJSON']); + Route::get('/geojson/site', [TerrafundCreateGeometryController::class, 'getAllPolygonsAsGeoJSON']); - Route::get('/geojson/complete', [TerrafundCreateGeometryController::class, 'getPolygonsAsGeoJSON']); Route::get('/validation/self-intersection', [TerrafundCreateGeometryController::class, 'checkSelfIntersection']); Route::get('/validation/size-limit', [TerrafundCreateGeometryController::class, 'validatePolygonSize']); Route::get('/validation/spike', [TerrafundCreateGeometryController::class, 'checkBoundarySegments']); @@ -623,9 +627,15 @@ Route::get('/polygon/{uuid}', [TerrafundEditGeometryController::class, 'getSitePolygonData']); Route::get('/polygon/geojson/{uuid}', [TerrafundEditGeometryController::class, 'getPolygonGeojson']); Route::put('/polygon/{uuid}', [TerrafundEditGeometryController::class, 'updateGeometry']); + Route::delete('/polygon/{uuid}', [TerrafundEditGeometryController::class, 'deletePolygonAndSitePolygon']); + + Route::get('/polygon/bbox/{uuid}', [TerrafundEditGeometryController::class, 'getPolygonBbox']); Route::put('/site-polygon/{uuid}', [TerrafundEditGeometryController::class, 'updateSitePolygon']); Route::post('/site-polygon/{uuid}', [TerrafundEditGeometryController::class, 'createSitePolygon']); + + Route::get('/centroids/{uuid}', [TerrafundPointsController::class, 'calculateCentroidOfCentroids']); + Route::get('/centroids-update', [TerrafundPointsController::class, 'updateProjectCentroids']); }); Route::get('/funding-programme', [FundingProgrammeController::class, 'index'])->middleware('i18n');