-1

Have a list of coordinate pairs based on the provided longitudes and latitudes and I want to store the list in a variable coordpairs.

I try using the code below. When I checked the coordinate pair I only get the value for the longitude.

for x in range(len(longitudes)):
    longitudes[x]
    
for y in range(len(latitudes)):
    latitudes[y]
    
    coordpairs = (longitudes[x], latitudes[y])
    print(coordpairs)

I have about 20 latlon point that I want to pass to a coordinate pair and then use the coordinate pair to create a polygon using this code: poly = Polygon(coordpairs)

1 Answers1

0

Due to your current indentation, coordpairs is only seeing the last value of longitudes each time it loops through y.

If you would like to use loops, you could do something like this (assuming your longitudes and latitudes lists are the same length)

coordpairs = []
for coord_num in range(len(longitudes)):
    coord_pair = [longitudes[coord_num], latitudes[coord_num]]
    coordpairs.append(coord_pair)

If you want to combine each item in longitudes with each item in latitudes without using loops, you can use

list(zip(longitudes, latitudes))
ldmichae
  • 46
  • 1
  • 2