phpGPX icon indicating copy to clipboard operation
phpGPX copied to clipboard

Statistics - get Bounds of the GPX Routes

Open ramblerswebs opened this issue 6 years ago • 15 comments

A useful new feature would be to be able to obtain the bounds of points in the GPX file. So you would retrieve the min/max Longitude and Latitude. I am looking at this package to process walking routes to get overall stats. The bounds would allow me to display all my routes on a single map. Each walk would have an icon showing stats and a link to display the actual walk. I have only just found this project but it looks good.

ramblerswebs avatar Mar 27 '18 13:03 ramblerswebs

Hi, auto-generation of the Bounds object should be a nice feature. I can start with the implementation next week, or feel free to offer a PR.

Sibyx avatar Mar 28 '18 07:03 Sibyx

thanks, I am new to this package but it looks very good. It would be great to have the above facility.

On a side issue I am having trouble with my require statements as I seem to need them in a particular order. Is there an easy way to load these classes, I am running within Joomla which has its own autoload classes

ramblerswebs avatar Mar 28 '18 12:03 ramblerswebs

This feature is nice to have in a 2.x release. The bounding box will be created for each route, segment and track.

Sibyx avatar Jul 29 '23 19:07 Sibyx

Hello. +1 here. Any progress on this? Would you need help to implement it? I have this code in PHP in my project (reading a geojson file), which does the trick. It would be nice to have in this library.

// Find the bounds of the trace, for a later zoom in mapbox
$geojsonArray = json_decode($geoJson, true);
// Initialize variables to store the most NW and SE points
$north = -PHP_FLOAT_MAX; // Longest lat
$east = -PHP_FLOAT_MAX; // Longest lon
$south = PHP_FLOAT_MAX; // Smallest lat
$west = PHP_FLOAT_MAX; // Smallest lon
// Iterate through each feature and its coordinates
foreach ($geojsonArray['features'] as $feature) {
  foreach ($feature['geometry']['coordinates'] as $lineString) {
    foreach ($lineString as $point) {
      $lng = $point[0];
      $lat = $point[1];

      // Update northWest and southEast points if needed
      if ($lat > $north) {$north = $lat;}
      if ($lng > $east) {$east = $lng;}
      if ($lat < $south) {$south = $lat;}
      if ($lng < $west) {$west = $lng;}
    }
  }
}

miqwit avatar Mar 07 '24 20:03 miqwit

Yeah, I am sorry. I wish I had much more time for this project (think about it a lot). I don't want to make false promises about the deadline. If you offer a PR I will take a look. For the next two months, there is no way I will implement this. I am sorry. Thanks for your patience.

Sibyx avatar Mar 07 '24 21:03 Sibyx

I updated my algorithm, as it had a problem. I will be happy to contribute to your library, I'll try to find time. On the other hand, it would be handy to export the track as an actual GeoJSON, rather than a proprietary JSON. I create another issue for that.

miqwit avatar Mar 08 '24 07:03 miqwit

I worked on the bounds topic this morning, before seeing there is some work done in develop :( Still, I'd like to submit my code in a PR for a review, even if it's discarded at a later stage. Can you add me as a collaborator to the project? (I can't create a PR right now).

miqwit avatar Mar 08 '24 14:03 miqwit

@miqwit I will gladly wait for the PR ;) Sorry, but I am not right know a fan of direct access to the repository without PR process. I hope you are understand.

Sibyx avatar Mar 10 '24 19:03 Sibyx

Yes I do. My problem is that I can't create a PR at all. I get this error: "Pull request creation failed. Validation failed: must be a collaborator".

miqwit avatar Mar 10 '24 20:03 miqwit

@miqwit how did you created the feature branch? Did you created a fork? My proposed solution:

  1. Fork phpGPX
  2. Add you changes to the fork
  3. Create PR (hopefully without any problems)

Sibyx avatar Mar 10 '24 20:03 Sibyx

OK, so I reviewed the develop branch, and realised that it's taking the bounds from the GPX format, as described in the specification: https://www.topografix.com/GPX/1/1/#type_boundsType.

However, when the element is not in the GPX (I am in this situation) it can be useful to compute it ; only when it's not there already. In this case my code will be useful. I can go in this direction if you agree it's a good way.

First, can you tell me the state of the develop branch? Should I fork from there, or should I fork from master and include both my code and your code?

miqwit avatar Mar 14 '24 10:03 miqwit

Yeah, I agree that we should compute it. This feature should be configurable.

Currently, the state of the develop branch is according to the Project Roadmap in the #67 discussion. I think that we should focus on the 2.x release.

Sibyx avatar Mar 14 '24 11:03 Sibyx

But I have to admit that develop is right know not in the ideal state. There is still plenty of work regarding to the typing for example. I am already started with removing of the Summarizable interface and creating new configuration object.

Sibyx avatar Mar 14 '24 11:03 Sibyx

Yes, I see. What I can suggest is that I work on another branch, and I take from develop the work on the bounds, which is useful ; and in integrate my code (which respect the old-types format), what do you think? I created classes and even tests the way it is currently done (in master).

miqwit avatar Mar 14 '24 13:03 miqwit

Yeah, I guess that makes sense. Thank you very much. If you have any questions feel free to ask ;)

Sibyx avatar Mar 14 '24 17:03 Sibyx