0

I have data from a JSONs like as below

data={'type': 'Feature', 'geometry': {'type': 'LineString', 'coordinates': 
[[410910.0885459831, 2479395.4132211693, 0.0], [410903.8088855865, 
2479401.860380645, 0.0], [410845.2521416071, 2479436.215147523, 0.0], 
[410844.8989142373, 2479436.568374893, 0.0], [410844.5338823536, 
2479436.90979775, 0.0], [410844.1588620354, 2479437.2403241317, 0.0], 
[410843.77385328256, 2479437.5581379607, 0.0]]}}

and I wish to make a concatenation on the elements like below in this line:

datas [i] ['geometry'] ['coordinates'] [j] [0]) +" "+ str (datas [i ] ['geometry'] ['coordinates'] [j] [1]of all existing sublists in coordinates.

Here is my code but unfortunately it does not work since it only gives me the last data [i] and not all the coordinates in the sublists

 path = os.path.join(dir, file)
 shapefile = ogr.Open(path)
 shape = shapefile.GetLayer()
 datas= [] 
 features=[]
 jsonstring=[]
 lines = []
 for i in range(len(shape)):
     features.append(shape.GetFeature(i))
     jsonstring.append(features[i].ExportToJson())   # myjson
     datas.append((json.loads(jsonstring[i])))

     for j in range(len(datas[i]['geometry']['coordinates'])-1):
         line = datas[i]['geometry']['type'] + "("+ str(datas[i]['geometry']['coordinates'][j][0])+" "+ str(datas[i]['geometry']['coordinates'][j][1])+")"
         lines.append(line)`

I'm using Python 3.x, and I would like to have in the end something like this:

LineString(410910.0885459831 2479395.4132211693, 410903.8088855865 2479401.860380645, ..... ,410843.77385328256, 2479437.558137960) 

for each data[i]

2
  • why not just get the feature geometry as WKT directly?
    – Ian Turton
    Jul 10 '20 at 9:15
  • @lan Turton, how can I get it directly please ?
    – nmokht97
    Jul 10 '20 at 11:37