ncssar / sartopo_python

Python calls for the caltopo / sartopo API
GNU General Public License v3.0
14 stars 2 forks source link

lines don't always have pattern, description, gpstype keys in properties dict #52

Closed caver456 closed 1 year ago

caver456 commented 1 year ago

Noticed during a crop test to see if #42 was addressed during plans_console commits:

2022-12-17 11:17:19,885 [CRITICAL] Uncaught exception:
Traceback (most recent call last):
  File "C:\Users\caver\Documents\GitHub\sartopo_python\sartopo_python\test4.py", line 93, in <module>
    r=sts.crop('CW209D','cropper') # line (finished apptrack)
  File "C:\Users\caver\Documents\GitHub\sartopo_python\sartopo_python\sartopo_python.py", line 2350, in crop
    pattern=tp['pattern'],
KeyError: 'pattern'

Sure enough:

# line CW209D imported from json - was a finished apptrack
#  - this is missing keys pattern, description, gsptype

            # "properties": {
            #    "stroke-opacity": 1,
            #    "creator": "11UEE9",
            #    "stroke-width": 2,
            #    "fill": "solid",
            #    "title": "CW209D",
            #    "stroke": "#FF0000",
            #    "class": "Shape",
            #    "updated": 1668200413000,
            #    "timestamp": 1671304623741
            # }

# then changed to dashed style:
            # "properties": {
            #    "stroke-opacity": 1,
            #    "creator": "11UEE9",
            #    "pattern": "M0 -3 L0 3,,12,F",
            #    "description": "",
            #    "stroke-width": 2,
            #    "fill": "#FF0000",
            #    "title": "CW209D",
            #    "stroke": "#FF0000",
            #    "class": "Shape",
            #    "updated": 0,
            #    "timestamp": 1671304412938,
            #    "gpstype": "TRACK"
            # }

# then changed back to solid style:
            # "properties": {
            #    "stroke-opacity": 1,
            #    "creator": "11UEE9",
            #    "pattern": "solid",
            #    "description": "",
            #    "stroke-width": 2,
            #    "fill": "#FF0000",
            #    "title": "CW209D",
            #    "stroke": "#FF0000",
            #    "class": "Shape",
            #    "updated": 0,
            #    "timestamp": 1671304471144,
            #    "gpstype": "TRACK"
            # }

So, regardless of whether this is due to finished apptrack, or due to geojson import, or due to newer CTD version: sartopo_python needs to handle the missing keys gracefully.

Start by looking for places in the code that care about these specific missing keys (pattern, description, gpstype) but also consider that other keys could be missing at various times.