An AML Program For Calculating the Number

of Points within a Set of Polygons

Appendix 1. The Complete Listing of the AML Program & Menu

The AML : pip.aml

 
&severity &error &routine exit
&terminal 9999
&type
&type

&type   ----------------------------------------
&type   |                                      |
/*      | Assignment 2     John J Bark         |
/*      |                                      |
&type   | This AML Calculates the Number of    |
&type   | Points within a set of Polygons      |
&type   |                                      |
&type   ----------------------------------------

/*
/* ---------------------------
/* Selecting Correct Workspace
/* ---------------------------
/*
&pause &seconds 1
&label correct_wspace
&type
&type
&type
w
&type
&sv i = 0
&pause &seconds 2
&messages &popup
&sv correct_wspace = [query 'Are you in the correct Workspace']
&messages &on
&if %correct_wspace% = .TRUE. &then
&goto coverages
/*
/* -----------------
/* Change Workspace?
/* -----------------
/*
&label change_wspace
&messages &popup
&sv change_wspace = [query 'Do you want to change Workspace']
&messages &on
&if %change_wspace% = .TRUE. &then
&goto select_wspace
&label not_help
&type
&type
&type This Program cannot help you any further.
&pause &seconds 1
&messages &popup
&sv quit = [query 'Do you want to Quit']
&messages &on
&if %quit% = .TRUE. &then
&goto end
&type
&type
&type The AML will reset itself.
&pause &seconds 2
&goto correct_wspace
/*
/* ------------------
/* Changing Workspace
/* ------------------
/*
&label select_wspace
w /home/magis/[username]
&type
&sv select_wspace = [getfile * -workspace 'Please select the Workspace you wish to enter' -sort -none]
&if %select_wspace% = ' ' &then
&do
&pause &seconds 1
&type
&type
&type You have not selected a Workspace.
&pause &seconds 1
&goto not_help
&end
w %select_wspace%
&sv wspace_name = [entryname %select_wspace%]
&type
&type
&type You may now select Coverages from Workspace %wspace_name%.
&pause &seconds 2
/*
/*
/* ---------------------
/* Selecting Coverages
/* ---------------------
/*
/*
&label coverages
&type
&type In a moment, Popup Menus will appear allowing you to select Polygon and Point Coverages for use within this AML.
&type
&type If the Coverage you require is not listed, select the NONE option.
/*
/* ----------------
/* Polygon Coverage
/* ---------------
/*
&label polygon
&sv poly [getcover * -poly -none 'Select a Polygon coverage']
&if %poly% = ' ' &then
&goto none_cover
&type
&sv poly_name = [entryname %poly%]
&if %i% = 1 &then
&goto correct
/*
/* ---------------
/* Points coverage
/* ---------------
/*
&label point
&sv point [getcover * -point -none 'Select a Point coverage']
&if %point% = ' ' &then
&goto none_cover
&sv point_name = [entryname %point%]
&if %i% = 2 &then
&goto correct
&goto name_intersect
/*
/* --------------------------
/* Coverage selection of NONE
/* --------------------------
/*
&label none_cover
&pause &seconds 1
&type
&type
&type You selected the NONE option from the Popup Menu.
&pause &seconds 2
&goto correct_wspace
/*
/* -------------------------------------
/* Entering Intersect coverage name
/* -------------------------------------
/*
&label name_intersect
&pause &seconds 1
&type
&type To discard any Points located outside of the Polygons a new Coverage is created using an Intersect Overlay.
&pause &seconds 2
&label name_loop
&messages &popup
&sv out_cov = [response 'Enter a name for the Intersect Coverage']
&messages &on
&if %out_cov% = ' ' &then
&do
&type
&messages &popup
&pause YOU MUST ENTER A NAME
&messages &on
&goto name_loop
&end
&type
&type Checking Validation of Coverage Name .....
&pause &seconds 3
/*
/* ------------------------
/* Validating Coverage name
/* ------------------------
/*
&if [exists %out_cov% -cover] &then
&do
&messages &popup
&pause Coverage %out_cov% exists in this Workspace. You will need to enter another name.
&sv list_cov1 = [query 'Do you want to see a list of existing Coverage names in this Workspace']
&messages &on
&if %list_cov1% = .TRUE. &then
lc
&goto name_loop
&end
&if [exists %out_cov%_freq.tab -info] &then
&do
&type
&type Later in this AML a Frequency Table is produced, but a Frequency File already exists for coverage name %out_cov%.
&type
&type To prevent confusion you need to enter another name for the Intersect Coverage.
&pause &seconds 3
&messages &popup
&sv list_cov2 = [query 'Do you want to see a list of existing Coverage names in this Workspace']
&messages &on
&if %list_cov2% = .TRUE. &then
lc
&goto name_loop
&end
/*
/* ------------------------------
/* Confirming Coverage Selections
/* ------------------------------
/*
&label correct
&pause &seconds 1
&type
&type
&type This AML will now perform an Intersect Overlay between
&type Polygon Coverage : %poly_name%
&type Points Coverage : %point_name%
&type Creating Intersect Coverage : %out_cov%
&type
&type If these details are correct the Intersect Overlay can be performed, otherwise you can change any of these selections.
&pause &seconds 5
&messages &popup
&sv intersect = [query 'Are these details correct']
&messages &on
&if %intersect% = .TRUE. &then
&goto intersect
&else
&menu intersect.menu &stripe 'Do you wish to change the'
&if %i% = 1 &then
&goto polygon
&if %i% = 2 &then
&goto point
&if %i% = 3 &then
&goto name_loop
&if %i% = 4 &then
&goto intersect
/*
/* -----------------------
/* Performing the Intersect
/* ------------------------
/*
&label intersect
&messages &popup
&pause Click on OK to perform the Intersect
&messages &on
&type
&type Intersecting %point_name% with %poly_name% to create %out_cov% .....
&messages &off
intersect %point% %poly% %out_cov% point # join
&messages &on
&type
&type Coverage %out_cov% was created by the performing the Intersect Command.
&pause &seconds 2
/*
/* ---------------------
/* Calculating Frequency
/* ---------------------
/*
&type
&type The Frequency Command is now used to calculate the Points Frequency within this Coverage.
&type
&pause &seconds 3
&messages &popup
&pause Click on OK to Calculate Frequency
&messages &on
&sv freq_item = [entryname %poly%]
&sv freq_item = %freq_item%#
&sv summary_item = %out_cov%-ID
&type
&type Calculating the Points Frequency .....
&messages &off
frequency %out_cov%.pat %out_cov%_freq.tab %out_cov%_case_item
%freq_item%
END
%summary_item%
END
&messages &on
&type
&type Points Frequency Calculated
&pause &seconds 2
/*
/* --------------------------------
/* Labelling Frequency in .pat file
/* --------------------------------
/*
&type
&type This program uses Joinitem to insert the calculated frequency into attribute table of Polygon Coverage %poly_name%.
&type
&type A name is required for this item in the attribute table.
&sv freq_name = frequency
&if [iteminfo %poly% -polygon %freq_name% -exists] &then
&do
&type
&type You cannot use item name Frequency as this already exists in the attribute table for %poly_name%.
&pause &seconds 3
&label item_name
&messages &popup
&sv freq_name [response 'Please enter a new Item Name']
&messages &on
&type
&if %freq_name% = ' ' &then
&do
&messages &popup
&pause YOU MUST ENTER A NAME.
&messages &on
&goto item_name
&end
&if [iteminfo %poly% -polygon %freq_name% -exists] &then
&do
&messages &popup
&pause Item name %freq_name% is not acceptable as it already exists in the Attribute Table.
&messages &on
&goto item_name
&end
&else
&do
&type Item Name %freq_name% is acceptable.
&pause &seconds 2
&goto freq_name
&end
&end
&type
&type The default item name is Frequency.
&pause &seconds 2
/*
/*
&label freq_name
&type
&messages &popup
&sv pat_item = [query 'Please confirm the use of this Item Name']
&messages &on
&if %pat_item% = .FALSE. &then
&goto item_name
/*
/* -------------------------------
/* Changing Frequency Item in INFO
/* -------------------------------
/*
&if %freq_name% = frequency &then
&goto joinitem
&type
&type Now changing Item Name Frequency to %freq_name% .....
&data ARC INFO > /dev/null
ARC
SELECT [UPCASE %out_cov%]_FREQ.TAB
ALTER FREQUENCY
[UPCASE %freq_name%]
~
~
~
~
~
~
Q STOP
&end
&type
&type Frequency Item Name changed to %freq_name%.
&pause &seconds 2
/*
/* ----------------------------------
/* Using Joinitem to Merge INFO files
/* ----------------------------------
/*
&label joinitem
&type
&type Joinitem will attach Frequency file %out_cov%_freq.tab to the attribute table of Polygon Coverage %poly_name%.
&pause &seconds 3
&messages &popup
&pause Click on OK to perform Joinitem
&messages &on
&type
joinitem %poly_name%.pat %out_cov%_freq.tab %poly_name%.pat %poly_name%# %poly_name%# #
&type
&type Unnecessary joined Items will be dropped from the attribute table of polygon coverage %poly_name%.
&type
dropitem %poly_name%.pat %poly_name%.pat %out_cov%_case_item
dropitem %poly_name%.pat %poly_name%.pat %out_cov%-id
&type
&pause &seconds 1
&messages &popup
&sv list = [query 'Do you want to list the Attribute Table containing Frequency']
&messages &on
&if %list% = .TRUE. &then
&do
&type
list %poly_name%.pat
&end
&type
&goto exit
/*
/* --------------------
/* Tidying Up Workspace
/* --------------------
/*
&label exit
&type
&type You have created the following:
&type Intersect Coverage : %out_cov%
&type Frequency File : %out_cov%_freq.tab
&type
&pause &seconds 2
&messages &popup
&sv delete_inter = [query 'Do you want to Delete the Intersect Coverage']
&messages &on
&if %delete_inter% = .TRUE. &then
&do
&type Deleting Intersect Coverage %out_cov% .....
&type
&messages &off
kill %out_cov%
&messages &on
&type Intersect Coverage %out_cov% has been deleted
&pause &seconds 2
&end
&messages &popup
&sv delete_freq = [query 'Do you want to Delete the Frequency File']
&messages &on
&if %delete_freq% = .TRUE. &then
&do
&type Deleting Frequency File %out_cov%_freq.tab .....
&type
&data ARC INFO > /dev/null
ARC
SELECT [UPCASE %out_cov%]_FREQ.TAB
DELETE [UPCASE %out_cov%]_FREQ.TAB
Y
Q STOP
&end
&type
&type Frequency file %out_cov%_freq.tab has been deleted.
&end
&label end
&messages &on
&type
&return
 
 
/*
/*
/* Error Routine
/* -------------
/*
&routine exit
&severity &error &ignore
&messages &on
&return &error An error has occurred.
 

The Menu : intersect.menu

 
1 intersect.menu
'Selected Coverages'
POLYGON &sv i = 1; &return
POINT &sv i = 2; &return
'Intersect Coverage name' &sv i = 3; &return
'OR perform the Intersect' &sv i = 4; &return

 

Return to Main Document

Last Updated 08-03-99