I have a raster file depicting 64 seperately labels polygons.
How can I randomly select 34 of those polygons & output to a new file???
Thank you in advance for any suggestions.
Teresa - -
----------
Teresa Hansen, Ogden Professional Services
Phone: 206-967-4985
teresa@lewis-deh2.army.mil
Teresa Hansen (teresa@lewis-deh2.army.mil) writes on 29 November 1995:
I have a raster file depicting 64 seperately labels polygons.
How can I randomly select 34 of those polygons & output to a new file???
use a simple program to randomly select, without replacement,
34 out of 64 categories (I coded one up for you, attached).
Then use r.reclass. You should be able to modify the attached
program to write a reclass rules file.
--
Darrell McCauley, PhD; mccauley@mcs.com; http://www.mcs.com/~mccauley/
/*-
* short program to randomly select, without replacement, NSELECT objects
* out of POOLSIZE
*
* Written by Darrell McCauley <mccauley@mcs.com>
*
* Note: rand may not be available on all systems and is not a good RNG.
* Do not use rand for designing missle intercept systems or for medical
* research.
*/
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#define RANDOM(lo,hi) ((float)rand()/RAND_MAX*(hi-lo)+lo)
#define POOLSIZE 64
#define NSELECT 34
int main ()
{
int i, n = 0;
char pool[POOLSIZE];
srand (time (NULL));
for (i = 0; i < POOLSIZE; i++)
pool[i] = NULL;
while (n < NSELECT)
{
i = (int) RANDOM (1, POOLSIZE) - 1;
if (pool[i] == NULL)
{
n++;
fprintf (stderr, ".");
pool[i] = 1;
}
}
fprintf (stderr, "\n");
for (i = 0; i < POOLSIZE; i++)
if (pool[i] != NULL)
printf ("%d\n", i);
return 0;
}