3
3
4
4
"""NLCD dataset."""
5
5
6
- import glob
7
6
import os
8
7
from collections .abc import Callable , Iterable
9
8
from typing import Any , ClassVar
15
14
16
15
from .errors import DatasetNotFoundError
17
16
from .geo import RasterDataset
18
- from .utils import BoundingBox , Path , download_url , extract_archive
17
+ from .utils import BoundingBox , Path , download_url
19
18
20
19
21
20
class NLCD (RasterDataset ):
22
- """National Land Cover Database (NLCD) dataset.
21
+ """Annual National Land Cover Database (NLCD) dataset.
23
22
24
- The `NLCD dataset
25
- <https://www.usgs.gov/centers/eros/science/national-land-cover-database>`_
26
- is a land cover product that covers the United States and Puerto Rico. The current
27
- implementation supports maps for the continental United States only. The product is
28
- a joint effort between the United States Geological Survey
23
+ The `Annual NLCD products
24
+ <https://www.usgs.gov/centers/eros/science/annual-national-land-cover-database>`_
25
+ is an annual land cover product for the conterminous U.S. initially covering the period
26
+ from 1985 to 2023. The product is a joint effort between the United States Geological Survey
29
27
(`USGS <https://www.usgs.gov/>`_) and the Multi-Resolution Land Characteristics
30
- Consortium (`MRLC <https://www.mrlc.gov/>`_) which released the first product
31
- in 2001 with new updates every five years since then.
28
+ Consortium (`MRLC <https://www.mrlc.gov/>`_).
32
29
33
30
The dataset contains the following 17 classes:
34
31
@@ -57,33 +54,60 @@ class NLCD(RasterDataset):
57
54
58
55
* single channel .img file with integer class labels
59
56
60
- If you use this dataset in your research, please use the corresponding citation :
57
+ If you use this dataset in your research, please cite the following paper :
61
58
62
- * 2001: https://doi.org/10.5066/P9MZGHLF
63
- * 2006: https://doi.org/10.5066/P9HBR9V3
64
- * 2011: https://doi.org/10.5066/P97S2IID
65
- * 2016: https://doi.org/10.5066/P96HHBIE
66
- * 2019: https://doi.org/10.5066/P9KZCM54
59
+ * https://doi.org/10.5066/P94UXNTS
67
60
68
61
.. versionadded:: 0.5
69
62
"""
70
63
71
- filename_glob = 'nlcd_*_land_cover_l48_*.img'
72
- filename_regex = (
73
- r'nlcd_(?P<date>\d{4})_land_cover_l48_(?P<publication_date>\d{8})\.img'
74
- )
75
- zipfile_glob = 'nlcd_*_land_cover_l48_*.zip'
64
+ filename_glob = 'Annual_NLCD_LndCov_*_CU_C1V0.tif'
65
+ filename_regex = r'Annual_NLCD_LndCov_(?P<date>\d{4})_CU_C1V0\.tif'
76
66
date_format = '%Y'
77
67
is_image = False
78
68
79
- url = 'https://s3-us-west-2.amazonaws.com/mrlc/nlcd_{}_land_cover_l48_20210604.zip '
69
+ url = 'https://s3-us-west-2.amazonaws.com/mrlc/Annual_NLCD_LndCov_{}_CU_C1V0.tif '
80
70
81
71
md5s : ClassVar [dict [int , str ]] = {
82
- 2001 : '538166a4d783204764e3df3b221fc4cd' ,
83
- 2006 : '67454e7874a00294adb9442374d0c309' ,
84
- 2011 : 'ea524c835d173658eeb6fa3c8e6b917b' ,
85
- 2016 : '452726f6e3bd3f70d8ca2476723d238a' ,
86
- 2019 : '82851c3f8105763b01c83b4a9e6f3961' ,
72
+ 1985 : 'a2e1c5f0b34e9b15a63a9dc10e8d3ec2' ,
73
+ 1986 : 'da1d08ca51ac43abc14711c8d6139f1d' ,
74
+ 1987 : '2cb85e8f077c227605cd7bac62a72a75' ,
75
+ 1988 : 'b20fb987cc30926d2d125d045e02626d' ,
76
+ 1989 : 'dbe851cbea34d0a57c2a94eb745a1267' ,
77
+ 1990 : '1927e0e040b9ff513ff039749b64919b' ,
78
+ 1991 : 'eca73474843d6c58693eba62d70e507c' ,
79
+ 1992 : '8beda41ba79000f55a8e9358ba3fa5a4' ,
80
+ 1993 : '1a023552967cdac1111e9968ea62c879' ,
81
+ 1994 : 'acc30ce4f6cdd78af5f7887d17ac4de3' ,
82
+ 1995 : 'f728e8fc231b2e8e74a14201f500543a' ,
83
+ 1996 : 'd2580904244f89b20d6258150fbf4161' ,
84
+ 1997 : 'fec4e08032e162f2cc7dbe019d042609' ,
85
+ 1998 : '87ea19434de96ea99cd5d7991042816c' ,
86
+ 1999 : 'd4133737f20e75f3bd3a5baa32a668da' ,
87
+ 2000 : 'e20b61bb2e7f4034a33c9fd536798a01' ,
88
+ 2001 : 'b1f46ace9aedd17a89efab489cb67bc3' ,
89
+ 2002 : '57bf60d7cd473096af3bb125391bde63' ,
90
+ 2003 : '5e346854da9abf739152e85fee4c7aff' ,
91
+ 2004 : '13136f271f53a454358eb7ec12bda686' ,
92
+ 2005 : 'f00b66b57a23eb49a077e88704964a91' ,
93
+ 2006 : '074ba90de5e62a37a5f001b7572f6baa' ,
94
+ 2007 : 'cdef29a191cf165baaae80857ce5a980' ,
95
+ 2008 : 'da907c76a1f12739333148504fd111c9' ,
96
+ 2009 : '47890b306b875e681990b3db0c709da3' ,
97
+ 2010 : '9a81f405f9e2f45d581078afd53c2d4b' ,
98
+ 2011 : '13f4ef40b204aa1108dc0599d9546701' ,
99
+ 2012 : '66b33146f9a9d9491be10c59c51e3e33' ,
100
+ 2013 : 'f8d230f7dea493c47fbc74984ff856cc' ,
101
+ 2014 : '68eb07ce86c1f7c2546ec43c2f9f7029' ,
102
+ 2015 : 'f5a1b59fe54a70752f544c06cb965be4' ,
103
+ 2016 : 'f0c2e74824fc281a57821e28e2c7fe6e' ,
104
+ 2017 : 'a0aa8be0ed7d637f0f88f26d3742b20e' ,
105
+ 2018 : 'a01f31547837ff1dfec1aba07b89bbec' ,
106
+ 2019 : 'fa738201cddc1393dac4383b6ce2561a' ,
107
+ 2020 : 'aa8f51690c7b01f3b3b413be9a7c36d6' ,
108
+ 2021 : '47fc1794a64704a918b6ad586df4267c' ,
109
+ 2022 : '11359748229e138cde971947864104a4' ,
110
+ 2023 : '498ff8a512d32fe905720796fdb7fd52' ,
87
111
}
88
112
89
113
cmap : ClassVar [dict [int , tuple [int , int , int , int ]]] = {
@@ -111,7 +135,7 @@ def __init__(
111
135
paths : Path | Iterable [Path ] = 'data' ,
112
136
crs : CRS | None = None ,
113
137
res : float | None = None ,
114
- years : list [int ] = [2019 ],
138
+ years : list [int ] = [2023 ],
115
139
classes : list [int ] = list (cmap .keys ()),
116
140
transforms : Callable [[dict [str , Any ]], dict [str , Any ]] | None = None ,
117
141
cache : bool = True ,
@@ -183,19 +207,14 @@ def __getitem__(self, query: BoundingBox) -> dict[str, Any]:
183
207
184
208
def _verify (self ) -> None :
185
209
"""Verify the integrity of the dataset."""
186
- # Check if the extracted files already exist
187
- if self .files :
188
- return
189
-
190
- # Check if the zip files have already been downloaded
210
+ # Check if the TIFF files for the specified years have already been downloaded
191
211
exists = []
192
212
for year in self .years :
193
- zipfile_year = self .zipfile_glob .replace ('*' , str (year ), 1 )
213
+ filename_year = self .filename_glob .replace ('*' , str (year ), 1 )
194
214
assert isinstance (self .paths , str | os .PathLike )
195
- pathname = os .path .join (self .paths , '**' , zipfile_year )
196
- if glob . glob (pathname , recursive = True ):
215
+ pathname = os .path .join (self .paths , filename_year )
216
+ if os . path . exists (pathname ):
197
217
exists .append (True )
198
- self ._extract ()
199
218
else :
200
219
exists .append (False )
201
220
@@ -208,7 +227,6 @@ def _verify(self) -> None:
208
227
209
228
# Download the dataset
210
229
self ._download ()
211
- self ._extract ()
212
230
213
231
def _download (self ) -> None :
214
232
"""Download the dataset."""
@@ -219,14 +237,6 @@ def _download(self) -> None:
219
237
md5 = self .md5s [year ] if self .checksum else None ,
220
238
)
221
239
222
- def _extract (self ) -> None :
223
- """Extract the dataset."""
224
- for year in self .years :
225
- zipfile_name = self .zipfile_glob .replace ('*' , str (year ), 1 )
226
- assert isinstance (self .paths , str | os .PathLike )
227
- pathname = os .path .join (self .paths , '**' , zipfile_name )
228
- extract_archive (glob .glob (pathname , recursive = True )[0 ], self .paths )
229
-
230
240
def plot (
231
241
self ,
232
242
sample : dict [str , Any ],
0 commit comments