Hot answers tagged

6

You can use Set Null statement: OutRas = SetNull(InRas1 < 128, InRas1) The above function will set all the values less that 128 to null. The above code can be run using Raster Calculator. If you are using Python, your code should be adjusted to like this outSetNull = SetNull("inRaster", "inRaster", "VALUE < 128") Try to avoid starting your ...


3

Use Boolean logic. Reclassify the first raster: 0 for all values in your range and 1 for the rest. Do the same for the second. Then use raster calculator and multiply together and the output will be 0 matching your parameters and 1 for everything else. http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/reclassify.htm http://desktop....


3

The equivalent syntax for the Raster Calculator would be: Con("myRaster.tif","myRaster.tif",-1,(FocalStatistics("myRaster.tif",NbrWedge(4,285,345),"MINIMUM")== -1))


3

Con expression must be logical. Either your create a bianry raster with values of 1/0 or you write the query (condition, value if true, value if false). In your case, this will be Con(("raster_road" == 1) | ("raster_road" == 2), "raster_road", "raster_land_cover") where | is the logical "or" and & would be the logical "and" (if needed) Note that if ...


3

More logical solution in your case Con(isnull(raw) or (raw<20), 0, formulae) Use symbol from raster calculator for OR, I cannot find one on my phone Formulae is .004*raw-0.08 which is negative at raw < 20


3

You can use the conditional tool: Con((raster<x),(eq1),Con((raster>x), (eq2),(eq3 or constant))) where eq1 your first calculation for true statement, eq2 your calculation for your second true statement and eq3 or a constant for your false statement. For example, for dataset Raster1 that has value ranging between 1:10, if Raster1 <=5 but >0 you ...


2

Here is how I would write this to reduce the number of tests : Con("Slope" <= 1 , 0.2 , Con("Slope" <= 3 , 0.3 , Con("Slope" <= 5, 0.4 , 0.5))) Note that you need to write several Con() because "|" is only used to test booleans.


2

the Y value is the values "if false" (and X is the value "if true"). You can enter a constant values (e.g. could be 0 in your case), a layer (could be your weighted overlay raster). Also, testing equality in the raster calculator is done by using "==" ("=" will not work)


2

Use == which is the equality operator, not a single = which is the assignment operator (i.e a = 1 assigns the value 1 to the variable a). You can also shorten your expression by having the comparison as the first argument and dropping the Value field. E.g: test_reclass = Float(Con("cpraster3.tif" == 1, 0.27, Con("cpraster3.tif" == 2, 1.00, Con("cpraster3....


2

As mentioned by @Luke, set arcpy.env.scratchWorkspace before running Spatial Analysis tool will redirect that result to scratch workspace.


2

GetParameterAsText gets the value AS TEXT. Therefore a,b,c,d are all strings. You need to convert them to a numeric format before asking Con to compare them to x.


2

I think you want to use nested Con statements, like is described here to build your if-elif-else structure, instead of Con() | Con() | Con(). Instead of saying: Con(queryA, trueA, falseA) | Con(queryB, trueB, falseB) | etc... You should phrase it as: Con(queryA, trueA, Con(queryB, trueB, Con(...))) where the innermost Con() statement will have 0 as it's ...


2

This will list the raster names without full path/workspace: arcpy.env.workspace = r'C:/speed' speed = arcpy.ListRasters("*SPEED*","TIF") So when you change workspace afterwards, arcpy will not know where to find them. Try adding full path to the raster lists using os.path.join and list comprehension: import os arcpy.env.workspace = r'C:/speed' speed = ...


2

Quoting example three from the documentation, proper use of Con includes a final step: import arcpy from arcpy import env from arcpy.sa import * env.workspace = "C:/sapyexamples/data" inRaster1 = Raster("landuse") inRaster2 = Raster("landuse2") outCon = Con(((inRaster1 == 1) & (inRaster2 == 5)), inRaster1 + inRaster2, 99) outCon.save("C:/sapyexamples/...


2

Con is an ArcGIS raster tool which is not available in QGIS. If you want to replace all 0 value cells with nodata, you could use something like: ("demclip_re@1") / ("demclip_re@1">0)


2

Try this piece of code. I do not think that you have to cast the mean/std to float. Try it out this way. Of course you need an Spatial Analyst, but since you are using RasterCalculator I think you have it. import arcpy from arcpy.sa import * arcpy.CheckOutExtension('Spatial') ws2 = r"C:\unsupervised_classification\output\raster_tagliati_su_flowacc" ...


1

There is probably a more elegant way, but you can do this using Con, SetNull, and InList, which functions like the in conditional operator you were trying. Con(IsNull(InList("q530_prj_Clip.tif", [2800,2804,2808,2812,6896,6900,6904,6908,2976,2980,2984,2988,3008,3012,3016,3020,7072,7076,7080,7084,7104,7108,7112,7116,2752,2756,2760,2764,3008,3012,3016,3020,...


1

It's possible that the issue is due to the Background Geoprocessing. You can disable background processing from the geoprocessing menu, Geoprocessing Options... Then untick the enable box. Run your code again.


1

@FelixIP comment is correct, you need to convert your raster file to a raster object using arcpy.Raster() before using Con(). Here is the code that worked for me: import arcpy from arcpy.sa import * from arcpy import env env.workspace = r"F:\Test\Test\FolderName" ext_out = arcpy.CheckOutExtension("SPATIAL") raslist = arcpy.ListRasters('*.tif') for ras ...


1

It appears that you're entering the labels in the SQL expression and not the values themselves. It should work if you query the numeric values without any text. Here's an example for "North": VALUE >= 0 AND VALUE <= 22.5 You might find this page helpful.


1

This logic can equally be done very easily in model builder as shown below: You don't need to do a reclassification the CON tool can achieve this. A CON tool would be set up as shown below:


1

I think your problem might be the expression is a string to when the raster calc runs it can't find the "fin" variable. I rewrote the expression to use the arcpy.sa module for the Con and Mod functions. I would also build a list of tif files in a directory (assuming all your tifs are contained in it and not more) so that you don't miss any and don't try to ...


1

I haven't found a limit in the number of nestings in a Map Algebra expression, however there is a limit to the length of the expression itself: The maximum length of the logical expression is 4,096 characters See Con - ArcGIS Desktop Help. My guess is that if you hit a limit to the number of nestings in an expression, it will be based on your system ...


1

This should work: Con("Name_of_Raster_1" > ("Name_of_Raster_2"*85+"Name_of_Raster_3" / 4),"Name_of_Raster_1",0)


1

Your loop could be simplified thus: import sys import os for raster in Listrasters: r = arcpy.Raster(raster) rastname = str(raster) #gets the layer's name in a variable finalname = "Quart_{}_{}_{}".format(a,b,rastname)#sets final layer name finalpath = os.path.join(finalGDB ,finalname) #sets the full ...


1

I'm not an ArcGIS expert; but I am going to have a guess at what the issue is here as I have a bit of a suspicion on what the cause is. The output of the raster calculator has been assigned to bands[1]; you haven't actually saved the output; it's just in memory at this stage. The next iteration of the loop, this memory data is now deleted and so each ...


1

Try the Reclassify tool: http://desktop.arcgis.com/en/arcmap/10.3/tools/spatial-analyst-toolbox/reclassify.htm Open this tool and you should be able to input your raster, then redefine pixel value(s).


1

Couldn't you just chain 3 functions in your model? Have each function create one of the rasters you want. To my knowledge there isn't a way to make a Con tool create multiple outputs.


1

The raster calculator is working a different way. First you need to declare your OutRaster that will be saved: OutRas = Con(...) Your expression may probably look like this (like your second try, but not sure why you set other names there): OutRas = Con("rocktype1"==1,1,Con("rocktype2"==2,2,Con("rocktype3"==1,3)))


1

Why don't you just use a reclassify? Other option it would be to read the raster like array and then perform the changes in the sense you want.


Only top voted, non community-wiki answers of a minimum length are eligible