1

So I want to create a LineString and get the length of the LineString from two sets of LatLon coordinates (points) in each row in a Pandas Dataframe, and store in a new column

Blockquote

How can I do this?

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Nov 22, 2018 at 13:09
1

1 Answer 1

1

You can use apply to create the output column like this:

import shapely.geometry as geom
your_df['geometry'] = your_df.apply(lambda x: geom.LineString([(x['startlat'], x['startlon']) , (x['endlat'], x['endlon'])]), axis = 1)

If your coordinates columns aren't float make sure to parse them first with float(...)

answered Nov 22, 2018 at 14:03
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.