1 / 10

Geog 375 Final Project

Geog 375 Final Project. Kit Lai Spring 2013. Code Explanation. The following is to set workspace for the folder below: arcpy.env.workspace = r"C:scriptmo" Then, I check if table exists, delete the content of the table if arcpy.Exists("MO_INTERNAL_DOC.sde/MO.DOC.allminestempNAD83"):

jena
Download Presentation

Geog 375 Final Project

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Geog 375 Final Project Kit Lai Spring 2013

  2. Code Explanation The following is to set workspace for the folder below: arcpy.env.workspace = r"C:\script\mo" Then, I check if table exists, delete the content of the table if arcpy.Exists("MO_INTERNAL_DOC.sde/MO.DOC.allminestempNAD83"): arcpy.Delete_management("MO_INTERNAL_DOC.sde/MO.DOC.allminestempNAD83") Then, I get the table count result = int(arcpy.GetCount_management("MO_INTERNAL_DOC.sde/MO.doc.ALLMINES").getOutput(0)) Then, I display the table count print result

  3. Code Explanation Then, I check if table count result is greater than 0, do the following codes • if result > 0: Then, I run table to table conversion to generate ObjectID • arcpy.TableToTable_conversion("MO_INTERNAL_DOC.sde/MO.doc.ALLMINES", "C:/script/mo", "MO_INTERNAL_DOC.sde/MO.doc.allminestempNAD83") Then, I set local variables... • sourceTable = "MO_INTERNAL_DOC.sde/MO.doc.allminestempNAD83" #Internal SDE Table • problemTable = "MO_INTERNAL_DOC.sde/MO.doc.problemtable" #Internal SDE Table • sourceTableView = "MO_INTERNAL_DOC.sde/MO.doc.sourceTableView" #source table view • sourceFC = "MO_INTERNAL_DOC.sde/MO.doc.ALLMINESWGS84" #Internal Feature Class • targetFC = "MO_EXTERNAL_DOC.sde/MO.doc.ALLMINESWGS84" #External Feature Class • tempLayer ="tempLayer" Then, I make feature layer from source feature class • arcpy.MakeFeatureLayer_management(sourceFC, tempLayer) Then, I set spatial references for source and target • # uncomment the following two lines to put scripts on the server • #sourceRef = "C:/Program Files/ArcGIS/Server10.0/Coordinate Systems/Geographic Coordinate Systems/North America/NAD 1983.prj" • #projectionRef = "C:/Program Files/ArcGIS/Server10.0/Coordinate Systems/Projected Coordinate Systems/World/WGS 1984 Web Mercator (Auxiliary Sphere).prj" • #UnComment the following two lines to run on the desktop • #Source Feature class spatial references • sourceRef = "C:/Program Files/ArcGIS/Desktop10.0/Coordinate Systems/Geographic Coordinate Systems/North America/NAD 1983.prj" • #Target Feature class spatial references • projectionRef = "C:/Program Files/ArcGIS/Desktop10.0/Coordinate Systems/Projected Coordinate Systems/World/WGS 1984 Web Mercator (Auxiliary Sphere).prj"

  4. Code Explanation Then, I run make table view and make xy event layer geoprocessing to create shape from XY • # Make table view in order to create shape from lat, long • print "Making table view ... " • arcpy.MakeTableView_management(sourceTable, sourceTableView) • print "Creating shape from lat and long ..." • arcpy.MakeXYEventLayer_management(sourceTableView, "LONGITUDE", "LATITUDE", tempLayer, sourceRef) • print "Shape Created!!" • fc = tempLayer • fields = arcpy.ListFields(fc) Then, I crate a for loop through all the fields and print fields • for field in fields: • print("Field: {0}".format(field.name)) Then, I get count of number of points in source feature layer and print the count • count = arcpy.GetCount_management(tempLayer).getOutput(0) • print count

  5. Code Explanation Then, I check if temp1 feature class exists, if it exists, delete it • if arcpy.Exists("MO_INTERNAL_DOC.sde/MO.doc.temp1"): • arcpy.Delete_management("MO_INTERNAL_DOC.sde/MO.doc.temp1") Then, I copy data from feature layer to temp1 feature class • arcpy.FeatureClassToFeatureClass_conversion(tempLayer,"MO_INTERNAL_DOC.sde","temp1") • temp1="MO_INTERNAL_DOC.sde/MO.doc.temp1" Then, I use poly3 which is a polygon of California • poly3="MO_INTERNAL_DOC.sde/MO.DOC.POLYGON" • # Process: Check Select Features by Location (checking polygon) • print "Selecting points By Location ... " Then, I check if temp2 exists, if so, delete content of that table • if arcpy.Exists("MO_INTERNAL_DOC.sde/MO.doc.temp2"): • arcpy.Delete_management("MO_INTERNAL_DOC.sde/MO.doc.temp2") • temp2 ="MO_INTERNAL_DOC.sde/MO.DOC.temp2"

  6. Code Explanation Then, I intersect CA Polygon and the points feature class and get only points inside the polygon • arcpy.Intersect_analysis([temp1, poly3], temp2,"ALL","","") Then, I get the selected records count • selectedRecords = arcpy.GetCount_management(temp2).getOutput(0) Print selected record count • print selectedRecords Then, I check if templyclass exists, if so, delete content of that table • if arcpy.Exists("MO_INTERNAL_DOC.sde/MO.doc.templyclass"): • arcpy.Delete_management("MO_INTERNAL_DOC.sde/MO.doc.templyclass") • out2_lyr_class ="MO_INTERNAL_DOC.sde/MO.doc.templyclass" Then, I run erase analysis to get list of problem points outside of CA polygon • arcpy.Erase_analysis(temp1,temp2, out2_lyr_class) • out2_lyr ="out2_lyr"

  7. Code Explanation Then, I check if count of number of points in source feature layer is equal to the number of points in the selected records from intersect analysis, run project geoprocessing from NAD 83 to WGS 84 • if count == selectedRecords: • # Project from NAD 1983 to WGS 1984 • arcpy.Project_management(temp2, tempFC, projectionRef, "NAD_1983_to_WGS_1984_1") • # Copy feature class from temp2 to tempFC • arcpy.Copy_management(temp2, tempFC) Then, I check if count of number of points in source feature layer is NOT equal to the number of points in the selected records from intersect analysis, run project geoprocessing from NAD 83 to WGS 84, then male feature layer and log problem records and delete temp2 feature class • else: • print "Problem points ..." • print count #number of points in source feature layer • print selectedRecords #number of points in the selected records from intersect analysis • # Project from NAD 1983 to WGS 1984 • arcpy.Project_management(temp2, tempFC, projectionRef, "NAD_1983_to_WGS_1984_1") • # Copy feature class from temp2 to tempFC • arcpy.Copy_management(temp2, tempFC) • #Make Feature layer • arcpy.MakeFeatureLayer_management(out2_lyr_class, out2_lyr) Then, Delete temp2 • arcpy.Delete_management(temp2)

  8. Code Explanation Then, I run update geoprocessing method for the intenal feature class and repeat for external class • if arcpy.Exists(sourceFC): • arcpy.Copy_management(sourceFC, sourceFC+"_bak") • arcpy.DeleteFeatures_management(sourceFC) • print "Features in the target feature class deleted." • # Process: Append... • print "Appending features to the target feature class ..." • arcpy.Append_management(tempFC, sourceFC, "NO_TEST") • print "Finished!" • else: • print "The target feature class does not exist!" Then, I run delete management to delete temp1 and out2_lyr_class • arcpy.Delete_management(temp1) • arcpy.Delete_management(out2_lyr_class)

  9. Output • Updated SDE tables: • Internal and external tables • MO_INTERNAL_DOC.sde/MO.doc.ALLMINESWGS84" #Internal Feature Class • MO_EXTERNAL_DOC.sde/MO.doc.ALLMINESWGS84" #External Feature Class

  10. Summary • The python is to update points data - internal and external feature classes on a weekly basis for MXD and web map display. • Set up workspace, local variables and spatial references. • Import source table to become SDE table and feature class • Intersect input feature class with CA polygon to remove problem points • Reproject result feature class from NAD 83 to WGS 84 • Run update target method to update existing internal and external feature class. • Delete temporary feature classes and tables.

More Related