Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an initial version of WMSDataset #1965

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
isort
  • Loading branch information
Ian Turton committed Mar 27, 2024
commit dc99c2b97b4b7e5739dd56019aa25bccd82936cb
2 changes: 1 addition & 1 deletion tests/datasets/test_wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
# Licensed under the MIT License.

import pytest
from torchgeo.datasets import WMSDataset
import requests
adamjstewart marked this conversation as resolved.
Show resolved Hide resolved

from torchgeo.datasets import WMSDataset

SERVICE_URL = "https://mesonet.agron.iastate.edu/cgi-bin/wms/nexrad/n0r-t.cgi?"

Expand Down
9 changes: 4 additions & 5 deletions torchgeo/datasets/wms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
# Licensed under the MIT License.
# Author: Ian Turton, Glasgow University ian.turton@gla.ac.uk
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't normally edit the license header. Your contribution will still be included in the git history though.


from io import BytesIO
from typing import Any

import torchvision.transforms as transforms
from owslib.wms import WebMapService
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imports should be done lazily inside of the class so that the rest of TorchGeo still works even if owslib isn't installed. If you grep for any of our other optional dataset dependencies, you should see example code for this you can copy-n-paste.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ianturton you can check torchgeo.datasets.chabud as an example. See how we check if h5py is available in the constructor and then import h5py in the method that uses it.


from PIL import Image
from rasterio.coords import BoundingBox
from rasterio.crs import CRS
from rasterio.errors import CRSError
from rtree.index import Index, Property

from torchgeo.datasets import GeoDataset
from io import BytesIO
from PIL import Image
import torchvision.transforms as transforms
from rtree.index import Index, Property


class WMSDataset(GeoDataset):
Expand Down