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

From phurvitz
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
<pre>
 
<pre>
 +
/*----------------------------
 
/* 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 [exists ...field]
+
&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
 
&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%
  /* select the point i
+
&do i = 1 &to 2
  reselect framep point framep# = %i%
+
    &type %i% of %numpoints%
  /* save the selection
+
    &type [date -full]
  writeselect pts.sel framep point
+
    /* select the point i
  /* reselect from framep to create p1  
+
    clearselect framep point
  reselect framep p1 point pts.sel
+
    reselect framep point framep# = %i%
 
+
    /* save the selection
  /* delete the selection file
+
    writeselect pts.sel framep point
  &sv d [delete pts.sel -file]
+
    /* reselect from framep to create p1  
 
+
    &if ^ [exists p1 -cover] &then
  /* create a grid from the one selected point 
+
      arc reselect framep p1 point pts.sel
  pointg = pointgrid(p1)
 
 
 
  /* run the costdistance
 
  outg = con(costdistance(p1, ..\frame4, #, #, %maxdist%) > 0, 1, 0)
 
  
  /* get the cell count
+
    /* delete the selection file
  LIST <info_file> INFO {range} {item...item}
+
    &if [exists pts.sel -file] &then
  /* cell count * 9 = area
+
      &sv d [delete pts.sel -file]
 +
    &if [exists pts.sex -file] &then
 +
      &sv d [delete pts.sex -file]
  
  /* create a polygon from the costdistance grid
+
    /* create a grid from the one selected point 
  poly1 = gridpoly (outg)
+
    &if ^ [exists pointg -point] &then
 
+
      pointg = pointgrid(p1, #, #, #, 3)
  /* reselect needle points that overlap
+
   
  /* RESELECT <cover> <feature_class> OVERLAP <overlap_cover>
+
    /* run the costdistance
        /* <overlap_feature> {selection_distance}
+
    &if ^ [exists outg -grid] &then
        /* {PASSTHRU | WITHIN}
+
      outg = con(costdistance(pointg, frame4_n, #, #, %maxdist%) >= 0, 1, 0)
  reselect needles point overlap poly1 poly
 
  
  /* count of selection
+
    /* get the cell count (assumes only one value in the grid!)
 
+
    clearselect outg.vat info
  /* write selection and area back onto frameg point
+
    reselect outg.vat info value = 1
  calculate
+
    &sv cellcount = [show select outg.vat info 1 item count]
 +
    /* cell count * 9 = area
 +
    &sv cdarea = 9 * %cellcount%
  
  /* kill intermediate files
+
    /* create a polygon from the costdistance grid
  kill pointg
+
    &if ^ [exists poly1 -cover] &then
  kill outg
+
      poly1 = gridpoly (outg, 0.001)
  kill poly1
+
   
 
+
    /* 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
 
</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