Skip to content

OSError Invalid argument when reading shape file #235

Closed
@INRIX-Mark-Gershaft

Description

@INRIX-Mark-Gershaft

On some shape files containing data from OSM (i.e. could be encoding or special characters in road name column) I am getting OSError Invalid argument.

reader = shapefile.Reader(shape_file, encodingErrors='replace')
fields = reader.fields[1:]
field_names = [field[0] for field in fields]
feature_count = 0
for sr in reader.iterShapeRecords():
    atr = dict(zip(field_names, sr.record))
    geom = sr.shape.__geo_interface__
   feature_count += 1

When I debugged what I see is that after it read last feature it is still not at the end of the file, thus in iterShapes() it thinks that there are more shapes and tries to read it:

while shp.tell() < self.shpLength:
            yield self.__shape()

Then in __shape() it parses recLength and it is garbage (some negative number), tries to compute next records' location and puts it somewhere beyond file's valid locations.

(recNum, recLength) = unpack(">2i", f.read(8))
next = f.tell() + (2 * recLength)

Since file has 600K features I don't really know how to help further.
What is strange though is that QGIS and GeoPandas are able to parse same file.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions