Python error when clipping land use rasters

18 views
Skip to first unread message

Mayu Mizutani

unread,
Oct 9, 2025, 8:23:36 AMOct 9
to SWAT-user
Hello, 
I am having trouble using my land use raster when creating the HRUs in qSWAT+.
It is the NLCD layer that I have obtained from the MRLC as a GeoTIFF and converted into a .sdat file. These are the messages I get:

2025-10-08T14:48:07     WARNING    Traceback (most recent call last):
              File "C:\Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\QSWATPlus\QSWATPlus\hrus.py", line 5975, in getLanduseFile
              QSWATUtils.openAndLoadFile(root, FileTypes._LANDUSES,
              File "C:\Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\QSWATPlus\QSWATPlus\QSWATUtils.py", line 879, in openAndLoadFile
              layer = QSWATUtils.getLayerByFilename(root.findLayers(), outFileName, ft,
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              File "C:\Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\QSWATPlus\QSWATPlus\QSWATUtils.py", line 684, in getLayerByFilename
              layer = QSWATUtils.clipLayerToDEM(treeLayers, cast(QgsRasterLayer, layer), fileName, legend, gv)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
              File "C:\Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\QSWATPlus\QSWATPlus\QSWATUtils.py", line 587, in clipLayerToDEM
              assert os.path.exists(clipName), 'Failed to clip raster {0} to make {1}'.format(fileName, clipName)
              ^^^^^^^^^^^^^^^^^^^^^^^^
             AssertionError: Failed to clip raster C:/Users/mayum/Documents/working/qgis2/etowah\Watershed\Rasters\Landuse\nlcd_2024_saga.sdat to make C:/Users/mayum/Documents/working/qgis2/etowah\Watershed\Rasters\Landuse\nlcd_2024_saga_clip.tif
             

with this messages in Process window:

2025-10-08T14:48:07     INFO    gdal_translate -a_nodata 250.0 -of GTiff -srcwin 16073 5469 -8864 -7 C:/Users/mayum/Documents/working/qgis2/etowah\Watershed\Rasters\Landuse\nlcd_2024_saga.sdat C:/Users/mayum/Documents/working/qgis2/etowah\Watershed\Rasters\Landuse\nlcd_2024_saga_clip.tif

2025-10-08T14:48:07     INFO    GDAL command:

2025-10-08T14:48:07     INFO    gdal_translate -a_nodata 250.0 -of GTiff -srcwin 16073 5469 -8864 -7 C:/Users/mayum/Documents/working/qgis2/etowah\Watershed\Rasters\Landuse\nlcd_2024_saga.sdat C:/Users/mayum/Documents/working/qgis2/etowah\Watershed\Rasters\Landuse\nlcd_2024_saga_clip.tif

2025-10-08T14:48:07     INFO    GDAL command output:

2025-10-08T14:48:07     CRITICAL    Process returned error code 1

2025-10-08T14:48:07     INFO    Results: {'OUTPUT': 'C:/Users/mayum/Documents/working/qgis2/etowah\\Watershed\\Rasters\\Landuse\\nlcd_2024_saga_clip.tif'}

2025-10-08T14:48:07     CRITICAL    ERROR 1: Error: -srcwin 16073 5469 -8864 -7 has negative width and/or height.

2025-10-08T14:48:07     INFO    Input file size is 24888, 13703

Nancy B. Sammons

unread,
Oct 9, 2025, 9:08:42 AMOct 9
to Mayu Mizutani, SWAT-user

Mayu: 

You should post this on the SWAT+ and/or QSWAT+ Google group so the developer can review it.

Nancy

 

From: swat...@googlegroups.com <swat...@googlegroups.com> On Behalf Of Mayu Mizutani
Sent: Wednesday, October 8, 2025 1:55 PM
To: SWAT-user <swat...@googlegroups.com>
Subject: [SWAT-user:13268] Python error when clipping land use rasters

 

You don't often get email from mayumiz...@gmail.com. Learn why this is important

--
You received this message because you are subscribed to the Google Groups "SWAT-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swatuser+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/swatuser/d3159cbf-7a9c-4f41-bb1d-2d4df514282cn%40googlegroups.com.

Chris George

unread,
Oct 9, 2025, 9:12:56 AMOct 9
to Mayu Mizutani, SWAT-user
It looks like you assigned your project's projection to your landuse
file instead of reprojecting it properly.

Try clicking on Zoom Full in QGIS and you will see your project separate.

You do not need to clip landuse or soil rasters: QSWAT will do that for
you if they are much bigger than the DEM.

Chris

On 10/8/2025 7:54 PM, Mayu Mizutani wrote:
> Hello,  I am having trouble using my land use raster when creating the
> HRUs in qSWAT+. It is the NLCD layer that I have obtained from the MRLC
> as a GeoTIFF and converted into a .sdat file. These are the messages I
> get: 2025-10-08T14: 48: 07
> ZjQcmQRYFpfptBannerStart
> This Message Is From an External Sender
> This message came from outside your organization.
> ZjQcmQRYFpfptBannerEnd
> etowah\Watershed\Rasters\Landuse\nlcd_2024_saga_clip.tif
>
> 2025-10-08T14:48:07     INFO GDAL command output:
>
> 2025-10-08T14:48:07     CRITICAL Process returned error code 1
>
> 2025-10-08T14:48:07     INFO Results: {'OUTPUT': 'C:/Users/mayum/
> Documents/working/qgis2/etowah\\Watershed\\Rasters\\Landuse\
> \nlcd_2024_saga_clip.tif'}
>
> 2025-10-08T14:48:07     CRITICAL ERROR 1: Error: -srcwin 16073 5469
> -8864 -7 has negative width and/or height.
>
> 2025-10-08T14:48:07     INFO Input file size is 24888, 13703
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWAT-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swatuser+u...@googlegroups.com
> <mailto:swatuser+u...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/
> swatuser/d3159cbf-7a9c-4f41-bb1d-2d4df514282cn%40googlegroups.com
> <https://urldefense.com/v3/__https://groups.google.com/d/msgid/swatuser/
> d3159cbf-7a9c-4f41-bb1d-2d4df514282cn*40googlegroups.com?
> utm_medium=email&utm_source=footer__;JQ!!KwNVnqRv!
> FKfkPrDFcjvoSo01MetYVGLrMi3MS09Rr1B8QSmZr3_-
> qJPpMAXKktXCFXFxcCn_NXxE4W3g_nlwuSoYOUVXfy4s$>.

Mayu Mizutani

unread,
Oct 15, 2025, 9:37:08 AMOct 15
to SWAT-user
Im not sure what you mean.  QSWAT is not clipping the land use due to this error.

Mayu Mizutani

unread,
Oct 15, 2025, 9:37:14 AMOct 15
to SWAT-user
This is the Python error I get when trying to select the land use layer:

An error has occurred while executing Python code:

AssertionError: Failed to clip raster C:/Users/mayum/Documents/working/qgis2/etowah\Watershed\Rasters\Landuse\nlcd_1.sdat to make C:/Users/mayum/Documents/working/qgis2/etowah\Watershed\Rasters\Landuse\nlcd_1_clip.tif Traceback (most recent call last):
  File "C:\Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\QSWATPlus\QSWATPlus\hrus.py", line 5975, in getLanduseFile
    QSWATUtils.openAndLoadFile(root, FileTypes._LANDUSES,
  File "C:\Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\QSWATPlus\QSWATPlus\QSWATUtils.py", line 879, in openAndLoadFile

    layer = QSWATUtils.getLayerByFilename(root.findLayers(), outFileName, ft,
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\QSWATPlus\QSWATPlus\QSWATUtils.py", line 684, in getLayerByFilename

    layer = QSWATUtils.clipLayerToDEM(treeLayers, cast(QgsRasterLayer, layer), fileName, legend, gv)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\QSWATPlus\QSWATPlus\QSWATUtils.py", line 587, in clipLayerToDEM

    assert os.path.exists(clipName), 'Failed to clip raster {0} to make {1}'.format(fileName, clipName)
          ^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: Failed to clip raster C:/Users/mayum/Documents/working/qgis2/etowah\Watershed\Rasters\Landuse\nlcd_1.sdat to make C:/Users/mayum/Documents/working/qgis2/etowah\Watershed\Rasters\Landuse\nlcd_1_clip.tif


Python version: 3.12.7 (main, Oct 25 2024, 11:18:09) [MSC v.1938 64 bit (AMD64)]
QGIS version: 3.34.13-Prizren Prizren, 222b5995

Python Path:
  • C:/PROGRA~1/QGIS33~1.13/apps/qgis-ltr/./python
  • C:/Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python
  • C:/Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins
  • C:/PROGRA~1/QGIS33~1.13/apps/qgis-ltr/./python/plugins
  • C:\PROGRA~1\QGIS33~1.13\apps\grass\grass84\etc\python
  • C:\Users\mayum\Documents
  • C:\Program Files\QGIS 3.34.13\bin\python312.zip
  • C:\PROGRA~1\QGIS33~1.13\apps\Python312\DLLs
  • C:\PROGRA~1\QGIS33~1.13\apps\Python312\Lib
  • C:\Program Files\QGIS 3.34.13\bin
  • C:\PROGRA~1\QGIS33~1.13\apps\Python312
  • C:\PROGRA~1\QGIS33~1.13\apps\Python312\Lib\site-packages
  • C:\PROGRA~1\QGIS33~1.13\apps\Python312\Lib\site-packages\win32
  • C:\PROGRA~1\QGIS33~1.13\apps\Python312\Lib\site-packages\win32\lib
  • C:\PROGRA~1\QGIS33~1.13\apps\Python312\Lib\site-packages\Pythonwin
  • C:/Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python
  • C:\Users/mayum/AppData/Roaming/QGIS/QGIS3\profiles\default/python/plugins\QSWATPlus\QSWATPlus
  • C:/Users/mayum/Documents/working/qgis2/etowah

On Thursday, October 9, 2025 at 9:12:56 AM UTC-4 Chris George wrote:

Chris George

unread,
Oct 15, 2025, 10:56:32 AMOct 15
to Mayu Mizutani, SWAT-user
QSWAT tries to clip the landuse file if it is much bigger than the DEM.
The error message you had was a negative number appearing in the
calculations of where to make the clip. This normally indicates that
the DEM boundaries are not within the landuse file boundaries, and a
common cause of this is starting with a landuse file in a different
projection and instead of reprojecting it to the DEM's projection, just
assigning it the DEM's projection.

On 10/14/2025 1:57 AM, Mayu Mizutani wrote:
> Im not sure what you mean. QSWAT is not clipping the land use due to
> this error. On Thursday, October 9, 2025 at 9: 12: 56 AM UTC-4 Chris
> George wrote: It looks like you assigned your project's projection to
> your landuse file instead of reprojecting
> <https://urldefense.com/v3/__https://groups.google.com/d/msgid/__;!!
> KwNVnqRv!
> AX_KqpaS7DiyBDnRFfHw3FPZ7fpz_OULHLRJhJNBzSP0KZWLd8Y0jxe7aVP769QckL7RySKmPgj5V1NJBzaHBoRB$>
> > swatuser/d3159cbf-7a9c-4f41-bb1d-2d4df514282cn%40googlegroups.com
> <https://urldefense.com/v3/__http://40googlegroups.com__;!!KwNVnqRv!
> AX_KqpaS7DiyBDnRFfHw3FPZ7fpz_OULHLRJhJNBzSP0KZWLd8Y0jxe7aVP769QckL7RySKmPgj5V1NJB2HS8Tc9$>
> > <https://urldefense.com/v3/__https://groups.google.com/d/msgid/
> swatuser/ <https://urldefense.com/v3/__https://groups.google.com/d/
> msgid/swatuser/>
> > d3159cbf-7a9c-4f41-bb1d-2d4df514282cn*40googlegroups.com
> <https://urldefense.com/v3/__http://40googlegroups.com__;!!KwNVnqRv!
> AX_KqpaS7DiyBDnRFfHw3FPZ7fpz_OULHLRJhJNBzSP0KZWLd8Y0jxe7aVP769QckL7RySKmPgj5V1NJB2HS8Tc9$>?
> > utm_medium=email&utm_source=footer__;JQ!!KwNVnqRv!
> > FKfkPrDFcjvoSo01MetYVGLrMi3MS09Rr1B8QSmZr3_-
> > qJPpMAXKktXCFXFxcCn_NXxE4W3g_nlwuSoYOUVXfy4s$>.
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWAT-user" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swatuser+u...@googlegroups.com
> <mailto:swatuser+u...@googlegroups.com>.
> To view this discussion visit https://groups.google.com/d/msgid/
> swatuser/65d94311-5809-45cc-8f64-5304cea78d40n%40googlegroups.com
> <https://urldefense.com/v3/__https://groups.google.com/d/msgid/
> swatuser/65d94311-5809-45cc-8f64-5304cea78d40n*40googlegroups.com?
> utm_medium=email&utm_source=footer__;JQ!!KwNVnqRv!
> AX_KqpaS7DiyBDnRFfHw3FPZ7fpz_OULHLRJhJNBzSP0KZWLd8Y0jxe7aVP769QckL7RySKmPgj5V1NJB-I40Buw$>.

Reply all
Reply to author
Forward
0 new messages