0

I would like to multiply all the values within a raster layer with one value, which is written in an *.csv table (it is the only value in this table).

I tried this code (changing Times tool to Minus tool)

>>> import arcpy
>>> from arcpy import env
>>> from arcpy.sa import* 
>>> arcpy.env.workspace = "D:/Bachelorthesis"
>>> dgm = ['dgm']
>>> gwf = ['Groundwatertable']
>>> path = 'd:/Bachelorthesis/gis_daten_footprint/Data(1)/GIS_data.mdb/gwf'
>>> value = [row[0] for row in arcpy.da.SearchCursor(path,gwf)]
>>> Gwt = set(value)
>>> print (Gwt)
set([28.124])
>>> outMinus = Minus(dgm,Gwt) 

But then this error appears:

 Runtime error 
 Traceback (most recent call last):
   File "<string>", line 1, in <module>
   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py", line 3840, in Minus
     in_raster_or_constant2)
   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Utils.py", line 47, in swapper
     result = wrapper(*args, **kwargs)
   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\sa\Functions.py", line 3837, in wrapper
     return _wrapLocalFunctionRaster(u"Minus_sa", ["Minus", in_raster_or_constant1, in_raster_or_constant2])
TypeError: expected a raster or layer name

But 'dgm' is definitely a raster... Does anyone know how to make it work?

  • 1
    What GIS software are you using? What have you tried so far? – PolyGeo Jun 23 '16 at 11:23
  • I am using ArcGIS 10.1. I've tried the raster calculator, but that doesn't work because it only reads raster. And joining tables and raster doesn't work either. – NathalieLea Jun 23 '16 at 11:29
  • If you need to retrieve the table value automatically, you will need arcpy. I would read the value in the csv table with a Search Cursor, then feed it in the Times tool along with the raster. – GISGe Jun 23 '16 at 11:55
1

What I understand is you want to use the raster values to do some calculations with the values in the csv file. This is one way to do it.

Step1: Convert the raster into a point file. Use the raster values as column info of the point file.

Step2: Use that point file info to make calculations with the csv.

Step3: Once calculations are done. Either convert back the point file into the raster.

  • thanks! But now I have a problem with step 2... I can't find how to write to sql expression for the fieldCalculator in arcpy. How can I express hat I would like to have all the values from that field minus a certain value? Apparently arcpy.CalculateField_management("gwf","test","test"-2) doesn't work... – NathalieLea Jun 28 '16 at 10:18
  • @NathalieLea I think you can make the equation with simple SQL expression in field calculator itself. If you can share the details of equation, it would make it more clear exactly what u aim to do. – Chetan Jun 28 '16 at 12:48
  • My problem actually lies in this simple SQL expression. I can't find anywhere how to express in arcpy.CalculateField that each row in one field (f.ex. "test") is subtracted by a certain value (here "Gwt", that I defined in the script above with value = [row[0] for row in arcpy.da.SearchCursor(path,gwf)]). So I tried many different possibilities but nothing worked. For example: arcpy.CalculateField_management("gwf","test","test"-"Gwt"). The thing is also, that I need it to work automatically in a script that I will insert in a modell. – NathalieLea Jun 29 '16 at 8:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.