calvinmetcalf / shapefile-js

Convert a Shapefile to GeoJSON. Not many caveats.
http://calvinmetcalf.github.io/shapefile-js/
MIT License
735 stars 230 forks source link

Support of shx file #111

Closed zarov closed 5 years ago

zarov commented 5 years ago

First, thanks for this useful library !

I was wondering, what about the support of the shx file ? If we take a look at the ESRI Shapefile description, here's what we can read about:

An ESRI shapefile consists of a main file, an index file, and a dBASE table. [...] In the index file, each record contains the offset of the corresponding main file record from the beginning of the main file.

Is it a choice to not use this here ?

calvinmetcalf commented 5 years ago

while the dbf file has constant sized rows, the size of features in the shp file varies, so in order to enable the ability to jump to rows at random in a shp file you need an index which is what the shx file is, a file with constant sized rows each of which points to the start of a feature. So if you wanted to go to feature 52, you'd go to the 52nd row in the shx and from there find the start potion of feature 52 in the shp file allowing you to skip directly to there.

This library simply takes in a shapefile and transforms it into geojson in a single go, so we just read the features sequentially meaning we have no need to jump around and thus no need to use the shx.

tl;dr it's not that we don't support the shx, its more that we don't need it, all the information to turn a shpfile into a geojson is in the shp and dbf (plus maybe the prj and cpg)

zarov commented 5 years ago

Ok thanks for the explanation