cowegis/cowegis-geojson
PHP 8.2+ GeoJSON library for the Cowegis project implementing the GeoJSON specification (RFC 7946). Install via Composer (cowegis/cowegis-geojson) to work with GeoJSON data in your PHP applications.
jsonb or geometry types).FormRequest classes).protected $casts = ['coordinates' => Cowegis\GeoJson\GeoJson::class];GeoJson::encode() in API resources.return GeoJson::encode($model->geometry);jsonb (PostgreSQL) or geometry (PostGIS) with manual conversion.json_encode for simple cases.GeoJson::encode() in API responses.jsonb (PostgreSQL) or geometry (PostGIS) types.// app/Models/Location.php
use Cowegis\GeoJSON\GeoJson;
class Location extends Model {
protected $casts = [
'geometry' => GeoJson::class,
];
// Automatically serializes/deserializes GeoJSON
}
// app/Http/Resources/LocationResource.php
public function toArray($request) {
return [
'coordinates' => GeoJson::encode($this->geometry),
];
}
// app/Http/Requests/StoreLocationRequest.php
public function rules() {
return [
'geometry' => ['required', new ValidateGeoJson],
];
}
// app/Http/Middleware/ValidateGeoJson.php
public function handle($request, Closure $next) {
if ($request->has('geo_data')) {
GeoJson::validate($request->geo_data);
}
return $next($request);
}
jsonb for flexibility or geometry for PostGIS queries.ALTER TABLE locations ADD COLUMN geometry geometry(Point, 4326);json column type (limited geospatial support).L.geoJSON()).mapboxgl.Layer).ol.format.GeoJSON).| Phase | Task | Dependencies |
|---|---|---|
| Prep | Update composer.json and PHP to 8.2+. |
Dev environment setup. |
| Validation | Add GeoJSON validation to API endpoints (middleware/requests). | Existing request/response structure. |
| Model Layer | Extend Eloquent models with GeoJSON casting. | Database schema changes (if needed). |
| API Layer | Standardize GeoJSON in API responses/resources. | Model layer updates. |
| Database | Migrate GeoJSON fields to jsonb/geometry types. |
Model layer integration. |
| Frontend Sync | Ensure frontend libraries parse returned GeoJSON correctly. | API contract stability. |
| Testing | Validate edge cases (invalid GeoJSON, large payloads, performance). | All prior phases. |
| Deprecation | Phase out custom GeoJSON logic. | Full integration testing. |
How can I help you explore Laravel packages today?