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

Make MutableGeoraster implement limit_to_bands() #297

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marcronq
Copy link
Contributor

The GeoRaster2.limit_to_bands method behaves differently depending on whether _image has been already read or not:

    def limit_to_bands(self, bands):
        if self._image is not None:
            bands_data = self.bands_data(bands)
            return self.copy_with(image=bands_data, band_names=bands)
        else:
            indices = self.bands_indices(bands)
            bidxs = map(lambda idx: idx + 1, indices)
            doc = boundless_vrt_doc(self._raster_opener(self.source_file), bands=bidxs)
            filename = self._save_to_destination_file(doc.tostring())
            return self.__class__(filename=filename, band_names=bands)

When dealing with a MutableGeoraster instance this provokes that depending on this condition the returned type is MutableGeoRaster or GeoRaster2:

In [2]: img = GeoRaster2.open("whatever.tif", lazy_load=False, mutable=True)

In [5]: band = img.limit_to_bands(["raw"])

In [6]: type(band)
Out[6]: telluric.georaster.GeoRaster2

In [7]: img = GeoRaster2.open("whatever.tif", mutable=True)

In [8]: band = img.limit_to_bands(["raw"])

In [9]: type(band)
Out[9]: telluric.georaster.MutableGeoRaster

I made MutableGeoRaster implement the limit_to_bands method. This could also be accomplished modifying the base method but I don't know if Georaster2 class should know about its childs. What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant