GeospatialPython / pyshp

This library reads and writes ESRI Shapefiles in pure Python.
MIT License
1.1k stars 260 forks source link

Allow random access to shapefile records #178

Closed chrisranderson closed 5 years ago

chrisranderson commented 5 years ago

This would be great for my use case - using a large shapefile and fairly often wanting to return specific geometries instead of iterating through entire thing looking for it. I'm picturing something like reader.getShapeRecords([13321, 482, 953]).

I don't understand the shapefile format - is this possible? Simple to implement?

karimbahgat commented 5 years ago

If I understand you correctly, this is already possible by specifying the index of each random feature you want (notice the single- rather than plural-tense):

reader.shapeRecord(13321)
reader.shapeRecord(482)
reader.shapeRecord(953)
chrisranderson commented 5 years ago

I do see shapeRecord in the Reader class, I guess that's what you mean. I do see that in the README now - I missed it there and didn't notice it in autocomplete. Sorry about that. It could be rare that people Google "random access" to describe what I was trying to do; would it be helpful to add that to the README?

Maybe an alias of getShapeRecord on the Reader class would be useful since we both thought that's what the name of the method was. :)

karimbahgat commented 5 years ago

Yes, that's right, not sure why I wrote 'get' in there. Feel free to insert the relevant language where you see fit in the README and create a PR, then if it looks good I'll merge it.

Probably wait on the alias for now. But I think adding a quickstart tutorial, more easily available docs + reference API on ReadTheDocs would go a long way in making it easier to look up the functionality. Hope to get that added sometime soon.