OpenGIS / inreach-mapshare

Display Your Live inReach MapShare Data on Your WordPress Site
GNU General Public License v2.0
8 stars 1 forks source link

Feature request... making coordinates less precise #5

Open mmcc-xx opened 1 month ago

mmcc-xx commented 1 month ago

I'm working on a Wordpress site that will let people follow my son's progress as he bicycles across the US. While I'd like visitors to know his location, I'd feel better if it was a little less exact in case of creepy stalkers.

Would it be possible to add an option to, maybe, remove the last digit of the coordinates returned by Garmin so that the location shown isn't quite as precise? I'd be happy to work on this, but could use some guidance on how you'd like to see it done.

morehawes commented 1 month ago

Hi mmcc-xx,

Nice suggestion! PRs welcome :)

There would need to be a Setting, to adjust the level of precision. This could then be passed to the Inreach class to modify the coordinates.

There is a build script which will re-build the plugin once changes have been made:

# Install dependencies
npm install

# Run build script
grunt

I hope this helps :)

Cheers,

Joe

yiddifliddo commented 1 month ago

I'd like that feature too !!

mmcc-xx commented 1 month ago

Cool - I'll take a swing at it.

mmcc-xx commented 1 month ago

It looks like the coordinates that come from Garmin go out to 6 decimal places.

According to this: https://support.garmin.com/en-US/?faq=hRMBoCTy5a7HqVkxukhHd8 that implies a precision of just over 10cm. I'm guessing it isn't really accurate to that degree.

Anyway, would a setting of something like "coordinate decimal places", with an acceptable value of an integer >= 1 and <= 6 make sense? The plugin would then round all coordinates to that number of decimal places.

Suggestions for what to label the setting are welcome.

morehawes commented 1 month ago

It looks like the coordinates that come from Garmin go out to 6 decimal places.

Thanks for the info. Looking at the demo.kml I see 6 decimal places provided for all coordinates.

that implies a precision of just over 10cm. I'm guessing it isn't really accurate to that degree.

Yes it varies widely in my experience.

Anyway, would a setting of something like "coordinate decimal places", with an acceptable value of an integer >= 1 and <= 6 make sense? The plugin would then round all coordinates to that number of decimal places.

I think it would be nice to offer this as a dropdown (i.e. <select>) and labelled in terms of distances (in approximate metric & imperial) rather than decimal places. I'm not sure what a good lower limit would be, but "anonymising" to say 1km... or 1 mile seems reasonable. Open to thoughts though!

Rounding could be done by either "slicing" the unwanted digits off of the end of a string, or converting to a number and rounding mathematically. I'm not sure how much difference that will make in reality, but might be worth considering.

How about "Location Precision" for the title? I think the InReach MapShare Settings > Advanced tab makes sense.

I have created a branch called precision, feel free to submit a PR including any changes there, even if not 100%.

Cheers,

Joe

mmcc-xx commented 1 month ago

I got the setting in and working locally, so... minor progress.

I'm trying to figure out where to do the rounding (or truncating - it probably doesn't really matter which).

If I'm understanding the flow of how things work correctly, it looks like I should do it in App/Inreach.php, in the build_geojson function, in two places. First, right before the last line of this snippet, I'd adjust the prevision of $coordinates:

if($Placemark->Point->coordinates) {
  $class_append = [];

  //Demo!
  if(! Joe_Log::has('do_demo')) {
    $time_ago = Joe_Helper::time_ago(strtotime($Placemark->TimeStamp->when));
  } else {        
    $class_append[] = 'inmap-demo';

    $time_ago = Joe_Helper::time_ago(strtotime($Placemark->TimeStamp->when), strtotime('5/21/2022 11:04:30 PM'));
  }

  //Coordinates
  $coordinates = explode(',', (String)$Placemark->Point->coordinates);                                

  //Invalid
  if(sizeof($coordinates) < 2 || sizeof($coordinates) > 3) {
    continue;           
  }

  $Feature['geometry']['type'] = 'Point';
  $Feature['geometry']['coordinates'] = $coordinates;

and second, just before the last line of this snippet, I'd fuzz the value of $coords:

} elseif($Placemark->LineString->coordinates) {
  $coordinates = (string)$Placemark->LineString->coordinates;
  $coordinates = preg_split('/\r\n|\r|\n/', $coordinates);

  //Valid array
  if(sizeof($coordinates)) {

    $Feature['geometry']['type'] = 'LineString';

    //Each Coordinate
    foreach($coordinates as $point) {
      $coords = explode(',', $point);                         

      //Invalid
      if(sizeof($coords) < 2 || sizeof($coords) > 3) {
        continue;           
      } 

      $Feature['geometry']['coordinates'][] = $coords;

Sound reasonable?

yiddifliddo commented 1 month ago

Is another way round this to time delay the posting, so even if it's accurate it doesn't show the current location only an old one ?

morehawes commented 1 month ago

@mmcc-xx,

Thanks for digging into this! Yes it looks like that would take care of both Points and LineStrings.

I think it makes sense to add a method to the Inreach Class that takes care of the fuzzying: accepting coord(s) as an argument, reading the Setting and returning the modified value.

Coords can then be passed after each //Invalid check to that method.

Cheers

morehawes commented 1 month ago

@yiddifliddo,

Is another way round this to time delay the posting, so even if it's accurate it doesn't show the current location only an old one ?

This should already possible using the InReach MapShare > Advanced > Cache Minutes Setting. Please let me know if that is not the case for you.

This issue is for a feature which will make locations less accurate, not simply delayed.

Thank you for your input! ❤️

mmcc-xx commented 1 month ago

@morehawes

@mmcc-xx,

Thanks for digging into this! Yes it looks like that would take care of both Points and LineStrings.

I think it makes sense to add a method to the Inreach Class that takes care of the fuzzying: accepting coord(s) as an argument, reading the Setting and returning the modified value.

Coords can then be passed after each //Invalid check to that method.

Cheers

Hi - ok that seemed to work for the drawing of the map, but the precise coordinates are still listed in the table. I'd like to truncate the data there as well - if you can point me in the right direction that would be great. Since I'm rather impatient I'll start looking for it in the code too :)

(Edit: I found it - I'm now looping through the extended data array and rounding off latitude and longitude before it is passed over to the Joe code for building the table. I'll get a pull request posted once I figure out how to post a pull request)

Below you can see that the location precision of 1km has been selected, that the first point in the demo data isn't in the same spot as it normally would be, but the full 6 digits of precision is displayed in the table.

image

morehawes commented 1 month ago

Hi @mmcc-xx,

Nice progress!

I'd like to truncate the data there as well - if you can point me in the right direction that would be great.

I had a quick look, a couple of thoughts:

I hope this helps. Feel free to make your fork public so I can view your edits.

Cheers,

Joe

mmcc-xx commented 1 month ago

I am relatively git and github ignorant but I've been asking chatgpt for help.

I cloned the repos locally and made my changes. I "git add"-ed the changed files, and did a "git commit". I fetched and checked out the precision branch, and merged my changed into that branch. Now I'm trying to push to the precision branch, but I'm getting permission denied. Do I need to be made a collaborator for that to work?

morehawes commented 1 month ago

@mmcc-xx,

You're looking to:

  1. Fork the precision branch.
  2. Apply your changes to your fork (pull locally, overwrite changed files, commit changes)
  3. Click the option to submit a PR.

From there I can review changes. I hope this helps.

Cheers,

Joe

mmcc-xx commented 1 month ago

Thanks for that - done.

morehawes commented 1 month ago

@yiddifliddo & @mmcc-xx,

I'd like that feature too !!

This has been added to version 2 of the plugin. Any testing/feedback greatly appreciated! 🙏

More information here.

Cheers,

Joe