Open shapefile from memory/stream

Jan 30, 2015 at 7:05 AM
How can I open shapefile from byte-array or memorystream without having to save it on disk? We have shapefiles as byte arrays in SQL database and I can read them into memory from there. The problem is I have to turn them into Shapefile object without using disk. Is this possible?
Developer
Jan 31, 2015 at 9:01 AM
No, I don't think it's possible without some extra work. Here are some approaches:
1) You can save it to the disk as temporary files (.shp, .shx, .dbf) and then read with Shapefile.LoadDataFrom method (it's loaded as in-memory shapefile so temporary files can be deleted at once).
2) Another approach is to store shapefile data in geometry / geography column and use OgrLayer class to access them directly.
3) As for direct loading of in-memory data, there is Shape.ImportFromBinary method which takes array of bytes as input. In theory you can populate in-memory shapefile with it, but you need to extract chunks of data for particular shapes from your memory stream in order to do it. So it's hardly an easy option.