зеркало из https://github.com/microsoft/torchgeo.git
format fixes
This commit is contained in:
Родитель
cb17cad70a
Коммит
3227ada3ed
|
@ -3,20 +3,20 @@
|
||||||
|
|
||||||
"""CVPR 2019 Chesapeake Land Cover dataset."""
|
"""CVPR 2019 Chesapeake Land Cover dataset."""
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from typing import Any, Callable, Dict, Optional
|
from typing import Any, Callable, Dict, Optional
|
||||||
|
|
||||||
import shapely.geometry
|
import fiona
|
||||||
import shapely.ops
|
import pyproj
|
||||||
import rasterio
|
import rasterio
|
||||||
import rasterio.mask
|
import rasterio.mask
|
||||||
|
import shapely.geometry
|
||||||
|
import shapely.ops
|
||||||
from rasterio.crs import CRS
|
from rasterio.crs import CRS
|
||||||
import pyproj
|
|
||||||
import fiona
|
|
||||||
|
|
||||||
from .geo import GeoDataset
|
from .geo import GeoDataset
|
||||||
from .utils import check_integrity, download_and_extract_archive, BoundingBox
|
from .utils import BoundingBox, check_integrity, download_and_extract_archive
|
||||||
|
|
||||||
|
|
||||||
class CVPRChesapeake(GeoDataset):
|
class CVPRChesapeake(GeoDataset):
|
||||||
|
@ -42,33 +42,21 @@ class CVPRChesapeake(GeoDataset):
|
||||||
crs = CRS.from_epsg(3857)
|
crs = CRS.from_epsg(3857)
|
||||||
res = 1
|
res = 1
|
||||||
|
|
||||||
states = [
|
states = ["de", "md", "va", "wv", "pa", "ny"]
|
||||||
"de",
|
splits = (
|
||||||
"md",
|
[f"{state}-train" for state in states]
|
||||||
"va",
|
+ [f"{state}-val" for state in states]
|
||||||
"wv",
|
+ [f"{state}-test" for state in states]
|
||||||
"pa",
|
)
|
||||||
"ny"
|
|
||||||
]
|
|
||||||
splits = [
|
|
||||||
f"{state}-train"
|
|
||||||
for state in states
|
|
||||||
] + [
|
|
||||||
f"{state}-val"
|
|
||||||
for state in states
|
|
||||||
] + [
|
|
||||||
f"{state}-test"
|
|
||||||
for state in states
|
|
||||||
]
|
|
||||||
|
|
||||||
p_src_crs = pyproj.CRS("epsg:3857")
|
p_src_crs = pyproj.CRS("epsg:3857")
|
||||||
p_transformers = {
|
p_transformers = {
|
||||||
'epsg:26917': pyproj.Transformer.from_crs(
|
"epsg:26917": pyproj.Transformer.from_crs(
|
||||||
p_src_crs, pyproj.CRS("epsg:26917"), always_xy=True
|
p_src_crs, pyproj.CRS("epsg:26917"), always_xy=True
|
||||||
).transform,
|
).transform,
|
||||||
'epsg:26918': pyproj.Transformer.from_crs(
|
"epsg:26918": pyproj.Transformer.from_crs(
|
||||||
p_src_crs, pyproj.CRS("epsg:26918"), always_xy=True
|
p_src_crs, pyproj.CRS("epsg:26918"), always_xy=True
|
||||||
).transform
|
).transform,
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -120,15 +108,19 @@ class CVPRChesapeake(GeoDataset):
|
||||||
box = shapely.geometry.shape(row["geometry"])
|
box = shapely.geometry.shape(row["geometry"])
|
||||||
minx, miny, maxx, maxy = box.bounds
|
minx, miny, maxx, maxy = box.bounds
|
||||||
coords = (minx, maxx, miny, maxy, mint, maxt)
|
coords = (minx, maxx, miny, maxy, mint, maxt)
|
||||||
self.index.insert(i, coords, {
|
self.index.insert(
|
||||||
"naip-new": row["properties"]["naip-new"],
|
i,
|
||||||
"naip-old": row["properties"]["naip-old"],
|
coords,
|
||||||
"landsat-leaf-on": row["properties"]["landsat-leaf-on"],
|
{
|
||||||
"landsat-leaf-off": row["properties"]["landsat-leaf-off"],
|
"naip-new": row["properties"]["naip-new"],
|
||||||
"lc": row["properties"]["lc"],
|
"naip-old": row["properties"]["naip-old"],
|
||||||
"nlcd": row["properties"]["nlcd"],
|
"landsat-leaf-on": row["properties"]["landsat-leaf-on"],
|
||||||
"buildings": row["properties"]["buildings"]
|
"landsat-leaf-off": row["properties"]["landsat-leaf-off"],
|
||||||
})
|
"lc": row["properties"]["lc"],
|
||||||
|
"nlcd": row["properties"]["nlcd"],
|
||||||
|
"buildings": row["properties"]["buildings"],
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
def __getitem__(self, query: BoundingBox) -> Dict[str, Any]:
|
def __getitem__(self, query: BoundingBox) -> Dict[str, Any]:
|
||||||
"""Retrieve image/mask and metadata indexed by query.
|
"""Retrieve image/mask and metadata indexed by query.
|
||||||
|
@ -173,9 +165,7 @@ class CVPRChesapeake(GeoDataset):
|
||||||
)
|
)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise IndexError(
|
raise IndexError(f"query: {query} spans multiple tiles which is not valid")
|
||||||
f"query: {query} spans multiple tiles which is not valid"
|
|
||||||
)
|
|
||||||
|
|
||||||
sample = {
|
sample = {
|
||||||
"image": naip_data,
|
"image": naip_data,
|
||||||
|
|
Загрузка…
Ссылка в новой задаче