There is an NDVI image of a small agricultural area. I was also given separate shapefiles for all fields (37 fields) inside that area. I have written a script that clipped NDVI image for each field using the shapefile. When a clipped NDVI image is saved, it is exported in tiff format and grayscale.
Shape_Files_Name = ['TX1_10_poly.shp', 'TX1_11N_poly.shp', 'TX1_11S_poly.shp'...........] for n in Shape_Files_Name: #mask out each field Clipped_File_Name = random.randint(1,101) arcpy.gp.ExtractByMask_sa (NDVI_Layer, n,
Clipped_File_Name
) #save the raster
arcpy.CopyRaster_management (Clipped_File_Name
, NDVI_Save_Location_and_Extension)
I was trying to find a way to export them to a known colour ramp. Thus, a dummy layer is created and applied the desired colour ramp to it. Later, for each NDVI field image, just applying the colour ramp by the following codes
arcpy.ApplySymbologyFromLayer_management(in raster, color ramp layer)
It works. But I would like to export those NDVI images in the colour ramp I applied. Is there any way to do that in ArcPy?
Copy Raster—Data Management toolbox | ArcGIS Desktop
CopyRaster_management (in_raster, out_rasterdataset, {config_keyword}, {background_value}, {nodata_value}, {onebit_to_eightbit}, {colormap_to_RGB}, {pixel_type}, {scale_pixel_value}, {RGB_to_Colormap}, {format}, {transform})
There are optional parameters there..which you might want to experiment with that deal with color. If your raster is has a colormap already you might be able to save that with the raster since I suspect it is defaulting and not being set
There was no colormap. To create a colormap, I clicked "Unique Values" on the symbology of the raster properties, it showed the maximum limit of unique value has been reached. Thus, I can't even save it with any color map.
Btw, after applying color ramp, the raster can manually be exported with color ramp in it. It was mainly because the RGB is forced into it. However, could not find any ArcPy so far to do that!
Unique wouldn't work in any event. Was your image rgb to begin with? there is that rgb_to_colormap option
No, it was a single band image. NDVI value ranging from -1 to 1.
Gray scale is what I would expect given the range of values
Is there any other option at all?
I am not sure... an image would help
If you clipped/extracted ndvi image had a color scheme, then you should be able to use it... not the original, but the extracted one and there are only two options with copyraster and you indicate applysymbology from layer doesn't work (you need a layer).
If you can show with the extracted image done manually and what you are getting via code, then I might have a clearer picture why you need a color ramp other than b&w
I am trying to explain the whole scenario -
1. The shown image is the pansharpened image which contains 4 bands (BGR and NIR)
2. NDVI was generated using "Image Analysis" option. The object of interest is the field no. 7N as its shapefile is also turned on (red circle.)
3. Here is the clipped field -using "Extracted By Mask" (Spatial Analyst) tools.
4. After changing the color ramp, is it looks like this. It is better for visualization, so our team asked for the same color image. I am trying to save this file with exactly this color. If I use copy raster then the result gets back to the image shown in no. 3 (grayscale).
Can you please tell me is there really anyway to save the raster exactly the same [as shown in no.4] with Python (Export function can do that)?
Thanks
Here is a very similar problem.