コード例 #1
0
def runScript(log,config):
    try:

        # Config File
        username = config.get( 'AGOL', 'USER')
        password = config.get('AGOL', 'PASS')
        joinData = config.get('LOCAL_DATA', 'JOINDATA')
        joinDataJoinField = config.get('LOCAL_DATA', 'JOINDATAJOINFIELD')
        inputData = config.get('LOCAL_DATA', 'INPUTDATA')
        inputJoinField = config.get('LOCAL_DATA', 'INPUTJOINFIELD')
        copyFields = eval(config.get('LOCAL_DATA', 'COPYFIELDS'))
        prevFields =eval(config.get('LOCAL_DATA', 'PREVIOUSFIELDS'))
        createCurrent = config.get('LOCAL_DATA', 'CREATECURRENT')
        reportArchiveURL = config.get('FS_INFO', 'REPORTARCHIVEURL')
        reportCurrentURL = config.get('FS_INFO', 'REPORTCURRENTURL')
        deleteSQL = config.get('FS_INFO', 'DELETESQL')

        print "Config file loaded"

        if arcpy.Exists(joinData) == False:
            print "Join Data Does Not Exist, exiting"
            sys.exit()

        if arcpy.Exists(inputData) == False:
            print "Input Data Does Not Exist, exiting"
            sys.exit()

        fs = services.FeatureService(url=reportArchiveURL,username=username,password=password)
        if fs == None:
            print "Cannot find Archive Service, exiting"
            sys.exit()

        Utilities.currentToPrevious(inputData,prevFields)
        print "Existing data moved to previous fields"

        Utilities.JoinAndCalc(inputData,inputJoinField,joinData,joinDataJoinField,copyFields)
        print "Data joined and calculated"

        #Save results to historical service
        fs.addFeatures(inputData)
        print "Historical data updated"

        #Update Current service if used
        if createCurrent == "True":
            fs.url = reportCurrentURL
            fs.deleteFeatures(deleteSQL)
            print "Current service reset"
            fs.addFeatures(inputData)
            print "Current service updated"



    except FeatureServiceError,e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
コード例 #2
0
def runScript(log,config):
    try:

        # Config File
        username = config.get( 'AGOL', 'USER')
        password = config.get('AGOL', 'PASS')
        inputData = config.get('LOCAL_DATA', 'INPUTDATA')
        createCurrent = config.get('LOCAL_DATA', 'CREATECURRENT')
        reportCurrentURL = config.get('FS_INFO', 'REPORTCURRENTURL')
        deleteSQL = config.get('FS_INFO', 'DELETESQL')

        print "Config file loaded"

        if arcpy.Exists(inputData) == False:
            print "Input Data Does Not Exist, exiting"
            sys.exit()

        #Update Current service if used
        if createCurrent == "True":
            fs.url = reportCurrentURL
            fs.deleteFeatures(deleteSQL)
            print "Current service reset"
            fs.addFeatures(inputData)
            print "Current service updated"

    except FeatureServiceError,e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
コード例 #3
0
def runScript(log,config):
    try:


        # Config File
        username = config.get( 'AGOL', 'USER')
        password = config.get('AGOL', 'PASS')

        serviceInfo = eval(config.get('FS_INFO', 'SERVICEINFO'))

        print "Config file loaded"
        fs = services.FeatureService(url="",username=username,password=password)

        for serItm in serviceInfo:
            fs.url = serItm[0]
            fs.deleteFeatures(serItm[1])
            print "Delete Complete: "  + serItm[0]


    except FeatureServiceError,e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
コード例 #4
0
def runScript(log, config):
    try:

        # Config File
        username = config.get('AGOL', 'USER')
        password = config.get('AGOL', 'PASS')
        inputData = config.get('LOCAL_DATA', 'INPUTDATA')
        createCurrent = config.get('LOCAL_DATA', 'CREATECURRENT')
        reportCurrentURL = config.get('FS_INFO', 'REPORTCURRENTURL')
        deleteSQL = config.get('FS_INFO', 'DELETESQL')

        print "Config file loaded"

        if arcpy.Exists(inputData) == False:
            print "Input Data Does Not Exist, exiting"
            sys.exit()

        #Update Current service if used
        if createCurrent == "True":
            fs.url = reportCurrentURL
            fs.deleteFeatures(deleteSQL)
            print "Current service reset"
            fs.addFeatures(inputData)
            print "Current service updated"

    except FeatureServiceError, e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
コード例 #5
0
def runScript(log, config):
    try:

        # Config File
        username = config.get('AGOL', 'USER')
        password = config.get('AGOL', 'PASS')

        serviceInfo = eval(config.get('FS_INFO', 'SERVICEINFO'))

        print "Config file loaded"
        fs = services.FeatureService(url="",
                                     username=username,
                                     password=password)

        for serItm in serviceInfo:
            fs.url = serItm[0]
            fs.deleteFeatures(serItm[1])
            print "Delete Complete: " + serItm[0]

    except FeatureServiceError, e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
コード例 #6
0
def runScript(log,config):
    try:

        exampleConfigValue = config.get('SAMPLE', 'SETTING')
        print exampleConfigValue

    except FeatureServiceError,e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
コード例 #7
0
def runScript(log,config):
    try:


        # Config File
        username = config.get( 'AGOL', 'USER')
        password = config.get('AGOL', 'PASS')

        serviceUrl = config.get('FS_INFO', 'SERVICEURL')

        print "Config file loaded"
        fs = services.FeatureService(url=serviceUrl,username=username,password=password)
        fs.extractDataUsingSync(r"c:\temp\AttachmentTest\AttachmentTest.gdb", "grid", "attachments", attachment_folder=r"c:\temp\AttachmentTest")


    except FeatureServiceError,e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
コード例 #8
0
            fs.url = reportCurrentURL
            fs.deleteFeatures(deleteSQL)
            print "Current service reset"
            fs.addFeatures(inputData)
            print "Current service updated"

    except FeatureServiceError,e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    except UtilitiesError, e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    except arcpy.ExecuteError:

        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "ArcPy Error Message: %s" % arcpy.GetMessages(2)
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
コード例 #9
0
def runScript(log,config):
    try:

        exampleConfigValue = config.get('SAMPLE', 'SETTING')
        print exampleConfigValue

    except FeatureServiceError,e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    except UtilitiesError, e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    except arcpy.ExecuteError:

        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "ArcPy Error Message: %s" % arcpy.GetMessages(2)
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
コード例 #10
0
def runScript(log,config):
    try:

        username = config.get( 'AGOL', 'USER')
        password = config.get('AGOL', 'PASS')



        outageURL = config.get('FS_INFO', 'OUTAGESERVICE')
        outageDelSQL = config.get('FS_INFO', 'OUTAGEDELETESQL')


        outageAreaLayer = config.get('LOCAL_DATA', 'OUTAGELAYER')
        outageAreaCustOutField = config.get('LOCAL_DATA', 'CUSTOMERSOUTFIELD')
        outageAreaCustInField = config.get('LOCAL_DATA', 'CUSTOMERSINFIELD')
        outageAreaTotCustField = config.get('LOCAL_DATA', 'TOTALCUSTOMERSFIELD')
        outageAreaPercOutField = config.get('LOCAL_DATA', 'PERCENTOUTFIELD')
        outageAreaRptDate = eval(config.get('LOCAL_DATA', 'DATEFIELD'))

        eventLayer = config.get('LOCAL_DATA', 'EVENTSLAYER')

        print "Config file loaded"

        # Local variables:
        outageAreaJoinedToEvents = 'in_memory\AreaJoinedWithOutage'##'%scratchgdb%\AreaJoinedWithOutage'

        if arcpy.Exists(outageAreaLayer) == False:
            print "Join Data Does Not Exist, exiting"
            sys.exit()

        if arcpy.Exists(eventLayer) == False:
            print "Input Data Does Not Exist, exiting"
            sys.exit()

        # Process: Spatial Join


        arcpy.SpatialJoin_analysis(outageAreaLayer, eventLayer, outageAreaJoinedToEvents, 'JOIN_ONE_TO_ONE', 'KEEP_ALL',"","INTERSECT","#","#")
        print "Spatial Join Complete"

        #Join the spatial join to the source data and copy the customer count information
        Utilities.JoinAndCalc(outageAreaLayer,"OBJECTID",outageAreaJoinedToEvents,"TARGET_FID",[("Join_Count",outageAreaCustOutField)])

        print "Outage Counts Calculated"

        if Utilities.FieldExist(outageAreaLayer,[outageAreaCustInField,outageAreaTotCustField]):
            # Process: Calc Number In
            arcpy.CalculateField_management(outageAreaLayer, outageAreaCustInField, "!" + outageAreaTotCustField +"!- !" + outageAreaCustOutField + "!", "PYTHON_9.3", "")
            print "Number of people in service calculated"

        if Utilities.FieldExist(outageAreaLayer,[outageAreaCustInField,outageAreaTotCustField,outageAreaPercOutField]):

            # Process: Calc Percent Out
            arcpy.CalculateField_management(outageAreaLayer, outageAreaPercOutField, "calc( !" + outageAreaCustOutField +"!, !" + outageAreaTotCustField +"! )", "PYTHON_9.3", "def calc(numout,numserv):\\n  if numout == 0:\\n    return 0\\n  else:\\n    return round(float((float(numout) / float(numserv)) *100),2)")
            print "Percentage out calculated"

        if Utilities.FieldExist(outageAreaLayer,[outageAreaRptDate[0]]):
            # Process: Set Time
            tz = time.timezone
            dateExp = "import time\\nimport datetime\\nfrom time import mktime\\nfrom datetime import datetime\\ndef calc(dt):\\n  return datetime.fromtimestamp(mktime(time.strptime(str(dt), '" + str(outageAreaRptDate[1]) + "')) + " + str(tz) + ")"
            exp =  "calc('" + datetime.datetime.now().strftime(str(outageAreaRptDate[1])) + "')"
            arcpy.CalculateField_management(outageAreaLayer,outageAreaRptDate[0], exp, "PYTHON_9.3", dateExp)
            print "Report time set"


        fs = services.FeatureService(url=outageURL,
                        username=username,
                        password=password)

        fs.deleteFeatures(outageDelSQL)
        print "Outage Polygon layer cleared"

        results = fs.addFeatures(fc=outageAreaLayer)
        print "Outage Polygon layer features added"


    except FeatureServiceError,e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
コード例 #11
0
            fs.url = reportCurrentURL
            fs.deleteFeatures(deleteSQL)
            print "Current service reset"
            fs.addFeatures(inputData)
            print "Current service updated"

    except FeatureServiceError, e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    except UtilitiesError, e:
        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "Add. Error Message: %s" % e
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")

    except arcpy.ExecuteError:

        line, filename, synerror = Utilities.trace()
        print "error on line: %s" % line
        print "error in file name: %s" % filename
        print "with error message: %s" % synerror
        print "ArcPy Error Message: %s" % arcpy.GetMessages(2)
        print datetime.datetime.now().strftime("%Y-%m-%d %H:%M")