Clip, Merge, Cluster, and Repeat Final project for G IS 375 Charles Morse
Purpose: Clustering is of great importance to my work in archaeology, it is the first clue of a significant region for study and important material association between object types. This script was an attempt to automate a routine analyzing and combining different layers to see which mergings produced more or less clustering while producing summary statements about the given feature classes. In so doing, I could have a python script for re-use on archaeological excavations such that the user to change the initial information and run the script immediately.
Preparation and setup The initial steps were the simple importation and setup to ensure that ‘arcpy.mapping’ was not needed before each mapping function. On the left, you will see that the code prints the day’s date and what this code was written for and when, to compare to the current date. The date code was taken from my professor Nathan Jennings’ assignment for the class this was written for.
I also set up the variables and different workspaces I also set up the variables and different workspaces. My reasoning for each is explained in the in the red text shown above.
Here, variables were given the specific names for the layers they referenced, just as the specific query and base name was given. Though each of these steps are needed for the current code, the construction that keeps this and the last slide’s code portions in mind was crucial as I wrote the script. By presenting all of these variables here, I know exactly what I would need to change to run this code in a new situation. This also shows the setup of the layer count for my clip routine and initiation of the listlayers function for my next loop.
Here, the first stage of preparing the layers begins: setting my processing extent. It employs the makefeaturelayer function when the selected layer name is the base I set up at the beginning. In one script, it makes a new layer with the desired region selected and then dissolves the lines between polygons to form a region to clip my other layers to. Somewhat awkwardly, the results of this portion do not print first as the Base variable is not selected until after a routine where the different variables and their associated layers are named.
Here, as noted above, the layers that are associated with each variable are named so the viewer can confirm that they were set correctly at the beginning of the code. Furthermore, it checks to see if the given mxd has any group layers. If not, it congratulates the viewer. If it does, it instructs to open the mxd in arcmap and ungroup.
This portion begins the clip routine This portion begins the clip routine. While I am clipping, set the output name to a variable that includes a count number. As that count increases, each layer is given the next number in its name. As a result, I have lyr_1-3 set as bases prepped for merging.
After deleting the processing extent to free the loop, each layer is merged to another while assuring that the current layer is the correct one (so layer 2 is not clipped to 3 to make layer 4 where, in succession, layers 1 and 2 should be combined to 4.
Meanwhile, layer 6 is formed through combining the first and last layer from the gdb. This is accomplished by maintaining the values from clipcount (even though clipping is no longer occurring) and by introducing other count variables like for the merge to be sure that LYR_1 and LYR_3 are combined. The result is the expected ideal, layers 1 – 6 are created in rapid succession
Now that the layers are prepared for analysis, we can begin cluster analysis. Unfortunately, I don’t have a way to save something to an incrementing number without exporting. Each fc is analyzed for clustering with the NN tool. Afterwards, each is saved to a new variable based on if it is LYR_1, 2, . . . 6.
This portion of the code is very repetitive, it calls for different summary statements based on whether the merging of tow layers increased or decreased the clustering of points in the first (or second) layer. Again, I could not find a way to loop and call for a variable as part of another variable.
At the conclusion of the code, simplified general statements are given about each layer named by their actual terms (e.g., cemeteries, conifer trees, etc) given for VAR_1, _2, and _3 at the beginning. When each statement was given as the general summary in the step before, the general statement of rising and lowering were assigned to each pt variable. This is followed by a print statements for each pt variable with a large space before each to make it more obvious in the shell.
Indiana + Illinois + Ohio + Kentucky + Michigan To be sure that this routine worked with more regions, I modified the query for different areas and it ran with slightly different results, showing increasing association and dissociation of variables defending on the area investigated. Indiana + Illinois Indiana + Illinois + Ohio + Kentucky + Michigan California + Arizona + Utah + Oregon + Nevada + Idaho