ncssar / sartopo_python

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

'size' and 'incremental' in cropped track edit request #45

Closed caver456 closed 2 years ago

caver456 commented 2 years ago

Noticed during debug of a failed crop which is due to bad return value from fourify:

08:58:27 [sartopo_bg:1508:INFO]   Outing AB 102: cropping 1 uncropped track(s):['0298d38c-6623-487a-a894-400389bd8321']
08:58:27 [sartopo_bg:1510:INFO]    cropping 0298d38c-6623-487a-a894-400389bd8321
08:58:27 [sartopo_python:621:INFO] refresh requested for map P68: 1284ms since last completed sync; shorter than syncInterval; forceImmediate not specified: not syncing now
08:58:27 [sartopo_python:621:INFO] refresh requested for map P68: 1286ms since last completed sync; shorter than syncInterval; forceImmediate not specified: not syncing now
08:58:27 [sartopo_python:1964:INFO] crop: target=0298d38c-6623-487a-a894-400389bd8321  boundary=bf104985-8cfd-4d1f-a1e7-d2c6b1b72dfa
08:58:27 [sartopo_python:1470:INFO] spur removed at [-120.92181185136342, 39.30702305738722]
08:58:27 [sartopo_python:1470:INFO] spur removed at [-120.92100914108661, 39.30678468713071]
08:58:27 [sartopo_python:1470:INFO] spur removed at [-120.92040119298338, 39.306889045613296]
08:58:27 [sartopo_python:729:INFO] sending post to http://localhost:8080/api/v1/map/P68/Shape
08:58:27 [sartopo_python:753:INFO] {'json': '{"properties": {"title": "grownBoundary", "description": "", "stroke-width": 2, "stroke-opacity": 1, "stroke": "#A200FF", "fill": "#A200FF", "fill-opacity": 0.1, "gpstype": "TRACK"}, "geometry": {"type": "Polygon", "coordinates": "1 segment (167 points)"}}'}
08:58:27 [sartopo_python:1994:INFO] a
08:58:28 [sartopo_python:2074:INFO] adding shape to result list
08:58:28 [sartopo_python:2076:INFO] four:632
08:58:28 [sartopo_python:1345:INFO] editFeature called
08:58:28 [sartopo_python:1386:INFO]  id specified: 0298d38c-6623-487a-a894-400389bd8321
08:58:28 [sartopo_python:729:INFO] sending post to http://localhost:8080/api/v1/map/P68/Shape/0298d38c-6623-487a-a894-400389bd8321
08:58:28 [sartopo_python:753:INFO] {'json': '{"type": "Feature", "id": "0298d38c-6623-487a-a894-400389bd8321", "geometry": {"size": 1160, "coordinates": "633 points", "incremental": true, "type": "LineString"}}'}
08:58:28 [sartopo_python:621:INFO] refresh requested for map 90K: 2237ms since last completed sync; shorter than syncInterval; forceImmediate not specified: not syncing now
08:58:28 [sartopo_python:634:INFO] Sartopo syncing initiated for map 90K.

'size' and 'incremental' keys are only referenced during addAppTrack, but a logging line in that command confirms that the function is never called (and this is a shape anyway, not an apptrack) - AB102f in the training map

'size' and 'incremental' do not exist in the original json. How the heck are they getting there?

The fourify question is a separate issue; bypassing fourify and just using the coordinates from the shapely result gives a clean correctly cropped line and looks like this in the log:

08:58:28 [sartopo_python:2074:INFO] adding shape to result list
08:58:28 [sartopo_python:2076:INFO] four:632
08:58:28 [sartopo_python:1345:INFO] editFeature called
08:58:28 [sartopo_python:1386:INFO]  id specified: 0298d38c-6623-487a-a894-400389bd8321
08:58:28 [sartopo_python:729:INFO] sending post to http://localhost:8080/api/v1/map/P68/Shape/0298d38c-6623-487a-a894-400389bd8321
08:58:28 [sartopo_python:753:INFO] {'json': '{"type": "Feature", "id": "0298d38c-6623-487a-a894-400389bd8321", "geometry": {"size": 1160, "coordinates": "633 points", "incremental": true, "type": "LineString"}}'}
08:58:28 [sartopo_python:621:INFO] refresh requested for map 90K: 2237ms since last completed sync; shorter than syncInterval; forceImmediate not specified: not syncing now
08:58:28 [sartopo_python:634:INFO] Sartopo syncing initiated for map 90K.
caver456 commented 2 years ago

'size' and 'incremental' are in the response from the POST request used to create the new line (sartopo_python.addLine rjr) - 'size' is equal to the number of points in the payload, and incremental is what it is - no need to change it until/unless it is understood.

So - what happens if an incorrect / stale size value is passed to the edit request? Should it be updated in the request? Omitted? Or does it matter / is it OK to send the stale value, if the host revises it based on payload anyway? Take a look at the response from the edit request.

caver456 commented 2 years ago

The response from the edit request still contains the stale size.

A separate getFeature afterwards (with forceImmediate=True) does not contain the size or incremental keys at all.

So this is kind of a dilemma. Not sure what if anything makes use of the size value.

Probably the best choice here is to just make sure that whenever size is sent, that it's accurate. So, inside editFeature, if geometry is specified, then size should also be recalculated and the new value should be used. If the host later decides to drop it, o well.

caver456 commented 2 years ago

Fixed by adding these lines in editFeature:

            if isinstance(geometry,dict) and 'coordinates' in geometry.keys():
                geometry['size']=len(geometry['coordinates'])
            # logging.info('geometry specified (size was recalculated if needed):\n'+json.dumps(geometry))