Skip to content

Commit 48cb3b8

Browse files
committed
feat: fixup region check code
1 parent aaa0af9 commit 48cb3b8

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,6 @@ download-soil-data:
8282
gdown 1asGnnqe0zI2v8xuOszlsNmZkOSl7cJ2n; \
8383
gdown 185Qjb9pJJn4AzOissiTz283tINrDqgI0; \
8484
gdown 1P3xl1YRlfcMjfO_4PM39tkrrlL3hoLzv; \
85-
gdown 1K0GkqxhZiVUND6yfFmaI7tYanLktekyp \
85+
gdown 1K0GkqxhZiVUND6yfFmaI7tYanLktekyp; \
86+
gdown 1c6EZwKAJvtkyxZsCzLM4ObmMi8mYbqds; \
87+
gdown 1z7foFFHv_mTsuxMYnfOQRvXT5LKYlYFN \

soil_id/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@
3232
REQUESTS_CACHE_PATH = f"{CACHE_DIR}/requests_cache"
3333

3434
# Determines if in/out of US
35-
US_AREA_PATH = f"{DATA_PATH}/SoilID_US_Areas.shp"
35+
US_AREA_PATH = f"{DATA_PATH}/SoilID_US_Areas.shz"
3636

3737
# US Soil ID
3838
STATSGO_PATH = f"{DATA_PATH}/gsmsoilmu_a_us.shp"
3939
MUNSELL_RGB_LAB_PATH = f"{DATA_PATH}/LandPKS_munsell_rgb_lab.csv"
4040

4141
# Global Soil ID
42-
HWSD_PATH = f"{DATA_PATH}/HWSD_global_noWater_no_country.shp"
42+
HWSD_PATH = f"{DATA_PATH}/HWSD_global_noWater_no_country.shz"
4343
WISE_PATH = f"{DATA_PATH}/wise30sec_poly_simp_soil.shp"
4444

4545
# Database

soil_id/tests/test_find_region.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright © 2025 Technology Matters
2+
#
3+
# This program is free software: you can redistribute it and/or modify
4+
# it under the terms of the GNU Affero General Public License as published
5+
# by the Free Software Foundation, either version 3 of the License, or
6+
# (at your option) any later version.
7+
#
8+
# This program is distributed in the hope that it will be useful,
9+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
# GNU Affero General Public License for more details.
12+
#
13+
# You should have received a copy of the GNU Affero General Public License
14+
# along with this program. If not, see https://www.gnu.org/licenses/.
15+
16+
from soil_id.utils import findRegionForLocation
17+
import pytest
18+
19+
test_locations = [
20+
(38.968984, -103.625974, 'US'),
21+
(-6.708697, -69.306646, 'Global'),
22+
(-3.521766, -136.995712, None)
23+
]
24+
25+
@pytest.mark.parametrize("location", test_locations)
26+
def test_find_region(location):
27+
lat, lon, region = location
28+
29+
assert findRegionForLocation(lat=lat, lon=lon) == region

soil_id/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,7 +2443,7 @@ def create_new_layer_osd(row, top, bottom):
24432443
##################################################################################################
24442444
# Database and API Functions #
24452445
##################################################################################################
2446-
def findSoilLocation(lon, lat):
2446+
def findRegionForLocation(lon, lat):
24472447
"""
24482448
Determines the location type (US, Global, or None) of the given longitude and latitude
24492449
based on soil datasets.
@@ -2473,7 +2473,7 @@ def findSoilLocation(lon, lat):
24732473
coord_transform = ogr.osr.CoordinateTransformation(pt_ref, geo_ref)
24742474

24752475
# Transform the coordinate system of the input point
2476-
lon, lat, _ = coord_transform.TransformPoint(lon, lat)
2476+
lon, lat, _ = coord_transform.TransformPoint(lat, lon)
24772477

24782478
# Create a point geometry
24792479
pt = ogr.Geometry(ogr.wkbPoint)

0 commit comments

Comments
 (0)