-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We should subscribe to the FileIO interface so we can deal with streaming files as well...
- Loading branch information
1 parent
a9acd12
commit 6dc7db8
Showing
4 changed files
with
70 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module ShapefileZipFileExt | ||
import ZipFile, Shapefile | ||
import Shapefile: _read_shp_from_zipfile | ||
function _read_shp_from_zipfile(zipfile) | ||
r = ZipFile.Reader(zipfile) | ||
# need to get dbx | ||
shpdata, shxdata, dbfdata, prjdata = nothing, nothing, nothing, nothing | ||
for f in r.files | ||
fn = f.name | ||
lfn = lowercase(fn) | ||
if endswith(lfn, ".shp") | ||
shpdata = IOBuffer(read(f)) | ||
elseif endswith(lfn, ".shx") | ||
shxdata = read(f, Shapefile.IndexHandle) | ||
elseif endswith(lfn, ".dbf") | ||
dbfdata = Shapefile.DBFTables.Table(IOBuffer(read(f))) | ||
elseif endswith(lfn, "prj") | ||
prjdata = try | ||
Shapefile.GeoFormatTypes.ESRIWellKnownText(Shapefile.GeoFormatTypes.CRS(), read(f, String)) | ||
catch | ||
@warn "Projection file $zipfile/$lfn appears to be corrupted. `nothing` used for `crs`" | ||
nothing | ||
end | ||
end | ||
end | ||
close(r) | ||
@assert shpdata !== nothing | ||
shp = if shxdata !== nothing # we have shxdata/index | ||
read(shpdata, Shapefile.Handle, shxdata) | ||
else | ||
read(shpdata, Shapefile.Handle) | ||
end | ||
if prjdata !== nothing | ||
shp.crs = prjdata | ||
end | ||
return Shapefile.Table(shp, dbfdata) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters