4

The code below creates many IDW rasters:

for date in all_dates:
    # Create a feature layer of each unique date
    where = "{0}=date '{1}'".format(arcpy.AddFieldDelimiters(datasource=fc, field=date_field),
                                    date.strftime('%Y-%m-%d'))
    arcpy.MakeFeatureLayer_management(in_features=fc, out_layer='lyr', where_clause=where)

    # For each field interpolate. This is untested since I dont have spatial analyst
    for fieldname in value_fields:
        outIDW = Idw(in_point_features='lyr', z_field=fieldname,
                     cell_size=10)  # , {power}, {search_radius}, {in_barrier_polyline_features})
        outIDW.save(os.path.join(output_folder, '{0}_{1}.tif'.format(fieldname, date.strftime('%Y%m%d'))))

as you know the generated rasters are in black and white(color ramp) I want to know if I can change them to other colors by using ArcPy not one by one in ArcMap.

1 Answer 1

4

The "Apply Symbology From Layer" tool does this. After the "outIDW.save" step, the layer will be the top-most layer in the map, so simply apply the symbology to the first layer in your map document. For example:

topLyr = arcpy.mapping.ListLayers(mxd, "*", df)[0]
symbologyLyr = r"C:\MyLayerFileFolder\someLayerFile.lyr"`
arcpy.management.ApplySymbologyFromLayer(topLyr, symbologyLyr)

(See Saving layers and layer packages).

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.