1

How can I change the name of the composite raster of multiple bands as below- I think this may be the solution to efficiently address this problem but you are welcome for further solution?

demo

I have a composite raster, Proximity_Rasters_NoHNSN.tif, which is produced by vertically stacking several other rasters.I need to extract all the band-wise values into a point layer in arcmap.

Now I am using Extract Multi Values to Points tool to extract band-wise values into a point layer which will be used for further analysis. But the problem is- the field added to the point layer after running this tool is not quite trackable since this tool adds fields like b1_Proximity_Rasters_NoHNSN.tif , b2_Proximity_Rasters_NoHNSN.tif...just prepending the b and band number to the raster name as you see.So I think running this tool after changing the band names will give me a meaningful and trackable result.

The field names added by Extract Multi Values to Points tool are as below: dem

How I am solving my problem now:

Now I am using arcpy to solve this problem by creating a new field and copying corresponding value into it and deleting the field after copying, but this way is too much time-consuming since I am dealing with large data.


Added code since @PolyGeo was guiding:

#Change field names
ffields = sorted([i.name  for i in arcpy.ListFields(eq_smpled_pnts) if re.match(r"b\d_", i.name)])
for old_fld in ffields:
    indx = int(re.findall(r'^b(\d{1,})', old_fld)[0])-1
    new_fld = raster_bands_names[indx]
    arcpy.AddField_management(in_table=eq_smpled_pnts, field_name=new_fld, field_type="DOUBLE", field_precision="12", field_scale="", field_length="25", field_alias="", field_is_nullable="NULLABLE", field_is_required="NON_REQUIRED", field_domain="")
    arcpy.CalculateField_management(in_table=eq_smpled_pnts, field=new_fld, expression= "!%s!"%new_fld, expression_type="PYTHON", code_block="")
    arcpy.DeleteField_management(eq_smpled_pnts, new_fld)

Update: After trying @GISGe suggestion I found that all work correctly but the band1 does not change the name as intended!!See the screenshot of the script run as below:

Script I used to rename each band:

#Change composite band name
def band_name_changer(image_stack_path,names_ordered_list):
    raster_describe_object = arcpy.Describe(image_stack_path)
    if len(raster_describe_object.children) != len(names_ordered_list):
        raise Exception("Input raster names length and number of bands in the stacked image is not equal.......")
    else:
        for bnd in enumerate(raster_describe_object.children):
            indx_bnd = bnd[0]
            input_path = bnd[1].catalogpath
            output_path = os.path.join(os.path.split(input_path)[0], names_ordered_list[indx_bnd])
            arcpy.Rename_management(in_data=input_path, out_data=output_path, data_type="RasterBand")

But the output is ok except the BAND_1??

error

  • 1
    I've tried the Rename tool and it works with a raster band. Will add it as answer if your question is reopenend – GISGe Nov 24 '16 at 14:09
  • I think this question should be closed because you are asking for help with code without showing us a code snippet that illustrates what you have tried so far i.e. "I am using arcpy to solve this problem by creating a new field and copying corresponding value into it and deleting the field after copying". However, I will leave it open for now because @GISGe says that they have an answer to post. – PolyGeo Nov 24 '16 at 22:19
2

Could you just not use the functionality of the "Extract multivalues to points" tool with it's built in ability to cast an output field names of your choosing?

ExtractMultiValuesToPoints("observers.shp", [["elevation", "ELEV"], ["costraster", "COST"], ["flowdir", "DIR"]], "NONE")

  • Yes it worked! Very simple solution I did not catch at all. damn. – SIslam Nov 25 '16 at 13:44
1

So, the Rename tool allows you to rename a raster band. It can overwrite the name in the input dataset so you're not obliged to create a different output:

enter image description here

This will solve the issue prior to running the Extract Multivalues to Point tool, but you can also modify the output of this tool: with Alter field, you can overwrite field names, again without intermediate steps or temporary results (but is works only with GDB feature classes, not with shapefiles or SDE feature classes).

  • Of course, only rename is the preferable, since I am working with more than 20 fields and more than 6 crore features, here in comparison of the alter field method but this rename tweak is not doing the job as you see in the updated question. – SIslam Nov 25 '16 at 10:14
  • Well this is strange, your script works fine for me, all bands are renamed according to the provided list. – GISGe Nov 25 '16 at 10:27
  • Same here I tried with other rasters that work fine but this does not. And tired of retrying.. – SIslam Nov 25 '16 at 10:35

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.