Skip to content

Commit c61f5c2

Browse files
committed
Rename size_B and size_16b_words correctly in ShpWriter._shp_file_length_B
1 parent 805be08 commit c61f5c2

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ part of your geospatial project.
9595

9696
## 3.0.14.dev
9797
### ShpWriter.shape API Tweak (small breaking change).
98-
- Make ShpWriter.shape return shape length in bytes (like offset) not in 16 bit words.
98+
- Make ShpWriter.shape return shape length in bytes (the
99+
same as for offset) not in 16 bit words.
99100

100101

101102
## 3.0.13

changelog.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
VERSION 3.0.14.dev
22

33
2026-06-20
4-
* API Tweak (small breaking change). Make ShpWriter.shape return shape length in bytes (like offset) not in 16 bit words.
4+
* API Tweak (small breaking change). Make ShpWriter.shape return shape length in bytes
5+
(the same as for offset) not in 16 bit words.
56

67
VERSION 3.0.13
78

src/shapefile.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4134,7 +4134,11 @@ def _header(self) -> None:
41344134
def _write_file_length(self) -> None:
41354135
# self.file required to be at correct position, e.g.
41364136
# if called by self._header
4137-
self.file.write(pack(">i", self._shp_file_length_B()))
4137+
4138+
# Calculate size as 16-bit words
4139+
size_B = self._shp_file_length_B()
4140+
size_16b_words = size_B // 2
4141+
self.file.write(pack(">i", size_16b_words))
41384142

41394143
def _shp_file_length_B(self) -> int:
41404144
"""Calculates the file length of the shp file."""
@@ -4143,9 +4147,7 @@ def _shp_file_length_B(self) -> int:
41434147

41444148
# Calculate size of all shapes
41454149
self.file.seek(0, 2)
4146-
size_16b_words = self.file.tell()
4147-
# Calculate size as 16-bit words
4148-
size_B = size_16b_words // 2
4150+
size_B = self.file.tell()
41494151
# Return to start
41504152
self.file.seek(start_B)
41514153
return size_B
@@ -4199,7 +4201,7 @@ def shape(
41994201
self,
42004202
s: Shape | HasGeoInterface | GeoJSONHomogeneousGeometryObject,
42014203
) -> tuple[int, int]:
4202-
"""Returns shape's offset and length in B"""
4204+
"""Appends s to the file. Returns shape's offset and length in B"""
42034205
if not isinstance(s, Shape):
42044206
if isinstance(s, HasGeoInterface):
42054207
shape_dict = s.__geo_interface__
@@ -4216,7 +4218,7 @@ def shape(
42164218
return self._shp_record(s)
42174219

42184220
def _shp_record(self, s: Shape) -> tuple[int, int]:
4219-
"""Returns shape's offset and length in B"""
4221+
"""Appends s to the file. Returns shape's offset and length in B"""
42204222
offset = self.file.tell()
42214223
self.shpNum += 1
42224224

0 commit comments

Comments
 (0)