Initial commit - construprogress app
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
<?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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user