Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Output won't reflect updated records in Input

$
0
0
Hello all,
I am a newbie in Python and have a simple script that does a spatial join on two feature classes (inputfc1) and (inputfc2) and overwrites the output (outputfc) every time it runs. But I noticed whenever a new record is added via a web application to the inputfc1, the total record count doesn’t reflect in my gp script i.e. my output still references the former count. Say for example: When the script was first created and executed, the total records in inputfc1 was 12, subsequently a user adds a new record via the web application to inputfc1 making it 13. When I open the mxd to check the number of records in the attribute table of inputfc1, it reflects the newly added record but the output from my script doesn’t reflect this newly added record. The only way it gets the updated total is if I delete the outputfc from the output folder and re-run the script. And I know I really don’t have to always delete the outputfc since I already set the output to be overwritten. But anytime inputfc1 is updated, my outputfc doesn’t reflect any new addition in the attribute table. Any pointers on how to go about resolving this simple script will be appreciated.


Code:

# Import arcpy module
import arcpy

# Set Geoprocessing environments
arcpy.env.workspace = "C:\\Users\\morgan.stanley\\Documents\\ArcGIS\\Default.gdb"

# Overwrite the output
arcpy.env.overwriteOutput = True


# Script arguments
inputfc1 = arcpy.GetParameterAsText(0)
if inputfc1 == '#' or not inputfc1:
    inputfc1 = "inputfc1" # provide a default value if unspecified

inputfc2 = arcpy.GetParameterAsText(1)
if inputfc2 == '#' or not inputfc2:
    inputfc2 = "inputfc2" # provide a default value if unspecified

outputfc = arcpy.GetParameterAsText(2)
if outputfc == '#' or not outputfc:
    outputfc = "C:\\Users\\morgan.stanley\\Documents\\ArcGIS\\Default.gdb\\outputfc" # provide a default value if unspecified

# Local variables:

# Process: Spatial Join
arcpy.SpatialJoin_analysis(inputfc1, inputfc2, outputfc, "JOIN_ONE_TO_ONE", "KEEP_ALL", "Status \"Status\" true true false 1 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,Status,-1,-1;Score \"Score\" true true false 8 Double 2 20 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,Score,-1,-1;Match_type \"Match_type\" true true false 2 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,Match_type,-1,-1;Match_addr \"Match_addr\" true true false 120 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,Match_addr,-1,-1;Side \"Side\" true true false 1 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,Side,-1,-1;Ref_ID \"Ref_ID\" true true false 8 Double 8 38 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,Ref_ID,-1,-1;X \"X\" true true false 8 Double 6 24 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,X,-1,-1;Y \"Y\" true true false 8 Double 6 24 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,Y,-1,-1;Street_ID \"Street_ID\" true true false 120 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,Street_ID,-1,-1;User_fld \"User_fld\" true true false 120 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,User_fld,-1,-1;Addr_type \"Addr_type\" true true false 20 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,Addr_type,-1,-1;ARC_Street \"ARC_Street\" true true false 100 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,ARC_Street,-1,-1;ARC_City \"ARC_City\" true true false 40 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,ARC_City,-1,-1;ARC_State \"ARC_State\" true true false 20 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,ARC_State,-1,-1;ARC_ZIP \"ARC_ZIP\" true true false 10 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,ARC_ZIP,-1,-1;housing_id \"housing_id\" true false false 12 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,housing_id,-1,-1;street \"street\" true true false 254 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,street,-1,-1;city \"city\" true true false 254 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,city,-1,-1;zip \"zip\" true true false 5 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,zip,-1,-1;inspection \"inspection\" true true false 36 Date 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,inspection,-1,-1;passedStat \"passedStat\" true true false 254 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,passedStat,-1,-1;completeDa \"completeDa\" true true false 36 Date 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,completeDa,-1,-1;project_id \"project_id\" true true false 9 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,project_id,-1,-1;year \"year\" true true false 4 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,year,-1,-1;secondaryProject_id \"secondaryProject_id\" true true false 9 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\TEST_GDB.GISADMIN.HCD_BIApplication\\TEST_GDB.GISADMIN.HCD_inputfc1Housing,secondaryProject_id,-1,-1;SUPER \"SUPER\" true true false 2 Short 0 5 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\Test_GDB.GISADMIN.COM_Political_inputfc2District,SUPER,-1,-1;COM_GDB_SDE_COM_Political_Sup_3 \"area\" true true false 8 Double 8 38 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\Test_GDB.GISADMIN.COM_Political_inputfc2District,COM_GDB_SDE_COM_Political_Sup_3,-1,-1;COM_GDB_SDE_COM_Political_Sup_4 \"len\" true true false 8 Double 8 38 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\Test_GDB.GISADMIN.COM_Political_inputfc2District,COM_GDB_SDE_COM_Political_Sup_4,-1,-1;GlobalID \"GlobalID\" false false true 38 GlobalID 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\Test_GDB.GISADMIN.COM_Political_inputfc2District,GlobalID,-1,-1;DistrictMembers \"DistrictMembers\" true true false 75 Text 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\Test_GDB.GISADMIN.COM_Political_inputfc2District,DistrictMembers,-1,-1;Shape_area \"Shape_area\" false false true 0 Double 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\Test_GDB.GISADMIN.COM_Political_inputfc2District,Shape.area,-1,-1;Shape_len \"Shape_len\" false false true 0 Double 0 0 ,First,#,Database Connections\\Test_GDB_SQL2008.sde\\Test_GDB.GISADMIN.COM_Political_inputfc2District,Shape.len,-1,-1", "WITHIN", "", "")

# Update Row - I was just trying to see if the search cursor will help
rows = arcpy.SearchCursor("outputfc")
row = rows.next()

recordsCounted = 0

while row:
    recordsCounted += 1
    row = rows.next()

print "Total Records in inputfc1 is " + str(recordsCounted)


Viewing all articles
Browse latest Browse all 2485

Trending Articles