How to stretch values of raster inside the polygons?

1627
6
12-15-2016 06:20 AM
KarolinaKorzeniowska
Occasional Contributor

I have a raster dataset (DEM) and a shapefile with around 2000 polygons. I have cut my raster to the boundaries of my polygons and now I would like to stretch the values of my raster into 0-1 values range based on their height (the lowest height = 0, the highest height = 1). However, I would like to stretch into 0-1 values inside every polygon separately (so the values inside every individual polygon have to be stretched into 0-1 range). Is there some automatic way to do this? 

Tags (3)
0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

I would suggest performing the work manually then acquire the code snippet from the Results Window and/or produce a model of the workflow, using an iterator to cycle through the rasters.  Each polygon will have to be used to produce a separate raster, which will be pretty onerous, so if you are adept with python and coding, you could work with arrays to skip the need to produce permanent rasters

KarolinaKorzeniowska
Occasional Contributor

Thank you for your answer. I followed your idea, however I stocked in the last step - stretching the data. Below is my workflow which I implemented in model builder:

1. Iterate feature selection of my polygons using their ID

2. Clip the raster DEM using selected polygons

3. Get raster properties from my clipped DEM (minimum and maximum values)

4. Stretch the data using raster calculator expression: (("%DEM_%Value%.tif%"-(%Property%))*1)/(%Property (2)%-(%Property%))

where:

%DEM_%Value%.tif% - input DEM and %Value% is the polygon ID

%Property%  - minimum

%Property (2)% - maximum

After running my model I have the error (attached below) and I do not know why it does not work, because when I try to run it manually it works. Any ideas?

Start Time: Fri Dec 16 08:12:01 2016
(("%DEM_%Value%.tif%"-(1403.25))*1)/(3229.6999511719-(1403.25))
ERROR 000539: Error running expression: rcexec()
Traceback (most recent call last):
File "<expression>", line 1, in <module>
File "<string>", line 5, in rcexec
TypeError: unsupported operand type(s) for -: 'str' and 'float'

Failed to execute (Raster Calculator (2)).
Failed at Fri Dec 16 08:12:01 2016 (Elapsed Time: 0.28 seconds)

DanPatterson_Retired
MVP Emeritus

it is because 
"%DEM_%Value%.tif%"  is enclosed in double quotes, making it a string
%DEM_%Value%.tif%  would return a number I presume

KarolinaKorzeniowska
Occasional Contributor

I think this is not the case, because after removing the quotes I cannot run the model at all, I have a message that the expression in raster calculator is wrong.

0 Kudos
DanPatterson_Retired
MVP Emeritus

well then the message is strange since one part of the subtraction is a string and the other part is a float, so unless your whole field is a string, ... in which case a new field needs to be created and values in numeric format determined

0 Kudos
KarolinaKorzeniowska
Occasional Contributor

Thank you for your answer. I am not sure if I understand you correctly. I have tried to create from my string data a float data using Copy Raster function. However, still I have a message that my data are string. It is strange, because both (input and output) data which I used in copy raster function are float.

0 Kudos