jongough / ocpn_draw_pi

OpenCPN general drawing plug in
7 stars 17 forks source link

Automatic refresh of GPX #510

Open eried opened 1 year ago

eried commented 1 year ago

hi, is there is a way to automatically reload a layer gpx file? or a timer, or when it changes?

jongough commented 1 year ago

Not at the moment.

eried commented 1 year ago

ok thanks for answering. I was thinking on what would be easier (i.e. if I attempt to code it), probably just a X minute reload... because detecting changes would be tied to the OS

jongough commented 1 year ago

What are you wanting to do that is not done already? OD only handles its own objects and has an API, both JSON and Binary, which can be used to change the objects that OD handles. All other stuff is done by OCPN or another plugin.

eried commented 1 year ago

I just need to update a permanent layer every x minutes

jongough commented 1 year ago

Can you provide an example gpx file that you want to update?

eried commented 1 year ago

Sure, for example (in this case without ocpn_draw features, but the concept is the same):

<?xml version="1.0"?>
<gpx version="1.1" creator="OpenCPN" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd" xmlns:opencpn="http://www.opencpn.org">
  <rte>
    <name>Nets (boat name)</name>
    <desc>something</desc>
    <extensions>
      <opencpn:guid>8d2b0cad-bcdd-43ab-93d3-a9290cbbafe4</opencpn:guid>
      <opencpn:viz>1</opencpn:viz>
      <opencpn:planned_speed>6.00</opencpn:planned_speed>
      <opencpn:planned_departure>2022-10-25T11:40:42Z</opencpn:planned_departure>
      <opencpn:time_display>PC</opencpn:time_display>
      <opencpn:style width="5" />
      <gpxx:RouteExtension>
        <gpxx:IsAutoNamed>false</gpxx:IsAutoNamed>
        <gpxx:DisplayColor>Blue</gpxx:DisplayColor>
      </gpxx:RouteExtension>
    </extensions>
    <rtept lat="63.048216666667" lon="7.6747833333333">
      <time>2022-10-25T13:40:21Z</time>
      <name>Nets (boat name)</name>
      <desc>something</desc>
      <sym>diamond</sym>
      <type>WPT</type>
      <extensions>
        <opencpn:guid>29DC016C-3CEC-49B9-828A-60F7FA1076FE</opencpn:guid>
        <opencpn:viz_name>1</opencpn:viz_name>
        <opencpn:arrival_radius>0.050</opencpn:arrival_radius>
        <opencpn:waypoint_range_rings visible="false" number="0" step="1" units="0" colour="#FF0000" />
        <opencpn:scale_min_max UseScale="false" ScaleMin="2147483646" ScaleMax="0" />
      </extensions>
    </rtept>
  </rte>
</gpx>

And then some task downloaded the new one with a different position:

<?xml version="1.0"?>
<gpx version="1.1" creator="OpenCPN" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.topografix.com/GPX/1/1" xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd http://www.garmin.com/xmlschemas/GpxExtensions/v3 http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd" xmlns:opencpn="http://www.opencpn.org">
  <rte>
    <name>Nets (boat name)</name>
    <desc>something</desc>
    <extensions>
      <opencpn:guid>8d2b0cad-bcdd-43ab-93d3-a9290cbbafe4</opencpn:guid>
      <opencpn:viz>1</opencpn:viz>
      <opencpn:planned_speed>6.00</opencpn:planned_speed>
      <opencpn:planned_departure>2022-10-25T11:40:42Z</opencpn:planned_departure>
      <opencpn:time_display>PC</opencpn:time_display>
      <opencpn:style width="5" />
      <gpxx:RouteExtension>
        <gpxx:IsAutoNamed>false</gpxx:IsAutoNamed>
        <gpxx:DisplayColor>Blue</gpxx:DisplayColor>
      </gpxx:RouteExtension>
    </extensions>
    <rtept lat="63.05" lon="7.675">
      <time>2022-10-25T13:40:21Z</time>
      <name>Nets (boat name)</name>
      <desc>something</desc>
      <sym>diamond</sym>
      <type>WPT</type>
      <extensions>
        <opencpn:guid>29DC016C-3CEC-49B9-828A-60F7FA1076FE</opencpn:guid>
        <opencpn:viz_name>1</opencpn:viz_name>
        <opencpn:arrival_radius>0.050</opencpn:arrival_radius>
        <opencpn:waypoint_range_rings visible="false" number="0" step="1" units="0" colour="#FF0000" />
        <opencpn:scale_min_max UseScale="false" ScaleMin="2147483646" ScaleMax="0" />
      </extensions>
    </rtept>
  </rte>
</gpx>
jongough commented 1 year ago

I was more interested in what gpx file you want OD to reload on a timer so that I can see what objects have to be 'updated'. At the moment there are ways to load and save gpx files in OD, but this is user initiated for OD objects only. Are you trying to implement dynamic boundaries or text points, or something else altogether?

eried commented 1 year ago

yes, mostly mark fishing spots and update them every 30 mins or so. Now it can work via reopening opencpn because the file gets updated in the background, but I wonder what would be the easiest way to get it updated inside the program

That is the reason I was checking this plugin because it also has the benefits of more powerful drawing tools for the same fishing spots: the gpx import in opencpn is a bit buggy (i.e. export and import of a gpx does not always get the same on screen)

jongough commented 1 year ago

You would need to use a similar technique to that used by squiddio to put in OD Text Points of places of interest. This uses the JSON message API to load up the places. It sounds like you would need to use OD_CreateTextPoint and OD_DeleteTextPoint to mark places of significance and delete and recreate those that have changed. Reloading files that have not changed would effectively slow down OCPN, particularly on smaller machines, as it is single threaded and currently is approaching capacity limits. OD is purely a drawing tool and makes its objects available to other plugins to use via the JSON and Binary APIs.

Who and what is going to update this gpx file? What objects are going to be in the gpx file? OD only 'knows' about its objects and not OCPN objects. So WayPoints do not work in OD. If the file contains WayPoints/RoutePoints these would need converting to the OD naming (the definitions for OD points are based on OCPN WayPoints with extra additions to allow the more complex displays).