Raster Calculator "Merge" two Rasters - SyntaxError

1108
5
Jump to solution
04-06-2014 01:17 AM
Stefaningenfeld
New Contributor
Greetings guys,

first i must apologize for my english, i am no nativ speaker
I have a problem with the Raster Calculator in ArcGis 10.2.1 (ArcInfo)

Situation description:

I have two different Rasters ("basic_raster" and "damm").

The "basic_raster" contains the normal Environment with z values
[ATTACH=CONFIG]32841[/ATTACH]

The "damm" raster contains a damm with z values
[ATTACH=CONFIG]32843[/ATTACH]

I would like to add the "Z" value from the Damm Raster to the Environment Raster.
At the end it should looks like this picture but of course in one Raster
[ATTACH=CONFIG]32842[/ATTACH]

In the Forum they said i had to create a "condition" raster. To do that i used the reclassify funktion from the spatial Analyst to create "Reclass_damm" (check the picture).
[ATTACH=CONFIG]32840[/ATTACH]

87 = the infos i want to add to the other Raster (87meter is the height for the damm)
0 = ignor this areas, i want to keep the infos from the basic_raster


Next i started the Raster calculator and tried this command:

New_Raster = Con(condition > 0, "Reclass_damm", "basic_raster")

But something with the condition is wrong i get all the time this error:

Messages
Executing: RasterCalculator "New_Raster = con(condition > 0, "Reclass_damm" "basic_raster")" "E:\Master Thesis\Datenbank.mdb\New_Raster"
Start Time: Sun Apr 06 10:15:45 2014
New_Raster = con(condition > 0, Raster(r"Reclass_damm") Raster(r"basic_raster"))
ERROR 000539: Parsing error SyntaxError: invalid syntax (line 5)
Failed to execute (RasterCalculator).
Failed at Sun Apr 06 10:15:46 2014 (Elapsed Time: 0,55 seconds)


Maybe somebody out there who could help ?
0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable
Original User: Hornbydd

Stefan,

Your syntax looks good but the error message is making a reference to no spatial reference. You need to ensure that both grids have the same coordinate system. You can use the Define Projection tool to set the raster that does not have a coordinate system defined.

As a side note I see you are creating a raster in a personal geodatabase. Whilst that is possible I have found rasters in personal geodatabases to be problematic. I would strongly suggest you place the output raster in a file geodatabase or as an ESRI grid in a folder. ESRI grids seem to work best for raster processing but have a limited file name length.

Duncan

View solution in original post

0 Kudos
5 Replies
by Anonymous User
Not applicable
Original User: Hornbydd

I think your CON statement should be:

New_Raster = Con("Reclass_damm", "Reclass_damm", "basic_raster", "VALUE > 0")
0 Kudos
Stefaningenfeld
New Contributor
Hello Hornbydd,

thx for your answer, your command worked fine with my little test setup.
But when i tried it with a bigger Raster file i got this message:

Messages
Executing: RasterCalculator "New_Raster = Con("reclass_damm", "reclass_damm", "basic_raster", "VALUE > 0")" C:\Users\stefan\Desktop\Versuchsdb.mdb\New_Raster
Start Time: Sun Apr 06 22:24:53 2014
New_Raster = Con(Raster(r"reclass_damm"), Raster(r"reclass_damm"), Raster(r"basic_raster"), "VALUE > 0")
ERROR 000539: Error running expression: rcexec()
Traceback (most recent call last):
  File "<expression>", line 1, in <module>
  File "<string>", line 5, in rcexec
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 244, in Con
    where_clause)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Utils.py", line 47, in swapper
    result = wrapper(*args, **kwargs)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\sa\Functions.py", line 238, in Wrapper
    where_clause)
  File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\geoprocessing\_base.py", line 498, in <lambda>
    return lambda *args: val(*gp_fixargs(args, True))
ExecuteError: ERROR 999999: Error executing function.
FDO error: -2147024894 [GDB_Items]
No spatial reference exists.
ERROR 010302: Unable to create the output raster: C:\Users\stefan\Documents\ArcGIS\Default.gdb\Con_reclass_2
ERROR 010067: Error in executing grid expression.
Failed to execute (Con).
Failed to execute (RasterCalculator).
Failed at Sun Apr 06 22:24:54 2014 (Elapsed Time: 0,82 seconds)


I did the same like before... This time the damm raster had a lot more Z values and the area was a lot bigger...
My Reclassify looked like this:
[ATTACH=CONFIG]32856[/ATTACH]
After it's done the file looked like this:
[ATTACH=CONFIG]32857[/ATTACH]

looked fine to me the "noData" rasters got the 0...

any clue what i made wrong ?

PS.
The original Damm Z values are in a polyline, is it possible to add them direct to the Raster, like the spatial analyst can do it with lines, points and polygones) ?

Right now i extract the position of the damm from the basic raster via "Extract by mask"
The Damm Polyline is my mask.
Than i use "Raster to point" to create a point layer
After that i change the z values in a few areas and change it back to a raster (Raster to Point)
This new Raster i reclassify and than i try to add the damm Z values to the basic raster.

There must be a better way to to this... even when it would work...
0 Kudos
by Anonymous User
Not applicable
Original User: Hornbydd

Stefan,

Your syntax looks good but the error message is making a reference to no spatial reference. You need to ensure that both grids have the same coordinate system. You can use the Define Projection tool to set the raster that does not have a coordinate system defined.

As a side note I see you are creating a raster in a personal geodatabase. Whilst that is possible I have found rasters in personal geodatabases to be problematic. I would strongly suggest you place the output raster in a file geodatabase or as an ESRI grid in a folder. ESRI grids seem to work best for raster processing but have a limited file name length.

Duncan
0 Kudos
Stefaningenfeld
New Contributor
Hello Duncan,

I tested your suggestion on my main computer but nothing changed i still had the same error messages...

But than i also tested it on my second computer and it worked absolutly perfect, no errors *sigh*

Right now i reinstall my ArcGIS version on this PC i have the feeling it's damaged.

really thx for you help 🙂
0 Kudos
luismunoz
New Contributor
Hello Duncan,

I tested your suggestion on my main computer but nothing changed i still had the same error messages...

But than i also tested it on my second computer and it worked absolutly perfect, no errors *sigh*

Right now i reinstall my ArcGIS version on this PC i have the feeling it's damaged.

really thx for you help 🙂


Hey! I'm having the same problem I'm not getting how to use the CON (Spatial ANALYST TOOL) to make the raster of both items, I guess you already figured it out! Please help me I need to know how to do this and Ive been stuck for days.
If you could explain me with detail I will really appreciated! Thanks
My mail is luismunozd@me.com THANKS A LOT!
0 Kudos