I need to do some raster/vector processing on some non-overlapping tiles. My python script needs to find the correct tiles and then extract the raster values and count them up. My script needs to be flexible enough such that sometimes there are no tiles to process while othertimes there could be up to four (since they are tiles, and my vector is so small, it is impossible for there to be more than four)

There is no switch/case in python so I am struggling at an efficient way of doing this. So basically I need to construct the variable inRaster out of 1,2,3,or 4 different rasters.

I can do it when there is only one but the problem is that with all these search cursors and loops, (a) my script is really slowing down and (b) it is not clear to me how to add 2, 3, or 4 rasters. I'd like to do something like inRaster=Plus(tile1,tile2,tile3) or inRaster=Plus(tile1,tile2,tile3,tile4).

I figured I would see if the intersect between my polygon and tiles has any rows in it (it should have 0,1,2,3,or 4 rows) and if there is some data, then construct inRaster

While I can do it for one row, I have trouble understanding how to loop thru all the rows.

        arcpy.MakeQueryTable_management(tempIntersect, tempTable,"USE_KEY_FIELDS")

        # Print the total rows
        arcpy.AddMessage("       numberOfRows for distance = " + str(dist) +"m is=" + str(numberOfRows) + " ...")            
        if not (numberOfRows is None):
            if numberOfRows   == 1:
                for myTileName in arcpy.da.SearchCursor(tempIntersect, "TILENAME"):
                    inRaster= os.path.join(TSpace,myTileFullName)
                    arcpy.AddMessage("       numberOfRows " + str(inRaster) + " ...")

                    outExtCircle=ExtractByCircle(inRaster, arcpy.Point(x,y), dist, "INSIDE")
                    rtemp          = os.path.join(WSpace,"myRastTemp")
                    if arcpy.Exists(rtemp):
                        #arcpy.AddMessage("       Deleting " + rtemp + " ...")
                #  Here I am trying to loop through and get all the tiles (and failing)
                for myTileName in arcpy.da.SearchCursor(tempIntersect, "TILENAME"):
                    arcpy.AddMessage("       tilename is " + str(myTestString) + " ...")

Your Answer

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

Browse other questions tagged or ask your own question.