1

I am iterating through a CSV file of tornadoes, and for each row getting the beginning lat, beginning long, ending lat, and ending long. and trying to plot their line geometry on a map. I got the points for the starting points but I am having troubles creating the lines to show the path of the tornadoes.

I have:

for i, row in dataframe.iterrows():
    lx = row[begin_long],[ending_long]
    ly = row[begin_lat],[ending_lat]
    line_geometry.append(LineString(lx,ly))
  • 1
    The LineString expects something like LineString([(x1, y1), (x2, y2)]), while now you pass ((x1, x2), (y1, y2)) – joris Dec 10 '19 at 9:52
0

The LineString object is initalised with a list of coordinate pairs, e.g.

line = LineString([(0, 1), (2, 3)])

It looks like your coordinates are in a DataFrame. In that case you can use the DataFrame.apply method to create a linestring:

df = DataFrame([[0, 1, 2, 3], [4, 5, 6, 7]], columns=["x0", "x1", "y0", "y1"])

def make_line(row):
    coordinates = [(row["x0"], row["y0"]), (row["x1"], row["y1"])]
    return LineString(coordinates)

df["line"] = df.apply(make_line, axis=1)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.