Skip to content

Commit d5624ec

Browse files
committed
Update shpConversion.py
1 parent c87bb20 commit d5624ec

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

avaframe/in2Trans/shpConversion.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def SHP2Array(infile, defname=None):
5858
number of features per line (parts)
5959
6060
"""
61-
# Input shapefile
61+
# Input shapefile
6262
sf = shapefile.Reader(str(infile))
6363
infile = pathlib.Path(infile)
6464
# set defaults for variables
@@ -115,9 +115,11 @@ def SHP2Array(infile, defname=None):
115115

116116
# check if records are available and extract
117117
if records:
118+
# loop through fields
118119
# Extract attributes for the feature
119120
attr_dict = {}
120121
for (name, typ, size, deci), value in zip(sf.fields[1:], records[n].record):
122+
# get entity name
121123
name = name.lower()
122124
attr_dict[name] = value # Store attributes in dictionary
123125

@@ -129,6 +131,7 @@ def SHP2Array(infile, defname=None):
129131
if name == "ci95":
130132
ci95 = value
131133
if name == "slope":
134+
# for dams
132135
slope = value
133136
if name == "rho":
134137
rho = value
@@ -137,7 +140,12 @@ def SHP2Array(infile, defname=None):
137140
if name == "iso":
138141
iso = value
139142
if name == "layer":
140-
layerN = value
143+
layerN = value
144+
# if name is still empty go through file again and take Layer instead
145+
if (type(layername) is bytes) or (layername is None):
146+
for (name, typ, size, deci), value in zip(sf.fields[1:], records[n].record):
147+
if name == "Layer":
148+
layername = value
141149

142150
attributes.append(attr_dict) # Add the attribute dictionary to the list
143151

0 commit comments

Comments
 (0)