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

Issue in Merging/Mosaicing multiple images using Rioxarray Python #172

Closed
rrsc1234 opened this issue Oct 15, 2020 · 10 comments
Closed

Issue in Merging/Mosaicing multiple images using Rioxarray Python #172

rrsc1234 opened this issue Oct 15, 2020 · 10 comments
Labels
question Further information is requested

Comments

@rrsc1234
Copy link

rrsc1234 commented Oct 15, 2020

Hi. I am using the following code to mosaic/merge 10 image files (.tif files) inside a folder using the following code:

`
import rioxarray
from rioxarray import merge
from rasterio.plot import show

items = [r'D:\LC08_L1TP_146046_20180425_20180502_01_T1.tif',
r'D:\LE07_L1TP_145045_20180426_20180523_01_T1.tif',
r'D:\LC08_L1TP_144046_20180427_20180502_01_T1.tif',
r'D:\LC08_L1TP_144045_20180427_20180502_01_T1.tif',
r'D:\LC08_L1TP_143046_20180420_20180502_01_T1.tif',
r'D:\LC08_L1TP_143047_20180420_20180502_01_T1.tif',
r'D:\LC08_L1TP_143045_20180420_20180502_01_T1.tif',
r'D:\LE07_L1TP_145046_20180426_20180523_01_T1.tif',
r'D:\LE07_L1TP_145045_20180426_20180523_01_T1.tif',
r'D:\LC08_L1TP_144047_20180427_20180502_01_T1.tif']

elements = []

for val in items:
elements.append(rioxarray.open_rasterio(val))

merged = merge.merge_arrays(elements, nodata=0.0)

image = merged.values
show(image)
`
After running the above code I am getting the following output:

Rioxarray_Merge_image

When I am loading all the input files (for mosaic/merge) in ArcMap, I am getting the following:

input_files_in_arcmap

From the above 2 images it is observed that the mosaic image obtained after running the above code is flipped (left part and right side are swapped).

Can someone please let me know how to solve this issue.

I am attaching the link to the input files:
https://drive.google.com/file/d/1hF5pb8MojW-N5l9xMgd1mJ95CtjLa8wQ/view?usp=sharing

@rrsc1234 rrsc1234 added the question Further information is requested label Oct 15, 2020
@snowman2
Copy link
Member

@rrsc1234 are you able to share the input files? That would be the easiest way to be able to assist.

@snowman2
Copy link
Member

I notice that you aren't using merged.plot(), what happens when you do that?

@rrsc1234
Copy link
Author

@rrsc1234 are you able to share the input files? That would be the easiest way to be able to assist.

@snowman2 . Here is the link to the input datasets:
https://drive.google.com/file/d/1hF5pb8MojW-N5l9xMgd1mJ95CtjLa8wQ/view?usp=sharing

@snowman2
Copy link
Member

I see that you have both EPSG:32643 and EPSG:32644 as the CRS of the datasets. The merge function assumes that they are all the same CRS.

You need to change:

for val in items:
    elements.append(rioxarray.open_rasterio(val))

to:

for val in items:
    rds = rioxarray.open_rasterio(val)
    if rds.crs != "EPSG:32643":
        rds = rds.rio.reproject("EPSG:32643")
    elements.append(rds)

@snowman2
Copy link
Member

@rrsc1234
Copy link
Author

I see that you have both EPSG:32643 and EPSG:32644 as the CRS of the datasets. The merge function assumes that they are all the same CRS.

You need to change:

for val in items:
    elements.append(rioxarray.open_rasterio(val))

to:

for val in items:
    rds = rioxarray.open_rasterio(val)
    if rds.crs != "EPSG:32643":
        rds = rds.rio.reproject("EPSG:32643")
    elements.append(rds)

@snowman2 . Thanks for your suggestion. Your solution worked for me.

@snowman2
Copy link
Member

Glad to hear that it worked 👍

@snowman2
Copy link
Member

With fix in #183, targeted for the 0.2 release, this will be managed automatically.

@betolink
Copy link

Will this work for datasets opened with xarray?

I tried to reproject a dataset into an adjacent UTM zone and the resulting grid was not aligned.

@snowman2
Copy link
Member

Will this work for datasets opened with xarray?
I tried to reproject a dataset into an adjacent UTM zone and the resulting grid was not aligned.

If you are using the latest rioxarray, then I would recommend opening a new issue with the details of your problem.

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

No branches or pull requests

3 participants