I’m processing large amount of geo datas, but occasionally encountered some cases:
RuntimeWarning: invalid value encountered in distance
return lib.distance(a, b, **kwargs)
RuntimeWarning: invalid value encountered in shortest_line
return lib.shortest_line(a, b, **kwargs)
I tried them in python console and found that some specific data will cause this waring but the result is even correct.
Here is the code and an example data that will cause this problem.
What makes it more weird is that it will only raise the warning for the first time python tries to calculate this piece of geodata.
>>> from shapely.geometry import Point, LineString, Polygon
>>> p = Point([444037.45235923684, 4432768.940062214])
>>> l = LineString([(444133.53324426746, 4432805.31270424),(444133.53324426746, 4432805.31270424),(444135.7614419243, 4432805.378952727),(444137.778475223, 4432805.432100361),(444139.7896194984, 4432805.446620431),(444141.81370974134, 4432805.440795805),(444143.84810851346, 4432805.423914926),(444145.8848029126, 4432805.401874071),(444147.92289024906, 4432805.380664571),(444149.96274860646, 4432805.363180846),(444152.0036369841, 4432805.350817922),(444154.0447198316, 4432805.344272887),(444156.08543010475, 4432805.343888665),(444158.1252506391, 4432805.349884151),(444160.1636512014, 4432805.362450611),(444162.2002235288, 4432805.381747374),(444164.23434018274, 4432805.408150714),(444166.2654926669, 4432805.442302018),(444168.292792287, 4432805.485611625),(444170.31557974376, 4432805.540908249),(444172.3342188634, 4432805.61411673),(444174.35935487103, 4432805.717899431)])
>>> d = p.distance(l)
C:UsersXXXAppDataLocalProgramsPythonPython39libsite-packagesshapelymeasurement.py:74: RuntimeWarning: invalid value encountered in distance
return lib.distance(a, b, **kwargs)
>>> print(d)
102.73512328429545
>>> d = p.distance(l)
>>> d = p.distance(l)
>>> print(d)
102.73512328429545