Difference between revisions of "Main Page/Stuff/Luc's AML"

From phurvitz
Jump to: navigation, search
 
Line 2: Line 2:
 
/*----------------------------
 
/*----------------------------
 
/* change dir
 
/* change dir
w D:\SAPRP_Working_Files\Raster_Calculations\Sample_Frame\costd
+
&wo D:\SAPRP_Working_Files\Raster_Calculations\Sample_Frame\costd
  
 
/*----------------------------
 
/*----------------------------
 
/* start grid
 
/* start grid
grid
+
&if [show program] <> GRID &then
 +
    grid
 +
 
 +
/* &goto skipkill1
 +
&if [exists pointg -grid] &then
 +
    kill pointg
 +
&if [exists p1 -cover] &then
 +
    kill p1
 +
&if [exists outg -grid] &then
 +
    kill outg
 +
&if [exists poly1 -cover] &then
 +
    kill poly1
 +
&label skipkill1
  
 
/*----------------------------
 
/*----------------------------
 
/* gridpoint
 
/* gridpoint
if ^[exists frameg -grid] &then
+
&if ^ [exists frame4_n -grid] &then
  framep = gridpoint (..\frame4)
+
    frame4_n = setnull (..\frame4 == 0, 1)
 +
&if ^ [exists framep -point] &then
 +
    framep = gridpoint (frame4_n)
 
/* add an area and count field to the frame points
 
/* add an area and count field to the frame points
&if ^[iteminfo framep -point needlecount -exists] &then
+
&if ^ [iteminfo framep -point needlecount -exists] &then
  additem framep.pat framep.pat needlecount 5 5 i
+
    arc additem framep.pat framep.pat needlecount 5 5 i
&if ^[iteminfo framep -point cdarea -exists] &then
+
&if ^ [iteminfo framep -point cdarea -exists] &then
  additem framep.pat framep.pat cdarea 10 10 i
+
    arc additem framep.pat framep.pat cdarea 10 10 i
 +
 
  
 
/* max distance to costdistance function
 
/* max distance to costdistance function
Line 24: Line 39:
 
/* count points
 
/* count points
 
&describe framep
 
&describe framep
&sv numpoints = dsc$points
+
&sv numpoints = %dsc$points%
  
 
/*----------------------------
 
/*----------------------------
 
/* go!
 
/* go!
&do i = 1 &to %numpoints%
+
/*&do i = 1 &to %numpoints%
  &type %i% of %numpoints%
+
&do i = 1 &to 2
  /* select the point i
+
    &type %i% of %numpoints%
  reselect framep point framep# = %i%
+
    &type [date -full]
  /* save the selection
+
    /* select the point i
  writeselect pts.sel framep point
+
    clearselect framep point
  /* reselect from framep to create p1  
+
    reselect framep point framep# = %i%
  reselect framep p1 point pts.sel
+
    /* save the selection
 +
    writeselect pts.sel framep point
 +
    /* reselect from framep to create p1  
 +
    &if ^ [exists p1 -cover] &then
 +
      arc reselect framep p1 point pts.sel
  
  /* delete the selection file
+
    /* delete the selection file
  &if [exists pts.sel -file] &then
+
    &if [exists pts.sel -file] &then
    &sv d [delete pts.sel -file]
+
      &sv d [delete pts.sel -file]
  &if [exists pts.sex -file] &then
+
    &if [exists pts.sex -file] &then
    &sv d [delete pts.sex -file]
+
      &sv d [delete pts.sex -file]
  
  /* create a grid from the one selected point   
+
    /* create a grid from the one selected point   
  pointg = pointgrid(p1)
+
    &if ^ [exists pointg -point] &then
 
+
      pointg = pointgrid(p1, #, #, #, 3)
  /* run the costdistance
+
   
  outg = con(costdistance(p1, ..\frame4, #, #, %maxdist%) > 0, 1, 0)
+
    /* run the costdistance
 +
    &if ^ [exists outg -grid] &then
 +
      outg = con(costdistance(pointg, frame4_n, #, #, %maxdist%) >= 0, 1, 0)
  
  /* get the cell count (assumes only one value in the grid!)
+
    /* get the cell count (assumes only one value in the grid!)
  &sv cellcount = [show outg.vat info 1 item count]
+
    clearselect outg.vat info
  /* cell count * 9 = area
+
    reselect outg.vat info value = 1
  &sv cdarea = 9 * %cellcount%
+
    &sv cellcount = [show select outg.vat info 1 item count]
 +
    /* cell count * 9 = area
 +
    &sv cdarea = 9 * %cellcount%
  
  /* create a polygon from the costdistance grid
+
    /* create a polygon from the costdistance grid
  poly1 = gridpoly (outg)
+
    &if ^ [exists poly1 -cover] &then
 
+
      poly1 = gridpoly (outg, 0.001)
  /* reselect needle points that overlap
+
   
  clearselect
+
    /* reselect needle points that overlap
  reselect needles point overlap poly1 poly # #
+
    clearselect needles point
 +
    reselect needles point overlap poly1 poly  
  
  /* count of selection
+
    /* count of selection
  &sv numneedles = [extract 1 [show select needles point]]
+
    &sv numneedles = [extract 1 [show select needles point]]
 
+
   
  /* write selection and area back onto frameg point
+
    /* write selection and area back onto frameg point
  calc framep point needlecount = %numneedles%
+
    calc framep point needlecount = %numneedles%
  calc framep point cdarea = %cdarea%
+
    calc framep point cdarea = %cdarea%
  
  /* kill intermediate files
+
    /* kill intermediate files
  kill pointg
+
/* &goto skipkill
  kill outg
+
    kill pointg
  kill poly1
+
    kill p1
 +
    kill outg
 +
    kill poly1
 +
&label skipkill
 +
    &type [date -full]
 
&end
 
&end
 
</pre>
 
</pre>

Latest revision as of 22:05, 6 November 2007

/*----------------------------
/* change dir
&wo D:\SAPRP_Working_Files\Raster_Calculations\Sample_Frame\costd

/*----------------------------
/* start grid
&if [show program] <> GRID &then
    grid

/* &goto skipkill1
&if [exists pointg -grid] &then
    kill pointg
&if [exists p1 -cover] &then
    kill p1
&if [exists outg -grid] &then
    kill outg
&if [exists poly1 -cover] &then
    kill poly1
&label skipkill1

/*----------------------------
/* gridpoint
&if ^ [exists frame4_n -grid] &then
    frame4_n = setnull (..\frame4 == 0, 1)
&if ^ [exists framep -point] &then
    framep = gridpoint (frame4_n)
/* add an area and count field to the frame points
&if ^ [iteminfo framep -point needlecount -exists] &then
    arc additem framep.pat framep.pat needlecount 5 5 i
&if ^ [iteminfo framep -point cdarea -exists] &then
    arc additem framep.pat framep.pat cdarea 10 10 i


/* max distance to costdistance function
&sv maxdist 100

/*----------------------------
/* count points
&describe framep
&sv numpoints = %dsc$points%

/*----------------------------
/* go!
/*&do i = 1 &to %numpoints%
&do i = 1 &to 2
    &type %i% of %numpoints%
    &type [date -full]
    /* select the point i
    clearselect framep point
    reselect framep point framep# = %i%
    /* save the selection
    writeselect pts.sel framep point
    /* reselect from framep to create p1 
    &if ^ [exists p1 -cover] &then
      arc reselect framep p1 point pts.sel

    /* delete the selection file
    &if [exists pts.sel -file] &then
      &sv d [delete pts.sel -file]
    &if [exists pts.sex -file] &then
      &sv d [delete pts.sex -file]

    /* create a grid from the one selected point  
    &if ^ [exists pointg -point] &then
      pointg = pointgrid(p1, #, #, #, 3)
    
    /* run the costdistance
    &if ^ [exists outg -grid] &then
      outg = con(costdistance(pointg, frame4_n, #, #, %maxdist%) >= 0, 1, 0)

    /* get the cell count (assumes only one value in the grid!)
    clearselect outg.vat info
    reselect outg.vat info value = 1
    &sv cellcount = [show select outg.vat info 1 item count]
    /* cell count * 9 = area
    &sv cdarea = 9 * %cellcount%

    /* create a polygon from the costdistance grid
    &if ^ [exists poly1 -cover] &then
      poly1 = gridpoly (outg, 0.001)
    
    /* reselect needle points that overlap
    clearselect needles point
    reselect needles point overlap poly1 poly 

    /* count of selection
    &sv numneedles = [extract 1 [show select needles point]]
    
    /* write selection and area back onto frameg point
    calc framep point needlecount = %numneedles%
    calc framep point cdarea = %cdarea%

    /* kill intermediate files
/* &goto skipkill
    kill pointg
    kill p1
    kill outg
    kill poly1
&label skipkill
    &type [date -full]
&end