Skip to content

Commit

Permalink
added code to use geojson-test-data
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielJDufour committed Oct 1, 2023
1 parent 6e3bd32 commit 30336f8
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
12 changes: 12 additions & 0 deletions data/country_populations.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
country,population
Afghanistan,27024636.0
Akrotiri and Dhekelia,23469.134765625
Croatia,4685367.0
Cyprus,790242.0625
Jamaica,2332581.75
Lebanon,5554060.0
Macedonia,2239499.25
New Zealand,0.0
Nicaragua,5066313.5
Ukraine,12697956.0
Uruguay,3303090.0
5 changes: 3 additions & 2 deletions data/create_expected_truth_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
["./antimeridian/split.shp", "gfwfiji_6933_COG_Binary.tif"],
["./antimeridian/across.shp", "gfwfiji_6933_COG_Binary.tif"],

["./geojson-test-data/EEZ_Land_v3_202030_New_Zealand.geojson", "./geotiff-test-data/nz_habitat_anticross_4326_1deg.tif"]
["./geojson-test-data/eez_land_union/EEZ_Land_v3_202030_New_Zealand.geojson", "./geotiff-test-data/nz_habitat_anticross_4326_1deg.tif"]
]

for i, (geom, raster, *opts) in enumerate(test_cases):
Expand Down Expand Up @@ -84,4 +84,5 @@
pop = 0
for tile in ghsl_tiles:
pop += zonal_stats(f"./gadm/geojsons/{file}", f"./ghsl/tiles/{tile}", stats="sum", band=1)[0]['sum']
print(f"{country}: {pop:,}")
print(f"{country}: {pop:,}")
writer.writerow({ "country": country, "population": pop })
2 changes: 1 addition & 1 deletion data/expected_data.txt
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ case: 13


case: 14
vector: ./geojson-test-data/EEZ_Land_v3_202030_New_Zealand.geojson
vector: ./geojson-test-data/eez_land_union/EEZ_Land_v3_202030_New_Zealand.geojson
raster: ./geotiff-test-data/nz_habitat_anticross_4326_1deg.tif
opts: []
result:
Expand Down
6 changes: 6 additions & 0 deletions data/geojson-test-data/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# download from https://github.com/DanielJDufour/geojson-test-data/
wget https://github.com/DanielJDufour/geojson-test-data/archive/refs/heads/main.zip -O geojson-test-data.zip
unzip -o geojson-test-data.zip "geojson-test-data-*/files/*" -d .
mv ./geojson-test-data-main/files/* .
rm -r geojson-test-data-main
rm geojson-test-data.zip
10 changes: 10 additions & 0 deletions src/stats/stats.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,16 @@ test("antimerdian #2 (split at antimeridian)", async ({ eq }) => {
eq(results, [{ count: 327_972, min: 1, max: 1, sum: 327_972 }]);
});

test("antimeridian New Zealand EEZ and Habitat", async ({ eq }) => {
const georaster = await parse("http://localhost:3000/data/geotiff-test-data/nz_habitat_anticross_4326_1deg.tif");
const geojson = JSON.parse(readFileSync("./data/geojson-test-data/eez_land_union/EEZ_Land_v3_202030_New_Zealand.geojson", "utf-8"));
const results = await stats(georaster, geojson, { stats: ["count", "min", "max", "sum"] });
eq(results, [{ count: 4_512, min: 1, max: 71, sum: 454 }]);

const results2 = await Promise.all(geojson.features[0].geometry.coordinates.map(geom => stats(georaster, geom, { stats: ["count", "min", "max", "sum"] })));
eq(results2, [[{ count: 322, min: 1, max: 71, sum: 3931 }], [{ count: 132, min: 1, max: 22, sum: 581 }]]);
});

test("antimerdian #3 (across antimeridian on left-side)", async ({ eq }) => {
return; // XXX
// converted GeoTIFF to all 1's
Expand Down

0 comments on commit 30336f8

Please sign in to comment.