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
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)
-
Edit: @user181566, the code snippet originally had this as a .lyrx file, which is for ArcPro. Updated to .lyr file (pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layerfile.htm).Keggering– Keggering2021年06月03日 22:50:24 +00:00Commented Jun 3, 2021 at 22:50
Explore related questions
See similar questions with these tags.