Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

append point to linstring #88

Open
stefanocudini opened this issue Feb 4, 2014 · 3 comments
Open

append point to linstring #88

stefanocudini opened this issue Feb 4, 2014 · 3 comments

Comments

@stefanocudini
Copy link

hi

how can I append new point at end of gpx track?

$newPoint = geoPHP::load('POINT(12.23 45.2)','wkt');

$trackFile = 'mytrack.gpx';

$track = geoPHP::load(file_get_contents($trackFile),'gpx');

...???append point???...

file_put_contents($trackFile, $out);
@mprins
Copy link
Contributor

mprins commented Feb 5, 2014

you would probably nee to get the last point of your track, use that and newPoint to build a line and then use [union()] to join the two lines (https://github.com/phayes/geoPHP/blob/master/lib/geometry/Geometry.class.php#L222) (requires geos) and assuming your track exists of only one segment

the other option is to serialize to string, append the point to the string and deserialize from string

@stefanocudini
Copy link
Author

Thank you for answer.
I'm resolved in this way:

    $trackFile = 'track.gpx';
    $loc = array(42.34,13.23);  //new POINT
    $locGeo = geoPHP::load('POINT('.implode(' ',$loc).')','wkt');

    $track = geoPHP::load(file_get_contents($trackFile),'gpx');

    $trackAr =  $track->asArray();

    if( $locGeo->equals($track->endPoint()) )
        die('this last point just exists');
    else
        $trackAr[]= $loc;

    $trackOut = array();
    foreach($trackAr as $v)
        $trackOut[]= new Point($v[0],$v[1]);

    $trackOut = new LineString($trackOut);

    $out = $trackOut->out('gpx');

    file_put_contents($trackFile, $out);

@stefanocudini
Copy link
Author

maybe a new method: addPoint inside LineString class could be useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants