GEOG 375 Final Project Robert Abbotts Spring 2013.

Slides:



Advertisements
Similar presentations
School of Geography FACULTY OF ENVIRONMENT Working with Tables 1.
Advertisements

NSF DUE ; Module 4.3. NSF DUE ; GeoTEd Partners Module name and number.
Environmental GIS Nicholas A. Procopio, Ph.D, GISP Some slides from Lyna Wiggins (Rutgers University)
Why python? Automate processes Batch programming Faster Open source Easy recognition of errors Good for data management What is python? Scripting programming.
Python & ModelBuilder. Overview Python/ModelBuilder Concepts – The Geoprocessor – Checking some environment variables – Providing feedback from your model/script.
ModelBuilder In ArcGIS 9.x By Tim Weigel GEOG 407/607 April 3 rd, 2006.
ModelBuilder at ArcGIS 9.2 Lyna Wiggins Rutgers University May 2008.
ArcEditor ArcInfo ArcView Display map, query & analyze spatial relationships, features & attributes Same functions as ArcView, plus abilty to create, &
@ 2007 Austin Troy. Geoprocessing Introduction to GIS Geoprocessing is the processing of geographic information. Perform spatial analysis and modeling.
Querying an Avian Inventory Database and Visualizing the Results GEORGE WASHINGTON BIRTHPLACE NATIONAL MONUMENT NATIONAL PARK SERVICE NR 595D Final Project.
To find a suitable land to develop a dream vacation home GEO376 Final Python Project Helen Peng May 2010.
Python & ModelBuilder. Continuing Education Python and ModelBuilder Overview Python/ModelBuilder Concepts –The Geoprocessor –Checking some environment.
Working with cursors in Python GISDE Python Workshop Qiao Li.
Extending Python Doing more than just interfacing with the geoprocessor Free example utility for NZ Projections Kim Ollivier.
2005 Ohio GIS Conference September 21-23, 2005 Marriott North Hotel Columbus, Ohio Geoprocessing for Animal Premises ID Luanne Hendricks State of Ohio.
Overview Cursors arcpy.da module Geometrys Arrays SpatialReferences
Introduction to ArcPy. Topics What is ArcPy? Accessing geoprocessing tools using ArcPy Writing scripts using ArcPy.
ArcGIS Network Analyst: Automating Workflows with Geoprocessing
Attributes in ArcGIS. ArcGIS Attributes FID – ESRI’s internal identifier Shape – Actual spatial data.
Copyright © 2006 by Maribeth H. Price 8-1 Chapter 8 Geoprocessing.
Spatial Analysis Workshop In-Class Exercise Tuesday, December 11, 2012.
Data Queries Selecting features in ArcMap Data queries  Important part of a GIS project Can be a part of your data preparation or final analysis  Data.
WBAreaComID Queries. By first converting the NHDFlowline feature class to a point feature class and then joining the flowline point feature class with.
Selecting features in ArcMap
WBAreaComID Queries Paul Kimsey 3/18/2007. Open Arc Toolbox.
NR 322: Editing Attributes Jim Graham Fall 2008 Chapter 6.
William Perry U.S. Geological Survey Western Ecological Research Center Geography 375 Final Project May 22, 2013.
Lecture 10: Geoprocessing with Python (II) Dr. Taysir Hassan Abdel Hamid Associate Professor, Information Systems Dept., Faculty of Computers and Information.
Data Visualization and Best Practices Webinar. Overview Environmental Data Sources and Considerations  SDWIS, radon labs, local health departments, for.
Outline of Script Import Modules Setup Workspace Environment and Assign Data Path Variables Summary of Script Title and Author Info.
Introduction to GIS Programming Final Project Submitted by Todd Lenkin Geography 375 Spring of 2011 American River College.
Lecture 18: Spatial Analysis Using Rasters Jeffery S. Horsburgh CEE 5190/6190 Geographic Information Systems for Civil Engineers Spring 2016.
Tech Support Tips and Tricks: ArcGIS for Desktop
Lab 1 Introduction to ArcGIS Feb 17, 2016
Development of a Public Notifications Tool using Python
Python – Beyond the Basics
Improving Georeferencing Workflow with Python
Geography 385 Introduction to ArcGIS Web Application Design
PYTHON: AN INTRODUCTION
Environmental GIS Nicholas A. Procopio, Ph.D, GISP
Lecture 22: Using ArcToolbox Tools in Python
Introduction to Scripting
Hazards Planning and Risk Management INTRODUCTION TO ARCGIS
Tan Hoang GEOG 362 – Final Project
Final Project: Read from a csv file and write to a database table
Hazards Planning and Risk Management INTRODUCTION TO ARCGIS
String several geoprocessing processes
Creating Geoprocessing Services
Lecture 9 Using Python for Geoprocessing
Geography 375 Introduction to Python May 15, 2015
Python I/O.
Topics Introduction to File Input and Output
Chapter 7 Files and Exceptions
Preparing raster files for Condatis
Automating and Validating Edits
Automating Analyses with ModelBuilder
Vector Geoprocessing.
Python Map Automation – Beyond the Basics of arcpy.mapping
Network Analyst – Automating Workflows with Geoprocessing
Scripting a Collector Data Export Workflow
Topics Introduction to File Input and Output
Virginia Lenvik Geography 375 Spring 2013
Midwest-bound A Site Suitability Analysis of South Bend, Indiana for Relocation by Joi Misenti Geog 375--Spring 2016.
Processing of NOAA Precipitation Data and Thematic Map Generation
Processing Well Data Points to be Used in Google Earth
Clip & Convert to ASCII Program Kelly Knapp Spring 2010
Final Project Geog 375 Daniel Hewitt.
GEO 481 Lab Geographical Information Systems Spring 2019
Ideal Parcels Locator Script
Geog 375 Individual Final Programming Project: Automated Thematic Maps
Presentation transcript:

GEOG 375 Final Project Robert Abbotts Spring 2013

Code Explanation Set Input shapefile from user input inFeatures = arcpy.GetParameterAsText(0) Set local variable to required shapefiles join_features = "//sac/GIS_Script_Shapefiles/24kquad_trim.shp" plss="//sac/GIS_Script_Shapefiles/pls_fill.shp" county="//sac/GIS_Script_Shapefiles/Counties.shp" Get input folder inputfolder = os.path.dirname(inFeatures) Check if shapefiles exist, if they are, delete them if os.path.isfile(inputfolder+"\out.shp"): arcpy.Delete_management(inputfolder+"\out.shp") if os.path.isfile(inputfolder+"\outcounty.shp"): arcpy.Delete_management(inputfolder+"\outcounty.shp") if os.path.isfile(inputfolder+"\PExport.shp"): arcpy.Delete_management(inputfolder+"\PExport.shp") Set local variables for shapefiles out_feature_class = inputfolder+"\out.shp" out_county_class = inputfolder+"\outcounty.shp" outFeatures = inputfolder+"\PExport.shp"

Code Explanation Use Spatial join geoprocessing tools to create output shapefiles arcpy.SpatialJoin_analysis(inFeatures, join_features, out_feature_class) arcpy.SpatialJoin_analysis(out_feature_class, plss,out_county_class) arcpy.SpatialJoin_analysis(out_county_class, county, outFeatures)

Code Explanation Set local variables for table fields fieldName1 = "GIS_ID" fieldLength = 16 fieldName2 = "DDLAT" fieldPrecision2 = 9 fieldName3 = "DDLON" fieldPrecision3 = 9 fieldName4 = "TEALE_X" fieldPrecision4 = 9 fieldName5 = "TEALE_Y" fieldPrecision5 = 9

Code Explanation Add GIS_ID, DDLAT, DDLON, TEALE_X, TEALE_Y fields arcpy.AddField_management(outFeatures, fieldName1, "TEXT", "", "", fieldLength) Calculate fields for update data to dispplay date, GPS date and GPS person in the table arcpy.CalculateField_management(outFeatures, fieldName1, '"%s%s%s%s" % (!Datafile![0:8], !GPS_Date![-4:-1],!GPS_Date![-1], !GPS_Person!)', "PYTHON") arcpy.AddField_management(outFeatures, fieldName2, "DOUBLE", "", "","","","NULLABLE","") arcpy.AddField_management(outFeatures, fieldName3, "DOUBLE", "", "","","","NULLABLE","") arcpy.AddField_management(outFeatures, fieldName4, "DOUBLE", "", "","","","NULLABLE","") arcpy.AddField_management(outFeatures, fieldName5, "DOUBLE", "", "","","","NULLABLE","") Add X Y fields and calculate fields for X, Y from Point_X and Point_Y arcpy.AddXY_management(outFeatures) arcpy.CalculateField_management(outFeatures, fieldName4, '!POINT_X!', "PYTHON") arcpy.CalculateField_management(outFeatures, fieldName5, '!POINT_Y!', "PYTHON")

Code Explanation Convert X Y to Lat/Lon using update cursor using for loop desc = arcpy.Describe(outFeatures) shapefieldname = desc.ShapeFieldName try: row, rows = None, None rows = arcpy.UpdateCursor(outFeatures, r'', \ r'GEOGCS["GCS_WGS_1984",' + \ 'DATUM["D_WGS_1984",' + \ 'SPHEROID["WGS_1984",6378137,298.257223563]],' + \ 'PRIMEM["Greenwich",0],' + \ 'UNIT["Degree",0.017453292519943295]]') for row in rows: feat = row.getValue(shapefieldname) pnt = feat.getPart() row.DDLat = pnt.Y row.DDLon = pnt.X rows.updateRow(row)

Code Explanation Except clause if error occurred and delete table rows and temp shapefiles except: if not arcpy.GetMessages() == "": arcpy.AddMessage(arcpy.GetMessages(2)) finally: # Regardless of whether the script succeeds or not, delete # the row and cursor # if row: del row if rows: del rows Delete fields and shapefile dropFields = ["POINT_X", "POINT_Y", "Join_Count", "TARGET_FID","Join_Cou_1","TARGET_F_1","Join_Cou_2","TARGET_F_2","AREA","PERIMETER", "DRGINDEX_","DRGINDEX_I", "OCODE", "USGS100","USGS250","CD","AREA_1","PERIMETE_1","PLSFILL_","PLSFILL_ID","X_COORD","Y_COORD","AREA_12","PERIMETE_2","COUNTY_","COUNTY_ID","Range_1","Staff"] arcpy.DeleteField_management(outFeatures, dropFields) arcpy.Delete_management(inputfolder+"\out.shp") arcpy.Delete_management(inputfolder+"\outcounty.shp") Get the map document mxd mxd = arcpy.mapping.MapDocument("CURRENT") Get the data frame df = arcpy.mapping.ListDataFrames(mxd,"*")[0] Create a new layer newlayer = arcpy.mapping.Layer(outFeatures) Add the layer to the map at the bottom of the TOC in data frame 0 arcpy.mapping.AddLayer(df, newlayer,"TOP") Refresh arcmap view, table of content arcpy.RefreshActiveView() arcpy.RefreshTOC() del mxd, df, newlayer

Output outFeatures is PExport.shp If Arcmap is open when the script is run using ArcToolbar, a temp new layer (outFeatures) will be displayed on top of table of content in ArcMap.

Summary First, the python script is to get user input shapefile from arctoolbox prompt. Second, the input shapefiles join other required shapefiles to create result output shapefile. Third, check if empty or none data fields exist in table using searchcursor function. Fourth, using add fields (add GIS_ID, DDLAT, DDLON, TEALE_X, TEALE_Y fields and calculate fields to populate the table fields with updated data using updatecursor function. Then, delete temporary shapefiles and table rows. Finally, add a new layer (outFeatures shapefile) to ArcMap on top of the table of content. And refresh the ArcMap document.