Con is empty - no result in python but in Map Algebra

607
2
Jump to solution
06-14-2021 05:28 AM
JohannesBierer
Occasional Contributor III

Hello,

I've problems with a Con command. In python there is only a empty result (no error message), but if I use Map Algebra  - raster calculator in ArcMaP there is a result? Version ArcGIS Desktop 10.6.1

What's wrong with the Con :

OutRas = Con((outClip > value2) & (outClip < value), outClip)

value2 is 0.1 m less than value in a dgm. For example Value: 907.1346 m und Value2: 907.0346 m

Any ideas? It's in line 64?

def ExpandSperren_1(self, outFC):

        myList = list()

        # outFC = Sperren_3D

        outLyr = "outLyr"

        arcpy.MakeFeatureLayer_management(outFC, outLyr)

        arcpy.AddField_management(outLyr, "POINT_Z_1", "DOUBLE") # , 10, 4)

        with arcpy.da.UpdateCursor(outLyr, ["POINT_Z", "POINT_Z_1"]) as cursor:

            for r in cursor:

                value = round(r[0], 4)
                print value
                r[1] = value

                cursor.updateRow(r)

        d = {}

        for r in arcpy.da.SearchCursor(outLyr, ["ORIG_FID", "POINT_Z_1"]):

            print r[0]

            d[r[0]] = r[1]

        for key, value in d.iteritems():

            # print value
            
            sel = "{} = {}".format("ORIG_FID", key)
            print sel
                    
            arcpy.SelectLayerByAttribute_management(outLyr, "NEW_SELECTION", sel)

            result = arcpy.GetCount_management(outLyr)
            count = int(result.getOutput(0))
            print("Count is {}".format(count))

            value2 = value - 0.1

            print "Value: {} und Value2: {}".format(value, value2)

            # Select Basin
            BasinLyr = "BasinLyr"
            arcpy.MakeFeatureLayer_management(self.outBasin, BasinLyr)
            arcpy.SelectLayerByLocation_management(BasinLyr, 'intersect', outLyr)

            strR = round(value, 4)
            print strR

            ReplaceRstrR = str(strR).replace(".", "_")
            outClip = "clip_{}".format(ReplaceRstrR)

            arcpy.Clip_management("SperrenDGM", "", outClip, BasinLyr, "#", "ClippingGeometry", "NO_MAINTAIN_EXTENT")

            arcpy.CheckOutExtension("Spatial")

            OutRas = Con((outClip > value2) & (outClip < value), outClip)
            OutRas.save("OutRas_{}".format(ReplaceRstrR))
            
            outFlood = value - OutRas
            outFlutung = Con(outFlood > 0, outFlood)
            outPut = "Zwischen_Height_{}".format(ReplaceRstrR)
            outFlutung.save(outPut)

            myList.append(outPut)

        self.outFLRaster = "AAA_FlHoehe_Gesamt_Kaltenbronn"
        arcpy.MosaicToNewRaster_management(myList, arcpy.env.workspace, \
                                   self.outFLRaster, "",\
                                   "32_BIT_FLOAT", "1", "1", "LAST","FIRST")

        arcpy.CheckInExtension("Spatial")

 

0 Kudos
1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

I believe you'd have to cast outClip into a Raster object to use that map algebra syntax i.e. arcpy.Raster(outClip)

OutRas = Con((arcpy.Raster(outClip) > value2) & (arcpy.Raster(outClip) < value), outClip)

 

View solution in original post

0 Kudos
2 Replies
DavidPike
MVP Frequent Contributor

I believe you'd have to cast outClip into a Raster object to use that map algebra syntax i.e. arcpy.Raster(outClip)

OutRas = Con((arcpy.Raster(outClip) > value2) & (arcpy.Raster(outClip) < value), outClip)

 

0 Kudos
JohannesBierer
Occasional Contributor III

Thank you David, that worked!