mjaschen / phpgeo

Simple Yet Powerful Geo Library for PHP
https://phpgeo.marcusjaschen.de
MIT License
1.56k stars 195 forks source link

Polyline / Simplification: add additional properties and/or keep original array keys? #58

Open wivaku opened 4 years ago

wivaku commented 4 years ago

Want to Simplify a GPX track, which includes not only lat+lon but also timestamps and other properties. After simplification, I want to retain these additional properties (most likely only the timestamp, the others need to be recalculated).

Looking at the documentation: https://phpgeo.marcusjaschen.de/Transformations_and_Processing/Simplifying_a_Polyline.html

How can I create a Polyline to be used by Simplify, which includes not only lat+lon, but additional properties? A la

$polyline->addPoint(new Coordinate($point['lat'], $point['lon']), $gpxDetails);

Alternatively, can you make it possible to retain the original array keys of the Polyline? (e.g. $simplified->getPoints(): [ 0 => [...], 3 => [...], 9 => [...] ])

PS. the Github example for Simplify does not work, the one in the documentation does.

wivaku commented 4 years ago

Alternatively: how can I modify the class? A la the example class MyPoint implements PointInterface mentioned here: https://github.com/emcconville/point-reduction-algorithms This way I can load points that include other properties, where getCoordinates is modified to get lat & lon from the custom Point.

mjaschen commented 4 years ago

Hi, that's currently not possible and I think that's out of scope for this library. For the time being you've to split the location data from other meta, simplify locations and merge both parts together again.

mjaschen commented 4 years ago

Extending the geometry classes (Coordinate, Polyline, etc.) is currently not possible. That would required the extensive use of interfaces instead of concrete classes in many places. I'd like to see such an abstraction introduced, but it's definitely a task for a new major release.