Currently dealing with two errors while programming the code shown below, I was wondering if anybody could help me or give some tips to solve them, thank you.
1) When trying to assign multiple LineString
objects to a MultiLineString
object I encountered difficulties. The idea is to create a name
depending on the feeder (fdr
) and use it as a variable in the MultiLineString
object. Different methods were tried (e.g. globals()[], list comprehension,..), but generate errors or like in the code below gives an AssertionError
. The problem is that namen
produces string objects 'l_6_1', 'l_6_2', .. while variables l_6_1, l_6_2, .. are required. (SOLVED)
2) My second question is related to calculating lengths, where the gdf
are read with espg:4326
, I applied a conversion in the class object (which changes the LineString object! --this has been checked), meanwhile the result from print(lengte)
isn't affected.. Any ideas where my mistakes are?
class Lines:
def __init__(self, fdr, node, gdf):
j= 1
lines= {}
gdf= gdf.to_crs({'init': 'epsg:3857'})
for i, k in zip(node[0::2], node[1::2]):
name= 'l_'+str(fdr)+'_'+str(j)
lines[name]= LineString([gdf.loc[i][['X', 'Y']], gdf.loc[k][['X', 'Y']]])
lengte= lines[name].length
print(lengte)
j= j+1
lines= pd.Series(lines)
s= lines.values
f= geometry.MultiLineString([l_6_0]+ list(s))
self.f = ops.linemerge(f)
Further I append this to a map and save (& export) since I work with Spyder.
x= Lines(6, nodes_6, gdf6)
folium.GeoJson(x.f).add_to(m)
m.save(os.path.join(dest, "grid.html"))