-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add swagger for bbox country from worldcountriesgenerated
- Loading branch information
1 parent
02b34d4
commit e0b11a7
Showing
4 changed files
with
76 additions
and
30 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
app/Http/Controllers/V2/Dashboard/CountryDataController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\V2\Dashboard; | ||
|
||
use App\Http\Controllers\Controller; | ||
use App\Models\V2\PolygonGeometry; | ||
use App\Models\V2\Projects\Project; | ||
use App\Models\V2\Sites\CriteriaSite; | ||
use App\Models\V2\Sites\SitePolygon; | ||
use App\Models\V2\WorldCountryGeneralized; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Facades\Storage; | ||
use Illuminate\Support\Str; | ||
use Symfony\Component\Process\Process; | ||
|
||
class CountryDataController extends Controller | ||
{ | ||
public function getCountryBbox(string $iso) | ||
{ | ||
// Get the bbox of the country and the name | ||
$countryData = WorldCountryGeneralized::where('iso', $iso) | ||
->selectRaw('ST_AsGeoJSON(ST_Envelope(geometry)) AS bbox, country') | ||
->first(); | ||
|
||
if (! $countryData) { | ||
return response()->json(['error' => 'Country not found'], 404); | ||
} | ||
|
||
// Decode the GeoJSON bbox | ||
$geoJson = json_decode($countryData->bbox); | ||
|
||
// Extract the bounding box coordinates | ||
$coordinates = $geoJson->coordinates[0]; | ||
|
||
// Get the country name | ||
$countryName = $countryData->country; | ||
|
||
// Construct the bbox data in the specified format | ||
$countryBbox = [ | ||
$countryName, | ||
[$coordinates[0][0], $coordinates[0][1], $coordinates[2][0], $coordinates[2][1]] | ||
]; | ||
|
||
return response()->json(['bbox' => $countryBbox]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters