laravel-mysql-spatial icon indicating copy to clipboard operation
laravel-mysql-spatial copied to clipboard

Generate normalized GeoJSON

Open sribna opened this issue 5 years ago • 3 comments

Readme says I can use toJson() method to get a GeoJSON string

$point = new Point(40.7484404, -73.9878441);
$point->toJson();

// {
//   "type": "Feature",
//   "properties": {},
//   "geometry": {
//     "type": "Point",
//     "coordinates": [
//       -73.9878441,
//       40.7484404
//     ]
//   }
// }

In reality it returns {"type":"Point","coordinates":[-73.9878441,40.7484404]} whish is't a valid GeoJson format

Maybe add toGeoJson method?

sribna avatar Jan 26 '20 23:01 sribna

Additionaly it would be nice if we could use the properties field eg by defining a variable in our model to specify columns which will be added to the properties field

Glutamat42 avatar Feb 27 '20 23:02 Glutamat42

@sribna thank you for reporting this. You're absolutely right, the documentation is inaccurate: toJson() actually returns the geometry part of the Feature.

Adding toGeoJson() and updating the documentation sounds like a good idea.

grimzy avatar Mar 06 '20 19:03 grimzy

@Glutamat42, also a good suggestion!

Any suggestion(s) on the implementation?

grimzy avatar Mar 06 '20 19:03 grimzy