5

I have a raster dataset (USDA Cropscape dataset) where each pixel is given a crop or landcover type (eg, corn, rice, urban area, forest). Some of the pixel values are classified as more than 1 crop/landcover type. For example, there are 40,000 pixels that are classified as “Double Crop Barley/Corn” as the class name. This is because certain acres of land engage in crop rotation practices. I have attached a screenshot of the attribute table.

I would like to reclassify the pixels (shown in 'Count' column of attached screenshot) as either Barley OR Corn (but not both), so that 20,000 pixels are classified as barley and 20,000 are corn. Now for the important part: I would like to randomly distribute the reclassification so that there is not a clustering of one crop type (ie, corn or barley) but an even and random distribution of each reclass across the entire extent. I don't want the first 20,000 pixels to be corn and the next to be barley, but every other pixel being classified as either one would be nice.

How would you go about this? General outline or step by step guidance, if possible. The important part is to get half of the pixels reclassified in randomized distributionattribute table of Cropscape raster layer

  • 1
    40,000 random coin flips does not mean that the end result will be 20k each. Do you want the reclassification to be random or evenly split (and alternating)? – Paul Sep 30 '15 at 22:34
  • Thanks Paul for the clarification. Would prefer it to be evenly split (20k for corn, 20k for barley) AND randomly distributed across the raster's extent. The goal is to have corn and barely equally (but also randomly) represented across sub-basins that fall within the extent. Any further tips? – bocadillo Oct 2 '15 at 20:15
3

Generate a random raster using the same cell size (and snapped to) as your ag data, reclassify the random raster so that all of the >0.5 values represent corn values and the < 0.5 values are barley values.

Use a Con function to replace all the corn+barley cells with the values with the randomly created corn or barly surface.

  • Thanks so much for the advise! I got the first part. But for the second part about the Con function, would you elaborate on it some more as well as give an example - if possible? I'm not 100% clear. – bocadillo Oct 2 '15 at 20:20
  • For example, say your Barley+Corn value that you want to replace is 2. The Con function will sift through that raster, find any cell with a value of 2, and replace that cell with the cell value from the reclassified raster. If it is false that the value is 2, keep the original cell value. Your con parameters might look like this. Input conditional raster: your original vegetation surface... Expression: VALUE = 2 Input true raster: that reclassified random raster that you made... Input false raster: the original vegetation surface... Output raster: the newly created surface – GBG Oct 5 '15 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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