Opened 15 years ago

Closed 9 years ago

#3050 closed enhancement (duplicate)

(re)build .shx file if missing or corrupt

Reported by: onnovl Owned by: warmerdam
Priority: normal Milestone:
Component: OGR_SF Version: unspecified
Severity: normal Keywords: shapelib
Cc:

Description

When I try to read the attached shapefile using gdal v 1.61 it fails. ArcMap and fwtools can load it without problems

c:\gdal\apps>ogrinfo -al "Coquitlam model extents.shp" INFO: Open of `Coquitlam model extents.shp'

using driver `ESRI Shapefile' successful.

Layer name: Coquitlam model extents Geometry: Polygon Feature Count: 1 Extent: (512327.353138, 5451672.031000) - (521044.434885, 5462154.161192) Layer SRS WKT: (unknown) Coquitlam m: Real (31.15) ERROR 1: Error in fseek() or fread() reading object from .shp file. OGRFeature(Coquitlam model extents):0

Coquitlam m (Real) = 25.000000000000000

Attachments (1)

Coquitlam model extents.zip (3.3 KB ) - added by onnovl 15 years ago.

Download all attachments as: .zip

Change History (7)

by onnovl, 15 years ago

Attachment: Coquitlam model extents.zip added

comment:1 by Even Rouault, 15 years ago

Which fwtools can load it ? I guess a pretty old one that makes no checks. I think the .shx file has been generated by a buggy software. According to the shapefile specification, the integer at offset 104 of the .shx file should be * the half * of the number of bytes of the first feature (number of 16bit words). But in the file, it is exactly the number of bytes of the first feature (3408 = 0x00000d50) instead of (1704 = 0x000006a8). If I put the later value, ogrinfo can read it successfully.

I'm not convinced that shapelib should be tolerant with respect to such corrupted files.

comment:2 by onnovl, 15 years ago

Dear Roualt, Thanks for the quick reply SHP and DBF files are "linked" simply by the order of the records in the files. So the SHX file isn't needed to read the data. It is only required if you want to read the data through the index. Therefore I think when the shx file is bad it should not prevent you from reading the shapefile. Apart from that windows xp system restore monitors shx files. After a system restore it may corrupt a lot of shapefiles by changing the shx file content. Kind regards Onno

comment:3 by warmerdam, 15 years ago

Component: defaultOGR_SF
Keywords: shapelib added
Summary: ogr fails to read shapefile with invalid extends (shx)(re)build .shx file if missing or corrupt
Type: defectenhancement

The ESRI Shape driver (based on shapelib) always fetches shape geometries via a lookup in the .shx file currently. It may be desirable in the future to (re)build the .shx file if it is missing or obviously corrupt by scanning the .shp and assuming sequential ordering. I have converted this to an enhancement request.

I do not anticipate action in this regard in the near future.

comment:4 by onnovl, 15 years ago

Dear Frank Thanks for the reply. You are true it may be someone else's responsibility to have his or her shapefile in the correct format. Maybe you could change the error text to something like "cannot read this shapefile, shx file may be corrupted" Kind regards Onno van Logchem

comment:5 by Jukka Rahkonen, 9 years ago

Dublicate to #5035.

comment:6 by Even Rouault, 9 years ago

Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.