Commit b3143c3d authored by Gaetano Raffaele's avatar Gaetano Raffaele

ENH: Added arrayToField function

parent 0e04f71f
......@@ -827,4 +827,23 @@ def queuedProcess(cmd_list,N_processes=4,shell=False,delay=0):
if len(cmd_queue) > 0:
prc_queue.append(subprocess.Popen(cmd_queue.pop(0), shell=shell))
time.sleep(delay)
break
\ No newline at end of file
break
def arrayToField(shp,fld,arr,type='float'):
ds = ogr.Open(shp,1)
ly = ds.GetLayer(0)
lydef = ly.GetLayerDefn()
in_type = ogr.OFTReal
in_type_np = np.float
if type == 'int':
in_type = ogr.OFTInteger
in_type_np = np.int
nf = ogr.FieldDefn(fld,in_type)
ly.CreateField(nf)
ly.ResetReading()
i = 0
for f in ly:
f.SetField(fld,arr[i].astype(in_type_np))
ly.SetFeature(f)
i += 1
ds = None
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment