Vote count:
0
I have a file with many sections like the following:
[40.742742,-73.993847]
[40.739389,-73.985667]
[40.74715499999999,-73.97992]
[40.750573,-73.988415]
[40.742742,-73.993847]
[40.734706,-73.991915]
[40.736917,-73.990263]
[40.736104,-73.98846]
[40.740315,-73.985263]
[40.74364800000001,-73.993353]
[40.73729099999999,-73.997988]
[40.734706,-73.991915]
[40.729226,-74.003463]
[40.7214529,-74.006038]
[40.717745,-74.000389]
[40.722299,-73.996634]
[40.725291,-73.994413]
[40.729226,-74.003463]
[40.754604,-74.007836]
[40.751289,-74.000649]
[40.7547179,-73.9983309]
[40.75779,-74.0054339]
[40.754604,-74.007836]
I need to read in each of these sections as a list of pairs of coordinates (Each section being separated by an extra \n
).
In a similar file I have (same except there are no extra newline breaks), I am drawing one polygon from the whole file. I can use the following code to read in the coordinates and draw it in matplotlib:
mVerts = []
with open('Manhattan_Coords.txt') as f:
for line in f:
pair = [float(s) for s in line.strip()[1:-1].split(", ")]
mVerts.append(pair)
plt.plot(*zip(*mVerts))
plt.show()
How can I accomplish the same task, except with many more than 1 polygon, each polygon in my file separated by an extra newline?
asked 23 secs ago
How can I read a file as nested lists of coordinates for multiple polygons?
Aucun commentaire:
Enregistrer un commentaire