45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Console\Commands;
|
||
|
|
|
||
|
|
use Illuminate\Console\Command;
|
||
|
|
use App\Services\SpatialFileConverter;
|
||
|
|
use App\Models\Phase;
|
||
|
|
|
||
|
|
class ConvertSpatialFile extends Command
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* The name and signature of the console command.
|
||
|
|
*
|
||
|
|
* @var string
|
||
|
|
*/
|
||
|
|
|
||
|
|
protected $signature = 'convert:spatial {file} {phase_id}';
|
||
|
|
protected $description = 'Convert a spatial file (DWG, SHP, KML, GeoJSON) to GeoJSON and attach to phase';
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Execute the console command.
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
$filePath = $this->argument('file');
|
||
|
|
$phaseId = $this->argument('phase_id');
|
||
|
|
$phase = Phase::findOrFail($phaseId);
|
||
|
|
$file = new \Illuminate\Http\UploadedFile($filePath, basename($filePath));
|
||
|
|
|
||
|
|
$geojson = SpatialFileConverter::convertToGeoJson($file, $file->getClientOriginalName());
|
||
|
|
if ($geojson) {
|
||
|
|
$layer = $phase->layers()->create([
|
||
|
|
'project_id' => $phase->project_id,
|
||
|
|
'name' => 'Converted: ' . basename($filePath),
|
||
|
|
'geojson_data' => $geojson,
|
||
|
|
'uploaded_by' => 1, // admin
|
||
|
|
'original_file' => $filePath
|
||
|
|
]);
|
||
|
|
$this->info("GeoJSON saved to layer ID {$layer->id}");
|
||
|
|
} else {
|
||
|
|
$this->error("Conversion failed for file type.");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|