1

I'm working in a Jupyter Notebook and deleted code I thought I didn't need the other. Now I get an overflow error, when running the notebook. I'm pretty sure the code used to work just fine and the problem is caused by me stupidly deleting stuff.

Anyway, I can't seem to find what is missing and would really appreciate help. I'm using a list with coordinates, convert them to a linestring and then transform them. Finally, I lookup the length.

import pyproj
from pyproj import Transformer
from shapely.ops import transform
from shapely.geometry import LineString

route = [[41.875562, -87.624421], [29.949932, -90.070116], [40.712728, -74.006015]]

ls = LineString(route) 

project = pyproj.Transformer.from_proj(
    pyproj.Proj(init='epsg:4326'),
    pyproj.Proj(init='epsg:3857'))

ls_metric = transform(project.transform, ls) 

ls_metric_length = round(ls_metric.length / 1000)

This returns

OverflowError: cannot convert float infinity to integer

The problem arises already with ls_metric which doesn't generate a LineString.

Georgy
  • 12,464
  • 7
  • 65
  • 73

1 Answers1

1

I ran your code and got this warning:

FutureWarning: '+init=<authority>:<code>' syntax is deprecated.
'<authority>:<code>' is the preferred initialization method

Sure enough I changed the pyproj Transformer and got a result:

project = pyproj.Transformer.from_proj(
    pyproj.Proj('epsg:4326'),
    pyproj.Proj('epsg:3857'))

gives a length of 3984 km. I used the latest versions in a venv:

pyproj==2.6.0
Shapely==1.7.0

The warning above also gives another important note regarding axis order changes; in short:

pyproj.Proj('epsg:4326') works with [lat,lng], [lat,lng] ...
pyproj.Proj(init='epsg:4326') works with [lng,lat], [lng,lat] ...

the first one being the preferred way while the second is deprecated.

Ionut Ticus
  • 2,683
  • 2
  • 17
  • 25
  • Thank you for your help! It is still not working on my notebook though. I'm beginning to think that something must be wrong with my installation... – johajippijupp Mar 23 '20 at 07:57
  • I just tried it in a new Jupyer notebook and worked; maybe your notebook is using old(er) packages. – Ionut Ticus Mar 23 '20 at 09:06
  • 1
    For the axis order changes, you can pass in 'always_xy=True' when creating the transformer. – snowman2 Mar 23 '20 at 13:45
  • Hi @lonut Ticus Could please help me with https://stackoverflow.com/questions/68668657/why-i-am-receiving-infinity-infity-in-linestring – R. Baraiya Jun 03 '22 at 13:08