Skip to main content
added 141 characters in body
Source Link
GIS7
  • 358
  • 1
  • 14

I have a workspace with NDVI rasters and another workspace with greyscale rasters. The rasters have the same name.

I want to reclassify the NDVI raster while also using the greyscale values in a function. Depending on the greyscale value, another reclass function should be used. So for every pixel, the correct function has to be found.

I need to use an if statement: if the greyscale raster cell value is high, another statement should be used but the code results in an error:

Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable.

arcpy.env.workspace = ndviws
ndvirasterlist = arcpy.ListRasters()

for rimage in ndvirasterlist:
    ndvi_raster = arcpy.sa.Raster(rimage)
    grey_raster = arcpy.sa.Raster(os.path.join(greyvalues,rimage))
    if grey_raster <= 28523:
        output_raster = Con(ndvi_raster < -0.0000006 * grey_raster +  0.3448,2,1)
    if grey_raster >28523 and grey_raster < 50000:
        output_raster = Con(ndvi_raster < -0.000009 * grey_raster + 0.437673,2,1)
    if grey_raster >=50000:
        output_raster = Con(ndvi_raster < -0.000007 * grey_raster + 0.5233,2,1)
    output_raster.save(os.path.join(outputws,rimage))

**edit: edit: in my real usecase I haveedited so that there are now 3 if statements, not 2!. Is this still working with con method?

I have a workspace with NDVI rasters and another workspace with greyscale rasters. The rasters have the same name.

I want to reclassify the NDVI raster while also using the greyscale values in a function. Depending on the greyscale value, another reclass function should be used. So for every pixel, the correct function has to be found.

I need to use an if statement: if the greyscale raster cell value is high, another statement should be used but the code results in an error:

Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable.

arcpy.env.workspace = ndviws
ndvirasterlist = arcpy.ListRasters()

for rimage in ndvirasterlist:
    ndvi_raster = arcpy.sa.Raster(rimage)
    grey_raster = arcpy.sa.Raster(os.path.join(greyvalues,rimage))
    if grey_raster <= 28523:
        output_raster = Con(ndvi_raster < -0.0000006 * grey_raster +  0.3448,2,1)
    if grey_raster >28523:
        output_raster = Con(ndvi_raster < -0.000009 * grey_raster + 0.437673,2,1)
    output_raster.save(os.path.join(outputws,rimage))

edit: in my real usecase I have 3 if statements, not 2!

I have a workspace with NDVI rasters and another workspace with greyscale rasters. The rasters have the same name.

I want to reclassify the NDVI raster while also using the greyscale values in a function. Depending on the greyscale value, another reclass function should be used. So for every pixel, the correct function has to be found.

I need to use an if statement: if the greyscale raster cell value is high, another statement should be used but the code results in an error:

Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable.

arcpy.env.workspace = ndviws
ndvirasterlist = arcpy.ListRasters()

for rimage in ndvirasterlist:
    ndvi_raster = arcpy.sa.Raster(rimage)
    grey_raster = arcpy.sa.Raster(os.path.join(greyvalues,rimage))
    if grey_raster <= 28523:
        output_raster = Con(ndvi_raster < -0.0000006 * grey_raster +  0.3448,2,1)
    if grey_raster >28523 and grey_raster < 50000:
        output_raster = Con(ndvi_raster < -0.000009 * grey_raster + 0.437673,2,1)
    if grey_raster >=50000:
        output_raster = Con(ndvi_raster < -0.000007 * grey_raster + 0.5233,2,1)
    output_raster.save(os.path.join(outputws,rimage))

**edit: edited so that there are now 3 if statements. Is this still working with con method?

deleted 1 character in body
Source Link
GIS7
  • 358
  • 1
  • 14

I have a workspace with NDVI rasters and another workspace with greyscale rasters. The rasters have the same name.

I want to reclassify the NDVI raster while also using the greyscale values in a function. Depending on the greyscale value, another reclass function should be used. So for every pixel, the correct function has to be found.

I need to use an if statement: if the greyscale raster cell value is high, another statement should be used but the code results in an error:

Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable.

arcpy.env.workspace = ndviws
ndvirasterlist = arcpy.ListRasters()

for rimage in ndvirasterlist:
    ndvi_raster = arcpy.sa.Raster(rimage)
    grey_raster = arcpy.sa.Raster(os.path.join(greyvaluewsgreyvalues,rimage))
    if grey_raster <= 28523:
        output_raster = Con(ndvi_raster < -0.0000006 * grey_raster +  0.3448,2,1)
    if grey_raster >28523:
        output_raster = Con(ndvi_raster < -0.000009 * grey_raster + 0.437673,2,1)
    output_raster.save(os.path.join(outputws,rimage))

edit: in my real usecase I have 3 if statements, not 2!

I have a workspace with NDVI rasters and another workspace with greyscale rasters. The rasters have the same name.

I want to reclassify the NDVI raster while also using the greyscale values in a function. Depending on the greyscale value, another reclass function should be used. So for every pixel, the correct function has to be found.

I need to use an if statement: if the greyscale raster cell value is high, another statement should be used but the code results in an error:

Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable.

arcpy.env.workspace = ndviws
ndvirasterlist = arcpy.ListRasters()

for rimage in ndvirasterlist:
    ndvi_raster = arcpy.sa.Raster(rimage)
    grey_raster = arcpy.sa.Raster(os.path.join(greyvaluews,rimage))
    if grey_raster <= 28523:
        output_raster = Con(ndvi_raster < -0.0000006 * grey_raster +  0.3448,2,1)
    if grey_raster >28523:
        output_raster = Con(ndvi_raster < -0.000009 * grey_raster + 0.437673,2,1)
    output_raster.save(os.path.join(outputws,rimage))

edit: in my real usecase I have 3 if statements, not 2!

I have a workspace with NDVI rasters and another workspace with greyscale rasters. The rasters have the same name.

I want to reclassify the NDVI raster while also using the greyscale values in a function. Depending on the greyscale value, another reclass function should be used. So for every pixel, the correct function has to be found.

I need to use an if statement: if the greyscale raster cell value is high, another statement should be used but the code results in an error:

Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable.

arcpy.env.workspace = ndviws
ndvirasterlist = arcpy.ListRasters()

for rimage in ndvirasterlist:
    ndvi_raster = arcpy.sa.Raster(rimage)
    grey_raster = arcpy.sa.Raster(os.path.join(greyvalues,rimage))
    if grey_raster <= 28523:
        output_raster = Con(ndvi_raster < -0.0000006 * grey_raster +  0.3448,2,1)
    if grey_raster >28523:
        output_raster = Con(ndvi_raster < -0.000009 * grey_raster + 0.437673,2,1)
    output_raster.save(os.path.join(outputws,rimage))

edit: in my real usecase I have 3 if statements, not 2!

added 61 characters in body
Source Link
GIS7
  • 358
  • 1
  • 14

I have a workspace with NDVI rasters and another workspace with greyscale rasters. The rasters have the same name.

I want to reclassify the NDVI raster while also using the greyscale values in a function. Depending on the greyscale value, another reclass function should be used. So for every pixel, the correct function has to be found.

I need to use an if statement: if the greyscale raster cell value is high, another statement should be used but the code results in an error:

Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable.

arcpy.env.workspace = ndviws
ndvirasterlist = arcpy.ListRasters()

for rimage in ndvirasterlist:
    ndvi_raster = arcpy.sa.Raster(rimage)
    grey_raster = arcpy.sa.Raster(os.path.join(greyvaluews,rimage))
    if grey_raster <= 28523:
        output_raster = Con(ndvi_raster < -0.0000006 * grey_raster +  0.3448,2,1)
    if grey_raster >28523:
        output_raster = Con(ndvi_raster < -0.000009 * grey_raster + 0.437673,2,1)
    output_raster.save(os.path.join(outputws,rimage))

edit: in my real usecase I have 3 if statements, not 2!

I have a workspace with NDVI rasters and another workspace with greyscale rasters. The rasters have the same name.

I want to reclassify the NDVI raster while also using the greyscale values in a function. Depending on the greyscale value, another reclass function should be used. So for every pixel, the correct function has to be found.

I need to use an if statement: if the greyscale raster cell value is high, another statement should be used but the code results in an error:

Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable.

arcpy.env.workspace = ndviws
ndvirasterlist = arcpy.ListRasters()

for rimage in ndvirasterlist:
    ndvi_raster = arcpy.sa.Raster(rimage)
    grey_raster = arcpy.sa.Raster(os.path.join(greyvaluews,rimage))
    if grey_raster <= 28523:
        output_raster = Con(ndvi_raster < -0.0000006 * grey_raster +  0.3448,2,1)
    if grey_raster >28523:
        output_raster = Con(ndvi_raster < -0.000009 * grey_raster + 0.437673,2,1)
    output_raster.save(os.path.join(outputws,rimage))

I have a workspace with NDVI rasters and another workspace with greyscale rasters. The rasters have the same name.

I want to reclassify the NDVI raster while also using the greyscale values in a function. Depending on the greyscale value, another reclass function should be used. So for every pixel, the correct function has to be found.

I need to use an if statement: if the greyscale raster cell value is high, another statement should be used but the code results in an error:

Invalid use of raster with Boolean operator or function. Check the use of parentheses where applicable.

arcpy.env.workspace = ndviws
ndvirasterlist = arcpy.ListRasters()

for rimage in ndvirasterlist:
    ndvi_raster = arcpy.sa.Raster(rimage)
    grey_raster = arcpy.sa.Raster(os.path.join(greyvaluews,rimage))
    if grey_raster <= 28523:
        output_raster = Con(ndvi_raster < -0.0000006 * grey_raster +  0.3448,2,1)
    if grey_raster >28523:
        output_raster = Con(ndvi_raster < -0.000009 * grey_raster + 0.437673,2,1)
    output_raster.save(os.path.join(outputws,rimage))

edit: in my real usecase I have 3 if statements, not 2!

naming; formatting
Source Link
Vince
  • 20.3k
  • 16
  • 48
  • 65
Loading
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Loading
Source Link
GIS7
  • 358
  • 1
  • 14
Loading