Skip to content

Commit

Permalink
added docstring, added test cases, changed load function to use GeoDa…
Browse files Browse the repository at this point in the history
…taFrames instead of Shapefile package.
  • Loading branch information
00krishna committed Jun 18, 2024
1 parent b754589 commit c87455c
Show file tree
Hide file tree
Showing 11 changed files with 1,037 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ version = "0.0.1"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
EzXML = "8f5d6c58-4d21-5cfd-889c-e3ad7ee6a615"
GeoDataFrames = "62cb38b5-d8d2-4862-a48e-6a340996859f"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
OpenAPI = "d5e62ea6-ddf3-4d43-8e4c-ad5e6c8bfd7d"
Shapefile = "8e980c4a-a4fe-5da2-b3a7-4b4b0353a2f4"

[compat]
DataFrames = "1.4"
Expand Down
5 changes: 3 additions & 2 deletions src/IPUMS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module IPUMS
download as dl
import OpenAPI.Clients:
Client
import Shapefile:
Table
import GeoDataFrames:
read
using DataFrames:
DataFrames,
DataFrame,
Expand Down Expand Up @@ -66,5 +66,6 @@ module IPUMS
export parse_ddi
export extract_download
export load_ipums_extract
export load_ipums_nhgis

end
32 changes: 29 additions & 3 deletions src/parsers/nhgis_parser.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@


function load_nhgis_extract(fname::String)

"""
load_ipums_nhgis(filepath::String)
This function will take in the filename for an NHGIS Shapefile, and will
return a GeoDataFrame object containing the shapefile data.
### Arguments
- `filepath::String` - The directory path to an IPUMS NHGIS extracted shapefile.
### Returns
This function outputs a Julia GeoDataframe that contains all of the data from
the IPUMS NHGIS extract file. Further, the metadata fields of the Dataframe
contain the metadata parsed from the Shapefile.
# Examples
Let's assume we have an extract NHGIS file named `US_state_1790.shp` in a folder
that contains the other shapefile files. The user can open this Shapefile using
the following code.
```julia-repl
julia> gdf = load_ipums_nhgis("test/testdata/nhgis0001_shapefile/US_state_1790.shp");
```
"""
function load_ipums_nhgis(filepath::String)

gdf = DataFrame(Table(fname))
gdf = read(fname)

return gdf

Expand Down
7 changes: 7 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ end
@test isa(metadata(df), Dict)
@test isa(colmetadata(df, :YEAR), Dict)
end

@testset "NHGIS Parser" begin
datafile = "testdata/nhgis0001_shapefile/US_state_1790.shp"
df = load_ipums_nhgis(datafile)
@test size(df) == (16, 8)

end
Binary file not shown.
1 change: 1 addition & 0 deletions test/testdata/nhgis0001_shapefile/US_state_1790.prj
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PROJCS["USA_Contiguous_Albers_Equal_Area_Conic",GEOGCS["GCS_North_American_1983",DATUM["D_North_American_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Albers"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Central_Meridian",-96.0],PARAMETER["Standard_Parallel_1",29.5],PARAMETER["Standard_Parallel_2",45.5],PARAMETER["Latitude_Of_Origin",37.5],UNIT["Meter",1.0]]
Binary file added test/testdata/nhgis0001_shapefile/US_state_1790.sbn
Binary file not shown.
Binary file added test/testdata/nhgis0001_shapefile/US_state_1790.sbx
Binary file not shown.
Binary file not shown.
996 changes: 996 additions & 0 deletions test/testdata/nhgis0001_shapefile/US_state_1790.shp.xml

Large diffs are not rendered by default.

Binary file added test/testdata/nhgis0001_shapefile/US_state_1790.shx
Binary file not shown.

0 comments on commit c87455c

Please sign in to comment.