Skip to content

Commit 7b07b56

Browse files
committed
Remove last of unnecessary else: s
1 parent f5752a0 commit 7b07b56

1 file changed

Lines changed: 44 additions & 50 deletions

File tree

src/shapefile.py

Lines changed: 44 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -618,10 +618,9 @@ def __geo_interface__(self) -> GeoJsonShapeT:
618618

619619
return {"type": "MultiPolygon", "coordinates": polys}
620620

621-
else:
622-
raise GeoJSON_Error(
623-
f'Shape type "{SHAPETYPE_LOOKUP[self.shapeType]}" cannot be represented as GeoJSON.'
624-
)
621+
raise GeoJSON_Error(
622+
f'Shape type "{SHAPETYPE_LOOKUP[self.shapeType]}" cannot be represented as GeoJSON.'
623+
)
625624

626625
@staticmethod
627626
def _from_geojson(geoj) -> Shape:
@@ -1053,7 +1052,7 @@ def __init__(
10531052
raise ShapefileException(
10541053
"Zipfile does not contain any shapefiles"
10551054
)
1056-
elif len(shapefiles) == 1:
1055+
if len(shapefiles) == 1:
10571056
shapefile = shapefiles[0]
10581057
else:
10591058
raise ShapefileException(
@@ -1088,12 +1087,12 @@ def __init__(
10881087
# Load and exit early
10891088
self.load()
10901089
return
1091-
else:
1092-
raise ShapefileException(
1093-
f"No shp or dbf file found in zipfile: {path}"
1094-
)
10951090

1096-
elif path.startswith("http"):
1091+
raise ShapefileException(
1092+
f"No shp or dbf file found in zipfile: {path}"
1093+
)
1094+
1095+
if path.startswith("http"):
10971096
# Shapefile is from a url
10981097
# Download each file to temporary path and treat as normal shapefile path
10991098
urlinfo = urlparse(path)
@@ -1126,16 +1125,13 @@ def __init__(
11261125
# Load and exit early
11271126
self.load()
11281127
return
1129-
else:
1130-
raise ShapefileException(
1131-
f"No shp or dbf file found at url: {path}"
1132-
)
11331128

1134-
else:
1135-
# Local file path to a shapefile
1136-
# Load and exit early
1137-
self.load(path)
1138-
return
1129+
raise ShapefileException(f"No shp or dbf file found at url: {path}")
1130+
1131+
# Local file path to a shapefile
1132+
# Load and exit early
1133+
self.load(path)
1134+
return
11391135

11401136
if not isinstance(shp, _NoShpSentinel):
11411137
self.shp = self.__seek_0_on_file_obj_wrap_or_open_from_name("shp", shp)
@@ -1208,44 +1204,42 @@ def __len__(self):
12081204

12091205
return self.numRecords
12101206

1211-
elif self.shp:
1207+
if self.shp:
12121208
# Otherwise use shape count
12131209
if self.shx:
12141210
if self.numShapes is None:
12151211
self.__shxHeader()
12161212

12171213
return self.numShapes
12181214

1219-
else:
1220-
# Index file not available, iterate all shapes to get total count
1221-
if self.numShapes is None:
1222-
# Determine length of shp file
1223-
shp = self.shp
1224-
checkpoint = shp.tell()
1225-
shp.seek(0, 2)
1226-
shpLength = shp.tell()
1227-
shp.seek(100)
1228-
# Do a fast shape iteration until end of file.
1229-
offsets = []
1230-
pos = shp.tell()
1231-
while pos < shpLength:
1232-
offsets.append(pos)
1233-
# Unpack the shape header only
1234-
(__recNum, recLength) = unpack_2_int32_be(shp.read(8))
1235-
# Jump to next shape position
1236-
pos += 8 + (2 * recLength)
1237-
shp.seek(pos)
1238-
# Set numShapes and offset indices
1239-
self.numShapes = len(offsets)
1240-
self._offsets = offsets
1241-
# Return to previous file position
1242-
shp.seek(checkpoint)
1243-
1244-
return self.numShapes
1245-
1246-
else:
1247-
# No file loaded yet, treat as 'empty' shapefile
1248-
return 0
1215+
# Index file not available, iterate all shapes to get total count
1216+
if self.numShapes is None:
1217+
# Determine length of shp file
1218+
shp = self.shp
1219+
checkpoint = shp.tell()
1220+
shp.seek(0, 2)
1221+
shpLength = shp.tell()
1222+
shp.seek(100)
1223+
# Do a fast shape iteration until end of file.
1224+
offsets = []
1225+
pos = shp.tell()
1226+
while pos < shpLength:
1227+
offsets.append(pos)
1228+
# Unpack the shape header only
1229+
(__recNum, recLength) = unpack_2_int32_be(shp.read(8))
1230+
# Jump to next shape position
1231+
pos += 8 + (2 * recLength)
1232+
shp.seek(pos)
1233+
# Set numShapes and offset indices
1234+
self.numShapes = len(offsets)
1235+
self._offsets = offsets
1236+
# Return to previous file position
1237+
shp.seek(checkpoint)
1238+
1239+
return self.numShapes
1240+
1241+
# No file loaded yet, treat as 'empty' shapefile
1242+
return 0
12491243

12501244
def __iter__(self):
12511245
"""Iterates through the shapes/records in the shapefile."""

0 commit comments

Comments
 (0)