Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to reference a field value in mosaic table to use in Python RFT #81

Open
resnow0892 opened this issue Sep 9, 2022 · 9 comments
Open

Comments

@resnow0892
Copy link

Hi,
I made a simple Python RFT chained with another RFT template. I use a Rasterize Feature to access a value inside a feature table. Then I am able to apply my python RFT to a mosaic. But It is not optimal for me.
I would like to directly use this numeric value stored in a field of my mosaic (this value can change from one raster to another inside the mosaic).
I made lot of test but unsuccessful.
Does someone has an idea on how to do that ?

thanks for your help.

@shenganzhan
Copy link
Contributor

You can create a RasterCollection from the mosaic and use getFieldValues to access the fields

@resnow0892
Copy link
Author

resnow0892 commented Sep 12, 2022

Thanks for you answer.
I made some tests using the RasterCollection. here is a part of my code :

    def updatePixels(self, tlc, shape, props, **pixelBlocks):
        
        #get the min anx max val of reference 
        test = RasterCollection(r'C:\testGDB\mosaicTest')

        mintest = test.getFieldValues('minVal')
        maxtest = test.getFieldValues('maxVal')

        pix_array = np.asarray(pixelBlocks['raster_pixels'])
       '''pixelBlocks rocessing'''

The mintest and maxtest variables return lists with all values in my mosaic

mintest
Out[54]: [-26, -24, -26, -22, -22, -21, 1, 1]

maxtest
Out[55]: [44, 0, 2, -1, 17, 2, 17, 20]

How to access correct list index from the pixelblock in process ?
Rasters are located in different places, and the min and max value change from one location to another. I would like to apply my python RFT using the min and max value of the mosaic item zoomed on.

@shenganzhan
Copy link
Contributor

shenganzhan commented Sep 12, 2022

I don't think it tells you which image the block comes from.

What do you want to do with the min/max?

@resnow0892
Copy link
Author

resnow0892 commented Sep 12, 2022 via email

@shenganzhan
Copy link
Contributor

How did you apply this to the current raster in the mosaic you are viewing?

I use a Rasterize Feature to access a value inside a feature table.

@resnow0892
Copy link
Author

resnow0892 commented Sep 13, 2022

I made 2 versions of the RFT.

  1. The first one takes as parameters one raster (the mosaic), and 2 numeric user defined min and max values. This version is manual and doesn't adapt to a level of zoom. But I try in this version to fin a way to replace the user defined min and max value with the mosaic fields.

  2. The second one takes as parameters 3 rasters:

  • the mosaic
  • a min constant value raster
  • a max constant value raster

To generate the min and max constant value rasters, I use the Rasterize feature raster function on a feature layer containing the min and max field. It works and depending of the rasster zoomed on, the colorscale automatically adapt to the range defined by the min and max in the feature layer (I manually created the feature layer polygons for each raster).
But this approach is not optimal, I am looking for another way to access these values.

On the home page I read an exemple which makes what I want (https://github.com/Esri/raster-functions):

"Fish Habitat Suitability
FishHabitatSuitability.py returns a raster representing suitability of fish habitat at a user-specified ocean depth given two rasters representing water temperature and salinity. This function demonstrates how raster functions can be exploited in analytic workflows.

[FishHabitatSuitability.rft.xml](https://github.com/Esri/raster-functions/blob/master/functions/FishHabitatSuitability.rft.xml] is a grouping raster function template that accepts the temperature and salinity rasters (in that order). This template—when used in the Add Rasters to Mosaic Dataset tool with the Table raster type or as a processing template on a mosaic dataset—is capable of obtaining the value of the depth parameter from a specific field (StdZ, if available) in the table."

I tried to reproduce this example using the @Field.min and @Field.max but not working. I am loosing hope to find a solution

@resnow0892
Copy link
Author

resnow0892 commented Sep 14, 2022

I tried to use as suggested a RasterCollection and make the intersection of the pixelblock object with the raster from the mosaic to access the values. Here is my updatePixel() function:

      def updatePixels(self, tlc, shape, props, **pixelBlocks):

        # Raster collection from an image mosaic service
        RC=RasterCollection('https://....')

        # pixelblock coordinates from x,y extend point geometry 
        point = arcpy.Point(props['extent'][0], props['extent'][1])
        pointGeometry = arcpy.PointGeometry(point).projectAs(arcpy.SpatialReference(props['spatialReference']))
        
        #Filter the Raster collection by geometry (intersecting the pixelblock)
        filterRC = RC.filterByGeometry(pointGeometry)
        
        # get min and max values for the intersected element
        valmin= filterRC.getFieldValues('minVal')[0]
        valmax= filterRC.getFieldValues("maxVal")[0]        
            
        pix_array = np.asarray(pixelBlocks['raster_pixels'])

        # Numpy operations to remap values from valmin and valmax
        bins = np.linspace(valmin, valmax, num=26) 
        pix_array = np.digitize(pix_array, bins,right=False)
        pix_array = np.where(pix_array == 0, 1, pix_array)

        pixelBlocks['output_pixels'] = pix_array.astype(props['pixelType'], copy=True)
               
        return pixelBlocks

It seems to work at a certain level of zoom. But when zooming out, nothing is displayed

@shenganzhan
Copy link
Contributor

It would be best if you could provide a reproducible case so we can diagnose.

@resnow0892
Copy link
Author

Ok, I will try to prepare some test data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants