ncssar / sartopo_python

Python calls for the caltopo / sartopo API -- SUPERCEDED by caltopo_python
GNU General Public License v3.0
16 stars 2 forks source link

expand: handle the case where the two polygons don't intersect #21

Closed caver456 closed 3 years ago

caver456 commented 3 years ago

in this case, the result will be a multipolygon. Rather than die with an error, simple return false, i.e. don't try to modify the original shape.

caver456 commented 3 years ago

the test code, operating on a map with two polygons a11 and a13 that don't intersect:

a11=sts.getFeatures(title='a11')[0]
a13=sts.getFeatures(title='a13')[0]
sts.expand(a11,a13)

the error message:

Traceback (most recent call last):
  File "test.py", line 34, in <module>
    sts.expand(a11,a13)
  File "C:\Users\caver\Documents\GitHub\sartopo_python\sartopo_python\sartopo_python.py", line 1163, in expand
    self.editObject(id=targetShape['id'],geometry={'coordinates':[list(result.exterior.coords)]})
AttributeError: 'MultiPolygon' object has no attribute 'exterior'
caver456 commented 3 years ago

There are at least a few different ways to intercept this error. For now, catch it early: if the objects don't intersect, show a message and return false. Apply this to all geom ops.