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

From phurvitz
Jump to: navigation, search
Line 1: Line 1:
 
<pre>
 
<pre>
 +
/*----------------------------
 
/* change dir
 
/* change dir
 
w D:\SAPRP_Working_Files\Raster_Calculations\Sample_Frame\costd
 
w D:\SAPRP_Working_Files\Raster_Calculations\Sample_Frame\costd
  
 +
/*----------------------------
 
/* start grid
 
/* start grid
 
grid
 
grid
  
 +
/*----------------------------
 
/* gridpoint
 
/* gridpoint
 
if ^[exists frameg -grid] &then
 
if ^[exists frameg -grid] &then
 
   framep = gridpoint (..\frame4)
 
   framep = gridpoint (..\frame4)
 
/* add an area and count field to the frame points
 
/* add an area and count field to the frame points
&if [exists ...field]
+
&if ^[iteminfo framep -point needlecount -exists] &then
 +
  additem framep.pat framep.pat needlecount 5 5 i
 +
&if ^[iteminfo framep -point cdarea -exists] &then
 +
  additem framep.pat framep.pat cdarea 10 10 i
  
 +
/* max distance to costdistance function
 
&sv maxdist 100
 
&sv maxdist 100
  
 
+
/*----------------------------
 
/* 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%
 
   /* select the point i
 
   /* select the point i
 
   reselect framep point framep# = %i%
 
   reselect framep point framep# = %i%
Line 29: Line 38:
  
 
   /* delete the selection file
 
   /* delete the selection file
   &sv d [delete pts.sel -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   
 
   /* create a grid from the one selected point   
Line 37: Line 49:
 
   outg = con(costdistance(p1, ..\frame4, #, #, %maxdist%) > 0, 1, 0)
 
   outg = con(costdistance(p1, ..\frame4, #, #, %maxdist%) > 0, 1, 0)
  
   /* get the cell count
+
   /* get the cell count (assumes only one value in the grid!)
   LIST <info_file> INFO {range} {item...item}
+
   &sv cellcount = [show outg.vat info 1 item count]
 
   /* cell count * 9 = area
 
   /* cell count * 9 = area
 +
  &sv cdarea = 9 * %cellcount%
  
 
   /* create a polygon from the costdistance grid
 
   /* create a polygon from the costdistance grid
Line 45: Line 58:
 
    
 
    
 
   /* reselect needle points that overlap
 
   /* reselect needle points that overlap
   /* RESELECT <cover> <feature_class> OVERLAP <overlap_cover>
+
   clearselect
        /* <overlap_feature> {selection_distance}
+
   reselect needles point overlap poly1 poly # #
        /* {PASSTHRU | WITHIN}
 
   reselect needles point overlap poly1 poly  
 
  
 
   /* count of selection
 
   /* count of selection
 +
  &sv numneedles = [extract 1 [show select needles point]]
 
    
 
    
 
   /* write selection and area back onto frameg point
 
   /* write selection and area back onto frameg point
   calculate
+
   calc framep point needlecount = %numneedles%
 +
  calc framep point cdarea = %cdarea%
  
 
   /* kill intermediate files
 
   /* kill intermediate files
Line 59: Line 72:
 
   kill outg
 
   kill outg
 
   kill poly1
 
   kill poly1
 
+
&end
 
 
 
 
 
</pre>
 
</pre>

Revision as of 17:42, 6 November 2007

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

/*----------------------------
/* start grid
grid

/*----------------------------
/* gridpoint
if ^[exists frameg -grid] &then
  framep = gridpoint (..\frame4)
/* add an area and count field to the frame points
&if ^[iteminfo framep -point needlecount -exists] &then
  additem framep.pat framep.pat needlecount 5 5 i
&if ^[iteminfo framep -point cdarea -exists] &then
  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%
  &type %i% of %numpoints%
  /* select the point i
  reselect framep point framep# = %i%
  /* save the selection
  writeselect pts.sel framep point
  /* reselect from framep to create p1 
  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  
  pointg = pointgrid(p1)
  
  /* run the costdistance
  outg = con(costdistance(p1, ..\frame4, #, #, %maxdist%) > 0, 1, 0)

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

  /* create a polygon from the costdistance grid
  poly1 = gridpoly (outg)
  
  /* reselect needle points that overlap
  clearselect
  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
  kill pointg
  kill outg
  kill poly1
&end