Sie sind auf Seite 1von 5

Pseudocode:

GET code location path


GET data location path
GET directory location
SET workspace to data location path
SET output overwrite TRUE

PRINT "Welcome to Timothy Blanchard's Multiple Query Analysis of Lunar Craters Python Tool for GIS 540."

PRINT "Beginning crater and geology data download. Please wait..."


SET new path for data download
IF NOT new path exists THEN:
Make new path
ENDIF

SET url list of data locations on ftp server


SET names of data files wanted

FOR url in geology url list:


Open url to obtain zipfile
READ zipfile
FOR files in zipfile:
FOR name in data files wanted list:
IF file has name THEN:
IF NOT (newpath + "/" + name) exists THEN:
Extract zipfile to newpath
PRINT newpath + "/" + name + " downloaded."
ELSEIF:
PRINT newpath + "/" + name + " already exists."
ENDIF
ENDIF
ENDFOR
ENDFOR
CALL close zipfile
PRINT "Crater and geology data downloaded."

PRINT "Beginning geology data correction as needed..."

Initialize empty geology file list

FOR feature classes in new path (just downloaded):


IF feature class endswith "geology.shp" THEN:
Append feature class to geology list
ENDIF
ENDFOR

CALL geology geodatabase create (geologyGDBCreate.py) method:


IF NOT geology geodatabase exists THEN:
SET output geodatabase
CALL arcpy Feature Class to Geodatabase Conversion on geology list
Update geology list with new gdb files
PRINT "{0} created.".format(outGDB)
ELSEIF:
PRINT "Geodatabase already exists."
ENDIF

PRINT "Applying row value corrections..."

DEFINE geologyCorrect(gdb):
SET row correction dictionary with correct spelling as keys for incorrect values
SET workspace to gdb
SET overwrite to TRUE
SET geology list by calling arcpy List Feature Classes
FOR geology in geology list:
SET field list by calling arcpy List Fields
FOR field in field list:
IF field name is Epoch THEN:
FOR correct, incorrect in row correction dictionary:

1
FOR value incorrect list:
Where Epoch row values are incorrect
Initialize cursor at where for geology
FOR row in cursor:
SET correct row value
CALL update cursor for row
ENDFOR
ENDFOR
ENDFOR
ENDIF
ENDFOR
ENDFOR

CALL geologyCorrect(geology database)

PRINT "Data corrections complete! Select options from widget..."

SET epoch list with epoch names

DEFINE class SubmitButton(Button):


DEFINE __init__(self,parent):
Button. __init__(self,parent)
SET text to "Submit Selections"
SET command to destroy window
SET location at bottom

DEFINE class EpochSelect:


DEFINE __init__(self, parent):
SET to top level window from parent
Create listbox
Initialize listbox list with "Unclassified"
FOR item in epoch list:
ADD item to listbox list
Bind double clicks in listbox to call OnDouble
Pack listbox
CALL top.mainloop()
DEFINE OnDouble(self, event):
SET widget event
GET cursor selection
SET value of cursor selection
OPEN epochfile text file for writing
WRITE value of cursor selection
CLOSE epochfile
Destroy top level window

DEFINE myEpoch():
SET myEpoch to call EpochSelect(root) to initiate callback of EpochSelect

SET root to Tk()


SET text to StringVar()
SET label to Message(root, textvariable=text, relief=RAISED, width = 400)
SET widget title to "Multiple Query Analysis of Lunar Craters"
SET title location

SET minVar to DoubleVar()


SET minScale to Scale(root, variable=minVar, orient=HORIZONTAL, to=590,
label="Minimum Crater Diameter (km)", length = 200)
SET minScale location anchored to center
SET maxVar to DoubleVar()
SET maxScale to Scale(root, variable=maxVar, orient=HORIZONTAL, from_=1,
to=591,label="Maximum Crater Diameter (km)", length = 200)
SET default max scale value to 591
SET maxScale location anchored to center

SET epoch button to execute myEpoch command with text "Epoch Selection"
SET epoch button location anchored to center

SET frame for region radio button selection using label text "Select Lunar Region"
SET frame to fill and expand window
SET regionVar to IntVar()

2
SET first radio button in frame for regionVar with text "Near Side" and value 703
SET first radio button location anchored to center
SET first radio button to default selection

SET second radio button in frame for regionVar with text "Right Side" and value 948
SET second radio button location anchored to center

SET third radio button in frame for regionVar with text "Left Side" and value 1034
SET third radio button location anchored to center

SET fourth radio button in frame for regionVar with text "Far Side" and value 1047
SET fourth radio button location anchored to center

SET fifth radio button in frame for regionVar with text "South Pole" and value 1162
SET fifth radio button location anchored to center

SET sixth radio button in frame for regionVar with text "North Pole" and value 1062
SET sixth radio button location anchored to center

CALL SubmitButton(root)
CALL root.mainloop()

GET minimum variable value


GET maximum variable value
IF minimum is greater than maximum THEN:
Warning: "Given min value is greater than given max. Please try again."
END
ENDIF
GET string value of region variable value
IF NOT epochfile exists (no selection was made from widget) THEN:
SET value to default epoch ('Imbrian System')
OPEN epochfile text file for writing
WRITE value to default epoch
CLOSE epochfile
ENDIF
OPEN epochfile for reading
READ epochfile and set at epoch variable
CLOSE epochfile
Remove epochfile from directory
PRINT "Craters with a range of diameter from {0} to {1} will be searched for in\
region {2} from the {3}.".format(min,max,region,epoch)

PRINT "Searching for objects..."


DEFINE findCraters(min,max,craterOutput):
GET crater file location
SET crater layer variable
SET expression "DIAM_KM > {0} AND DIAM_KM < {1}".format(min, max)
CALL arcpy Make Feature Layer management for crater file and crater layer
CALL Select Layer by Attribute: new selection from crater layer with expression
CALL arcpy Copy Features for crater layer to output
CALL arcpy Get Count to set count integer for crater layer selection
IF count is zero THEN:
Warning: "No craters were found in the given range. Please try again."
END
ELSEIF:
PRINT str(count) + " craters were found in the size range."
ENDIF

SET crater output


CALL findCraters(min,max,craterOutput)

SET region dictionary with file name keys and region name values
Find matching region from widget selection
FOR r in matching region:
SET decoded region to r recoded from Unicode to ASCII
ENDFOR
SET epoch search expression to "Epoch = '{0}'".format(epoch)
SET region layer variable
SET region output variable
CALL arcpy Make Feature Layer management for decoded region and region layer

3
CALL arcpy Select Layer by Attribute: new selection from region layer with expression
CALL arcpy Copy Features for region layer to region output
CALL arcpy Get Count to set count integer for region layer selection
CALL split on decoded region for \\ and set as rDList
CALL join on rDList with / and set as decoded region
IF count is zero:
Warning: "Surface areas from the '{0}' epoch do not exist in the {1} region."
.format(epoch, regionDict[regionDecoded])
END
ELSIF:
PRINT str(count) + " surface areas were found in the {0}
region.".format(regionDict[regionDecoded])
ENDIF
PRINT "Search finished, preparing results..."

SET intersect list to crater output and region output


SET intersect output variable
SET statistics table output
CALL arcpy Intersect analysis for intersect list with intersect output
SET statFields to ["MEAN", "MIN", "MAX", "STD", "COUNT"]
CALL arcpy Statistics analysis for intersect output with DIAM_KM for statFields

CALL arcpy List Tables to set tables


FOR table in tables:
With arcpy Search Cursor (table, *) as cursor:
FOR row in cursor:
SET statValues to [row[2:]]
IF row[6] (COUNT) is zero:
Warning: "No craters in the given range found from the
selected epoch in the selected region."
END
ENDIF
ENDFOR
ENDFOR

SET html header


SET html body
CALL HTML.Table (statValues, header_row = statFields) to build results table
SET column break to create two column page

CALL arcpy Make Feature Layer for crater output to "Craters from selected range"
CALL arcpy Make Feature Layer for region output to "Selected Epochs in Region"
CALL arcpy Make Feature Layer for intersect output to "Craters Found"

CALL arcpy mapping Map Document to set mxd (directory + "\CraterQuery.mxd")


SET dataframe by calling arcpy mapping List Data Frames on mxd for frame 0

CALL arcpy mapping Layer on "Selected Epochs in Region" to set region map add
CALL arcpy mapping Add Layer to add region to data frame
CALL arcpy mapping Layer on "Craters from selected range" to set craters map add
CALL arcpy mapping Add Layer to add craters to data frame
CALL arcpy mapping Layer on "Craters Found" to set found craters map add
SET found symbology from dataPath + "\\foundcraters_symbology.lyr"
CALL Apply Symbology From Layer management to set found crater symbology
CALL arcpy mapping Add Layer to add found craters to data frame

SET extent to region by calling getExtent()


CALL dataframe.extent to apply extent

SET output jpg location


CALL arcpy mapping Export to JPEG on mxd to output jpg location

FOR layer in arcpy mapping List Layers of mxd data frame:


CALL arcpy mapping Remove Layer to remove created layers, for reusability
ENDFOR

DELETE mxd to clear mxd

SET image location and encoding


SET image tag for encoded image

4
SET footer
SET html results file location
OPEN html file for writing
WRITE to html file the header, body, results table, column break, image tag, and footer
CLOSE html file

CALL webbrowser open new tab for html file


PRINT "Finished. See results in opened browser tab."

Das könnte Ihnen auch gefallen