-
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.
Allow Shapefile to read
.zip
files (#113)
* Allow Shapefile to read `.zip` files We should subscribe to the FileIO interface so we can deal with streaming files as well... Co-authored-by: David Gleich <[email protected]> * Add compat for ZipFiles * Add a test * Fix tests * Fix Makie ambiguity in convert_arguments definition * Switch from download to RemoteFile in tests * Increment minor version, but this is technically breaking...do we want that? * Update ShapefileMakieExt.jl --------- Co-authored-by: David Gleich <[email protected]>
- Loading branch information
1 parent
a9acd12
commit 35c8d42
Showing
5 changed files
with
101 additions
and
15 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
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