Beispiel #1
0
def PipeDepthCheck(errtype,inDB1,inDB2,outDB,logDB):

    #inDB1 is Pipe
    #inDB2 is Node

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1,"tempview")
    view2 = arcpy.MakeTableView_management(inDB2,"tempview2")

    joinres = arcpy.AddJoin_management(view,[x.name for x in arcpy.ListFields(view) if "UpstreamNodeID" in x.name][0],view2,[x.name for x in arcpy.ListFields(view2) if "ObjectID" in x.name][0],"KEEP_COMMON")

    fields = [x.name for x in arcpy.ListFields(joinres) if "ObjectID" in x.name or "InvertLevel" in x.name or "GroundLevel" in x.name]
#[u'GIS_VCS_DD_TEST.DANDAS.WW_Pipe.ObjectID', u'GIS_VCS_DD_TEST.DANDAS.WW_Pipe.UpstreamInvertLevel', u'GIS_VCS_DD_TEST.DANDAS.WW_Pipe.DownstreamInvertLevel', u'GIS_VCS_DD_TEST.DANDAS.WW_Node.ObjectID', u'GIS_VCS_DD_TEST.DANDAS.WW_Node.InvertLevel', u'GIS_VCS_DD_TEST.DANDAS.WW_Node.InvertLevelOriginID', u'GIS_VCS_DD_TEST.DANDAS.WW_Node.GroundLevel', u'GIS_VCS_DD_TEST.DANDAS.WW_Node.GroundLevelOriginID']

    cursorS = arcpy.da.SearchCursor(joinres,fields)

    cursorI = arcpy.da.InsertCursor(outDB,[x.name for x in arcpy.ListFields(outDB)[1:]])

    #UpstreamDict = {}
    for row in cursorS:
        if (isinstance(row[1],float) or isinstance(row[1],int)) and (isinstance(row[4],float) or isinstance(row[4],int) ) and (isinstance(row[6],float) or isinstance(row[6],int) ):
            if row[1] < row[4] or row[1] > row[6]:
                cursorI.insertRow(["Join with Node","Pipe","Upstream",globalScriptSettings.getErrID(),row[0],row[3],row[6],row[1],row[4]])
                errcount += 1
        else:
            cursorI.insertRow(["Join with Node","Pipe","Upstream",globalScriptSettings.getErrID(),row[0],row[3],row[6],row[1],row[4]])
            errcount += 1

    arcpy.RemoveJoin_management(joinres)
    del cursorS

    joinres2 = arcpy.AddJoin_management(view,[x.name for x in arcpy.ListFields(view) if "DownstreamNodeID" in x.name][0],view2,[x.name for x in arcpy.ListFields(view2) if "ObjectID" in x.name][0],"KEEP_COMMON")

    cursorSearch = arcpy.da.SearchCursor(joinres2,fields)

    #caughtlist = set()
    for row in cursorSearch:
        if (isinstance(row[2],float) or isinstance(row[2],int)) and (isinstance(row[4],float) or isinstance(row[4],int) ) and (isinstance(row[6],float) or isinstance(row[6],int) ):
            if row[2] < row[4] or row[2] > row[6]:
                cursorI.insertRow(["Join with Node","Pipe","Downstream",globalScriptSettings.getErrID(),row[0],row[3],row[6],row[2],row[4]])
                errcount += 1
        else:
            cursorI.insertRow(["Join with Node","Pipe","Downstream",globalScriptSettings.getErrID(),row[0],row[3],row[6],row[2],row[4]])
            errcount += 1

    logcursorI = arcpy.da.InsertCursor(logDB,[x.name for x in arcpy.ListFields(logDB)[1:]])

    del cursorSearch
    arcpy.RemoveJoin_management(joinres2)
    arcpy.Delete_management(view)
    arcpy.Delete_management(view2)
    del cursorI
    logcursorI.insertRow([dateofrun,errtype,errcount,globalScriptSettings.getRunCount()])
    del logcursorI

    returnValue = errcount
    return returnValue
Beispiel #2
0
def NamelenTest(errtype, inDB, outDB, logDB):

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    cursorS = arcpy.da.SearchCursor(
        inDB, "*", "len(" + arcpy.ListFields(inDB)[1].name + ") > 30")
    cursorI = arcpy.da.InsertCursor(
        outDB, [x.name for x in arcpy.ListFields(outDB)[1:]])
    logcursorI = arcpy.da.InsertCursor(
        logDB, [x.name for x in arcpy.ListFields(logDB)[1:]])
    for row in cursorS:
        cursorI.insertRow([
            "len(name)", "Knude", "",
            globalScriptSettings.getErrID(), row[0], row[1]
        ])
        errcount += 1
    del cursorI
    del cursorS
    logcursorI.insertRow(
        [dateofrun, errtype, errcount,
         globalScriptSettings.getRunCount()])
    del logcursorI

    returnValue = errcount
    return returnValue
Beispiel #3
0
def LateralRefrence(errtype,inDB1,inDB2,outDB,logDB):

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1,"tempview","NOT MainPipeID IS NULL")
    view2 = arcpy.MakeTableView_management(inDB2,"tempview2")

    joinres = arcpy.AddJoin_management(view,"MainPipeID",view2,"ObjectID","KEEP_ALL")

    joinfields = [x.name for x in arcpy.ListFields(joinres) if "ObjectID" in x.name or "MainPipeID" in x.name]

    cursorSwhere = arcpy.da.SearchCursor(joinres,joinfields,[x.name for x in arcpy.ListFields(joinres) if "MainPipe.ObjectID" in x.name][0] + " IS NULL")

    cursorI = arcpy.da.InsertCursor(outDB,[x.name for x in arcpy.ListFields(outDB)[1:]])

    logcursorI = arcpy.da.InsertCursor(logDB,[x.name for x in arcpy.ListFields(logDB)[1:]])

    for row in cursorSwhere:
        cursorI.insertRow(["Join on RefrenceID","LateralConnection","",globalScriptSettings.getErrID(),row[0],row[1]])
        errcount += 1
    del cursorI
    del cursorSwhere
    logcursorI.insertRow([dateofrun,errtype,errcount,globalScriptSettings.getRunCount()])
    del logcursorI
    arcpy.RemoveJoin_management(joinres)
    arcpy.Delete_management(view)
    arcpy.Delete_management(view2)

    returnValue = errcount
    return returnValue
Beispiel #4
0
def ClosenesCheck(errtype,inDB1,outDB,logDB):

    #inDB1 is Node

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1,"tempview")

    fields = [x.name for x in arcpy.ListFields(view) if "ObjectID" in x.name or "NodeTypeCode" in x.name]
    fields.append("SHAPE@XY")
    #[u'ObjectID', u'NodeTypeCode', 'SHAPE@XY']

    closenesDictX = {}

    cursorS = arcpy.da.SearchCursor(view,fields)

    for (ID,typecode,(X,Y)) in cursorS:
        coordkey = ((round(X,2),round(Y,2)))

        if closenesDictX.has_key(coordkey):
            coordlist = closenesDictX.pop(coordkey)
            coordlist.append((ID,typecode,coordkey))
            closenesDictX[coordkey] = coordlist
        else:
            closenesDictX[coordkey] = [(ID,typecode,coordkey)]

    cursorS.reset()

    cursorI = arcpy.da.InsertCursor(outDB,[x.name for x in arcpy.ListFields(outDB)[1:]])
    logcursorI = arcpy.da.InsertCursor(logDB,[x.name for x in arcpy.ListFields(logDB)[1:]])

    caughtlist = set()
    for (ID,typecode,(X,Y)) in cursorS:
        coordkey = ((round(X,2),round(Y,2)))
        for i in range(5):
            for j in range(5):
                Xcoordround = round(round(X,2)-0.02+i*0.01,2)
                Ycoordround = round(round(Y,2)-0.02+j*0.01,2)
                if closenesDictX.has_key((Xcoordround,Ycoordround)):
                    closelist = closenesDictX.get((Xcoordround,Ycoordround))
                    for (IDclose,typecodeclose,(Xclose,Yclose)) in closelist:
                        distance = math.sqrt(pow(round(X,2)-Xclose,2)+pow(round(Y,2)-Yclose,2))
                        if distance <= 0.02 and ID != IDclose and (ID,IDclose) not in caughtlist:
                            caughtlist.add((IDclose,ID))
                            cursorI.insertRow(["","Node","",globalScriptSettings.getErrID(),ID,typecode,IDclose,typecodeclose])
                            errcount += 1

    del cursorS
    arcpy.Delete_management(view)
    del cursorI
    logcursorI.insertRow([dateofrun,errtype,errcount,globalScriptSettings.getRunCount()])
    del logcursorI

    returnValue = errcount
    return returnValue
def TVCCInRefrence(errtype, inDB1, inDB2, inDB3, outDB, logDB):

    #inDB1 is TVCCInspection
    #inDB2 is Report
    #inDB3 is PipeReport

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1, "tempview")
    view2 = arcpy.MakeTableView_management(inDB2, "tempview2")
    view3 = arcpy.MakeTableView_management(inDB3, "tempview3")

    joinres = arcpy.AddJoin_management(view, "ReportID", view2, "ObjectID",
                                       "KEEP_ALL")
    joinres2 = arcpy.AddJoin_management(joinres, [
        x.name for x in arcpy.ListFields(joinres)
        if "Report.ObjectID" in x.name
    ][0], view3, "ReportID", "KEEP_ALL")

    joinfields = [
        x.name for x in arcpy.ListFields(joinres2)
        if "ObjectID" in x.name or "InActive" in x.name
    ]
    #[u'GIS_VCS_DD_TEST.DANDAS.WW_CCTVInspection.ObjectID', u'GIS_VCS_DD_TEST.DANDAS.WW_CCTVInspection.InActive', u'GIS_VCS_DD_TEST.DANDAS.WW_Report.ObjectID', u'GIS_VCS_DD_TEST.DANDAS.WW_PipeReport.ObjectID']

    cursorSwhere = arcpy.da.SearchCursor(joinres2, joinfields, [
        x.name
        for x in arcpy.ListFields(joinres2) if "PipeReport.ObjectID" in x.name
    ][0] + " IS NULL")

    cursorI = arcpy.da.InsertCursor(
        outDB, [x.name for x in arcpy.ListFields(outDB)[1:]])

    logcursorI = arcpy.da.InsertCursor(
        logDB, [x.name for x in arcpy.ListFields(logDB)[1:]])

    for row in cursorSwhere:
        cursorI.insertRow([
            "Join with Report and PipeReport", "TVCCInspection", "",
            globalScriptSettings.getErrID(), row[0], row[1]
        ])
        errcount += 1
    del cursorI
    del cursorSwhere
    logcursorI.insertRow(
        [dateofrun, errtype, errcount,
         globalScriptSettings.getRunCount()])
    del logcursorI
    arcpy.RemoveJoin_management(joinres2)
    arcpy.Delete_management(view)
    arcpy.Delete_management(view2)
    arcpy.Delete_management(view3)

    returnValue = errcount
    return returnValue
Beispiel #6
0
def InvalidCover(errtype, inDB1, inDB2, outDB, logDB):

    #inDB1 is Cover
    #inDB2 is Node

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1, "tempview")
    view2 = arcpy.MakeTableView_management(inDB2, "tempview2")

    joinres = arcpy.AddJoin_management(view, "NodeID", view2, "ObjectID",
                                       "KEEP_COMMON")

    joinfields = [
        x.name for x in arcpy.ListFields(joinres)
        if "ObjectID" in x.name or "NodeTypeCode" in x.name
    ]
    #[u'GIS_VCS_DD_TEST.DANDAS.WW_Cover.ObjectID', u'GIS_VCS_DD_TEST.DANDAS.WW_Node.ObjectID', u'GIS_VCS_DD_TEST.DANDAS.WW_Node.NodeTypeCode']

    cursorSwhere = arcpy.da.SearchCursor(
        joinres, joinfields, "NOT " + [
            x.name
            for x in arcpy.ListFields(joinres) if "Node.ObjectID" in x.name
        ][0] + " IS NULL")

    cursorI = arcpy.da.InsertCursor(
        outDB, [x.name for x in arcpy.ListFields(outDB)[1:]])

    logcursorI = arcpy.da.InsertCursor(
        logDB, [x.name for x in arcpy.ListFields(logDB)[1:]])

    for row in cursorSwhere:
        if row[2] != 1 and row[2] != 4 and row[2] != 7 and row[2] != 8 and row[
                2] != 9 and row[2] != 10 and row[2] != 11 and row[2] != 12:
            cursorI.insertRow([
                "Join with Node", "Cover", "",
                globalScriptSettings.getErrID(), row[0], row[1], row[2]
            ])
            errcount += 1
    del cursorI
    del cursorSwhere
    logcursorI.insertRow(
        [dateofrun, errtype, errcount,
         globalScriptSettings.getRunCount()])
    del logcursorI
    arcpy.RemoveJoin_management(joinres)
    arcpy.Delete_management(view)
    arcpy.Delete_management(view2)

    returnValue = errcount
    return returnValue
Beispiel #7
0
def Ownercheck(errtype, inDB1, inDB2, outDB, logDB):

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    ownerandcode = []

    fields = [
        x.name for x in arcpy.ListFields(inDB1)
        if "ObjectID" in x.name or "OwnerID" in x.name or "OwnerCode" in x.name
    ]

    cursorS = arcpy.da.SearchCursor(inDB2, [
        x.name for x in arcpy.ListFields(inDB2)
        if "ObjectID" in x.name or "OwnerCode" in x.name
    ])

    for row in cursorS:
        ownerandcode.append((row[0], row[1]))

    del cursorS

    #ownerandcode = ownerandcode + [(y,x) for (x,y) in ownerandcode]

    cursorS = arcpy.da.SearchCursor(inDB1, fields)

    cursorI = arcpy.da.InsertCursor(
        outDB, [x.name for x in arcpy.ListFields(outDB)[1:]])

    logcursorI = arcpy.da.InsertCursor(
        logDB, [x.name for x in arcpy.ListFields(logDB)[1:]])

    for row in cursorS:
        #if (row[2],row[3]) in ownerandcode and (row[3],row[2]) in ownerandcode:
        if (row[2], row[3]) in ownerandcode:
            pass
        else:
            cursorI.insertRow([
                "Comparing with Ejer", "MainPipe", "",
                globalScriptSettings.getErrID(), row[0], row[2], row[3]
            ])
            errcount += 1

    del cursorI
    del cursorS
    logcursorI.insertRow(
        [dateofrun, errtype, errcount,
         globalScriptSettings.getRunCount()])
    del logcursorI

    returnValue = errcount
    return returnValue
def MainPipePipes(errtype,inDB1,inDB2,outDB,logDB):

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    #view = arcpy.MakeTableView_management(inDB1,"tempview")
    #view2 = arcpy.MakeTableView_management(inDB2,"tempview2")
    #FT2 = arcpy.MakeFeatureLayer_management(inDB2,"tempFL")

    #joinres = arcpy.AddJoin_management(view,"ObjectID",FT2,"MainPipeID","KEEP_ALL")

    #view2 loses all its entries when joining for some reason
    #joinfields = [x.name for x in arcpy.ListFields(joinres) if "ObjectID" in x.name or "NodeID" in x.name]

    pipesaccountedfor = []

    fields = [x.name for x in arcpy.ListFields(inDB1) if "ObjectID" in x.name or "NodeID" in x.name]

    cursorS = arcpy.da.SearchCursor(inDB2,["MainPipeID"],"NOT MainPipeID IS NULL")

    for row in cursorS:
        pipesaccountedfor.append(row[0])

    del cursorS

    setpipesaccountedfor = set(pipesaccountedfor)

    cursorS = arcpy.da.SearchCursor(inDB1,fields)

    cursorI = arcpy.da.InsertCursor(outDB,[x.name for x in arcpy.ListFields(outDB)[1:]])

    logcursorI = arcpy.da.InsertCursor(logDB,[x.name for x in arcpy.ListFields(logDB)[1:]])

    for row in cursorS:
        if row[0] in setpipesaccountedfor:
            pass
        else:
            cursorI.insertRow(["Loop over Delledning","MainPipe","",globalScriptSettings.getErrID(),row[0],row[1],row[2]])
            errcount += 1
    del cursorI
    del cursorS
    logcursorI.insertRow([dateofrun,errtype,errcount,globalScriptSettings.getRunCount()])
    del logcursorI
    #arcpy.RemoveJoin_management(joinres)
    #arcpy.Delete_management(view)
    #arcpy.Delete_management(view2)

    returnValue = errcount
    return returnValue
def NodeMulCover(errtype, inDB, outDB, logDB):

    #find NodeIDs from Cover with multiple occourences, can find both covers and nodes from NodeIDs

    returnValue = 0
    errcount = 0
    uniqueList = []
    duplicateList = []
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB, "tempview",
                                          "NOT NodeID IS NULL")

    cursorS = arcpy.da.SearchCursor(
        view, [x.name for x in arcpy.ListFields(inDB)[:2]])

    for row in cursorS:
        if row[1] in uniqueList:
            duplicateList.append(row[1])
        else:
            uniqueList.append(row[1])

    setduplicateList = set(duplicateList)

    cursorS.reset()

    cursorI = arcpy.da.InsertCursor(
        outDB, [x.name for x in arcpy.ListFields(outDB)[1:]])

    logcursorI = arcpy.da.InsertCursor(
        logDB, [x.name for x in arcpy.ListFields(logDB)[1:]])

    for row in cursorS:
        if row[1] in setduplicateList:
            cursorI.insertRow([
                "Found duplicate NodeID", "Cover", "",
                globalScriptSettings.getErrID(), row[0], row[1]
            ])
            errcount += 1
    del cursorI
    del cursorS
    logcursorI.insertRow(
        [dateofrun, errtype, errcount,
         globalScriptSettings.getRunCount()])
    del logcursorI
    arcpy.Delete_management(view)

    returnValue = errcount
    return returnValue
def CoordinateCheck(errtype, inDB1, inDB2, outDB, logDB):

    #inDB1 is pipe
    #inDB2 is Node

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1, "tempview")

    fields = [
        x.name for x in arcpy.ListFields(inDB1)
        if "ObjectID" in x.name or "PipeID" in x.name or "NodeID" in x.name
        or "XCoordinate" in x.name or "YCoordinate" in x.name
    ]
    fields.append("SHAPE@")

    cursorS = arcpy.da.SearchCursor(view, fields)

    #[u'ObjectID', u'MainPipeID', u'UpstreamNodeID', u'DownstreamNodeID', 'SHAPE@']

    # NodeID : [(pipeID,firstX,firstY,lastX,lastY)..] from pipe
    nodeDict = {}
    for row in cursorS:
        firstcord = row[4].firstPoint
        lastcord = row[4].lastPoint
        if nodeDict.has_key(row[2]):
            nodeList = nodeDict.pop(row[2])
            nodeList.append((row[0], round(firstcord.X,
                                           4), round(firstcord.Y, 4),
                             round(lastcord.X, 4), round(lastcord.Y, 4)))
            nodeDict[row[2]] = nodeList
        else:
            nodeDict[row[2]] = [(row[0], round(firstcord.X,
                                               4), round(firstcord.Y, 4),
                                 round(lastcord.X, 4), round(lastcord.Y, 4))]

        if nodeDict.has_key(row[3]):
            nodeList = nodeDict.pop(row[3])
            nodeList.append((row[0], round(firstcord.X,
                                           4), round(firstcord.Y, 4),
                             round(lastcord.X, 4), round(lastcord.Y, 4)))
            nodeDict[row[3]] = nodeList
        else:
            nodeDict[row[3]] = [(row[0], round(firstcord.X,
                                               4), round(firstcord.Y, 4),
                                 round(lastcord.X, 4), round(lastcord.Y, 4))]

    del cursorS
    arcpy.Delete_management(view)

    view2 = arcpy.MakeTableView_management(inDB2, "tempview2")

    Sfields = [
        x.name for x in arcpy.ListFields(inDB2) if "ObjectID" in x.name
        or "XCoordinate" in x.name or "YCoordinate" in x.name
    ]
    Sfields.append("SHAPE@XY")

    #[u'ObjectID', u'XCoordinate', u'YCoordinate', 'SHAPE@XY']

    cursorS = arcpy.da.SearchCursor(view2, Sfields)

    cursorI = arcpy.da.InsertCursor(
        outDB, [x.name for x in arcpy.ListFields(outDB)[1:]])

    logcursorI = arcpy.da.InsertCursor(
        logDB, [x.name for x in arcpy.ListFields(logDB)[1:]])

    # pipeID : (X,Y)  already spent point
    pipeDict = {}
    for row in cursorS:

        nodeList = nodeDict.pop(row[0], [])
        for (ID, firstXcoord, firstYcoord, lastXcoord, lastYcoord) in nodeList:

            distance1 = abs(
                math.sqrt(
                    round(
                        math.pow(row[3][0] - firstXcoord, 2) +
                        math.pow(row[3][1] - firstYcoord, 2), 4)))
            distance2 = abs(
                math.sqrt(
                    round(
                        math.pow(row[3][0] - lastXcoord, 2) +
                        math.pow(row[3][1] - lastYcoord, 2), 4)))

            if distance1 < distance2:
                if distance1 > 0.002 and (
                        firstXcoord, firstYcoord) != pipeDict.get(ID, (0, 0)):
                    pipeDict[ID] = (firstXcoord, firstYcoord)
                    cursorI.insertRow([
                        "Node Shapefile X and Y coordinates", "Pipe", "",
                        globalScriptSettings.getErrID(), ID, row[0],
                        float(distance1)
                    ])
                    errcount += 1

            else:
                if distance2 > 0.002 and (
                        lastXcoord, lastYcoord) != pipeDict.get(ID, (0, 0)):
                    pipeDict[ID] = (lastXcoord, lastYcoord)
                    cursorI.insertRow([
                        "Node Shapefile X and Y coordinates", "Pipe", "",
                        globalScriptSettings.getErrID(), ID, row[0],
                        float(distance2)
                    ])
                    errcount += 1

    del cursorI
    del cursorS
    logcursorI.insertRow(
        [dateofrun, errtype, errcount,
         globalScriptSettings.getRunCount()])
    del logcursorI
    arcpy.Delete_management(view2)

    returnValue = errcount
    return returnValue
def CoordinateCheck(errtype, inDB1, inDB2, outDB, logDB):

    #inDB1 is Cover
    #inDB2 is Node

    returnValue = 0
    errcount = 0
    coverDict = {}
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1, "tempview",
                                          "NOT NodeID IS NULL")

    fields = [
        x.name for x in arcpy.ListFields(inDB1)
        if "ObjectID" in x.name or "NodeID" in x.name
        or "XCoordinate" in x.name or "YCoordinate" in x.name
    ]

    #[u'ObjectID', u'NodeID', u'XCoordinate', u'YCoordinate']

    cursorS = arcpy.da.SearchCursor(
        view, fields, "NOT " +
        [x.name
         for x in arcpy.ListFields(view) if "XCoordinate" in x.name][0] +
        " IS NULL AND NOT " +
        [x.name
         for x in arcpy.ListFields(view) if "YCoordinate" in x.name][0] +
        " IS NULL")

    # NodeID : [(coverID,X,Y),..] from Cover
    for row in cursorS:
        num1 = round(row[2], 4)
        num2 = round(row[3], 4)
        if coverDict.has_key(row[1]):
            coverList = coverDict.pop(row[1])
            coverList.append((row[0], num1, num2))
            coverDict[row[1]] = coverList
        else:
            coverDict[row[1]] = [(row[0], num1, num2)]

    del cursorS
    arcpy.Delete_management(view)

    Sfields = [
        x.name for x in arcpy.ListFields(inDB2) if "ObjectID" in x.name
        or "XCoordinate" in x.name or "YCoordinate" in x.name
    ]
    Sfields.append("SHAPE@XY")

    view2 = arcpy.MakeTableView_management(inDB2, "tempview2")

    cursorS = arcpy.da.SearchCursor(view2, Sfields)

    cursorI = arcpy.da.InsertCursor(
        outDB, [x.name for x in arcpy.ListFields(outDB)[1:]])

    logcursorI = arcpy.da.InsertCursor(
        logDB, [x.name for x in arcpy.ListFields(logDB)[1:]])

    for row in cursorS:

        coverList = coverDict.get(row[0], [])
        for (ID, Xcoord, Ycoord) in coverList:
            distance = math.sqrt(
                round(
                    math.pow(row[3][0] - Xcoord, 2) +
                    math.pow(row[3][1] - Ycoord, 2), 4))
            if abs(distance) > 1:
                cursorI.insertRow([
                    "Node Shapefile X and Y coordinates", "Cover", "",
                    globalScriptSettings.getErrID(), ID, row[0],
                    float(distance)
                ])
                errcount += 1
    del cursorI
    del cursorS
    logcursorI.insertRow(
        [dateofrun, errtype, errcount,
         globalScriptSettings.getRunCount()])
    del logcursorI
    arcpy.Delete_management(view2)

    returnValue = errcount
    return returnValue
Beispiel #12
0
def MainpipeFlow(errtype, inDB1, inDB2, outDB, logDB):

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1, "tempview",
                                          "NOT MainPipeID IS NULL")  #pipe
    view2 = arcpy.MakeTableView_management(inDB2, "tempview2")  #mainpipe

    joinres = arcpy.AddJoin_management(view, "MainPipeID", view2, "ObjectID",
                                       "KEEP_COMMON")

    joinfields = [
        x.name for x in arcpy.ListFields(joinres) if "ObjectID" in x.name
        or "UpstreamNodeID" in x.name or "DownstreamNodeID" in x.name
    ]

    #[u'GIS_DD_Tom_TEST.DANDAS.WW_Pipe.ObjectID', u'GIS_DD_Tom_TEST.DANDAS.WW_Pipe.UpstreamNodeID', u'GIS_DD_Tom_TEST.DANDAS.WW_Pipe.DownstreamNodeID',
    # u'GIS_DD_Tom_TEST.DANDAS.WW_MainPipe.ObjectID', u'GIS_DD_Tom_TEST.DANDAS.WW_MainPipe.UpstreamNodeID', u'GIS_DD_Tom_TEST.DANDAS.WW_MainPipe.DownstreamNodeID']

    cursorSwhere = arcpy.da.SearchCursor(joinres, joinfields)

    UpDownNodeDict = {}

    #MainPipeflow = (MainUP,MainDown,[(PipeID,pipeUD,pipeDown)...])
    # key is main pipe ID
    for row in cursorSwhere:
        if UpDownNodeDict.has_key(row[3]):
            MainPipeflow = UpDownNodeDict.pop(row[3])
            MainPipeflow[2].append((row[0], row[1], row[2]))
            UpDownNodeDict[row[3]] = MainPipeflow
        else:
            MainPipeflow = (row[4], row[5], [(row[0], row[1], row[2])])
            UpDownNodeDict[row[3]] = MainPipeflow

    del cursorSwhere

    cursorI = arcpy.da.InsertCursor(
        outDB, [x.name for x in arcpy.ListFields(outDB)[1:]])
    logcursorI = arcpy.da.InsertCursor(
        logDB, [x.name for x in arcpy.ListFields(logDB)[1:]])

    CurrentNode = 0
    for MainID, (mainUP, mainDOWN, nodeList) in UpDownNodeDict.items():

        res = CheckifFlow(MainID, mainUP, mainDOWN, nodeList)

        if res[0] == 1:  # 1=YES, there is an error
            cursorI.insertRow([
                "Join on MainPipe", "Delledning",
                "PipeObjID is 0 if it couldnt be determined",
                globalScriptSettings.getErrID(), res[1], res[2], res[3]
            ])
            errcount += 1
        elif res[0] == 2:  # 2=YES, there is an dangling pipe error
            danglinglist = res[3]
            cursorI.insertRow([
                "Join on MainPipe", "Delledning",
                "Dangling pipe(s) on main pipe, only giving one PipeObjID",
                globalScriptSettings.getErrID(), res[1], danglinglist[0][0],
                danglinglist[0][1]
            ])
            errcount += 1

    del cursorI
    logcursorI.insertRow(
        [dateofrun, errtype, errcount,
         globalScriptSettings.getRunCount()])
    del logcursorI
    arcpy.RemoveJoin_management(joinres)
    arcpy.Delete_management(view)
    arcpy.Delete_management(view2)

    returnValue = errcount
    return returnValue
Beispiel #13
0
def CoordinateCheck(errtype, inDB1, inDB2, inDB3, inDB4, outDB, logDB):

    #inDB1 is Pipe
    #inDB2 is MainPipe
    #inDB3 is Node
    #inDB4 is Lateral

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1, "tempview")
    view2 = arcpy.MakeTableView_management(
        inDB2, "tempview2"
    )  #NetworkCategoryCode = 4  gives the laterals themselvs, not the mains they sit on
    view3 = arcpy.MakeTableView_management(inDB3, "tempview3")
    view4 = arcpy.MakeTableView_management(inDB4, "tempview4")

    joinres = arcpy.AddJoin_management(
        view,
        [x.name for x in arcpy.ListFields(view)
         if "MainPipeID" in x.name][0], view2,
        [x.name for x in arcpy.ListFields(view2)
         if "ObjectID" in x.name][0], "KEEP_COMMON")

    joinfields = [
        x.name for x in arcpy.ListFields(joinres) if "MainPipeID" in x.name
    ]
    joinfields.append("SHAPE@")
    #[u'GIS_VCS_DD_TEST.DANDAS.WW_Pipe.MainPipeID', 'SHAPE@']

    Pipecursor = arcpy.da.SearchCursor(joinres, joinfields)

    count = 0
    LateralDict = {}
    # mainID : [geometry,]
    for row in Pipecursor:
        count += 1
        if LateralDict.has_key(row[0]):
            pointlist = LateralDict.pop(row[0])
            pointlist.append(row[1])
            LateralDict[row[0]] = pointlist
        else:
            LateralDict[row[0]] = [row[1]]

    joinres2 = arcpy.AddJoin_management(
        view3,
        [x.name for x in arcpy.ListFields(view3) if "ObjectID" in x.name][0],
        view4, [x.name for x in arcpy.ListFields(view4)
                if "NodeID" in x.name][0], "KEEP_COMMON")

    joinfields2 = [
        x.name for x in arcpy.ListFields(joinres2)
        if "NodeID" in x.name or "MainPipeID" in x.name
    ]
    joinfields2.append("SHAPE@")
    #[u'GIS_DD_Tom_TEST.DANDAS.WW_LateralConnection.NodeID', u'GIS_DD_Tom_TEST.DANDAS.WW_LateralConnection.MainPipeID', u'GIS_DD_Tom_TEST.DANDAS.WW_LateralConnection.MeasuredFromNodeID', 'SHAPE@']

    Pointscursor = arcpy.da.SearchCursor(joinres2, joinfields2)

    cursorI = arcpy.da.InsertCursor(
        outDB, [x.name for x in arcpy.ListFields(outDB)[1:]])
    logcursorI = arcpy.da.InsertCursor(
        logDB, [x.name for x in arcpy.ListFields(logDB)[1:]])

    for (nodeID, pipeID, measure, point) in Pointscursor:
        if LateralDict.has_key(pipeID):
            mindistance = 999999
            for lateral in LateralDict.get(pipeID):
                distance = point.distanceTo(lateral)
                if distance < mindistance:
                    mindistance = distance
            if mindistance > 0.002:
                cursorI.insertRow([
                    "LateralConnection and MainPipe", "Pipe and Node", "",
                    globalScriptSettings.getErrID(), pipeID, nodeID,
                    float(mindistance)
                ])
                errcount += 1

    del cursorI
    del Pointscursor
    del Pipecursor
    logcursorI.insertRow(
        [dateofrun, errtype, errcount,
         globalScriptSettings.getRunCount()])
    del logcursorI
    arcpy.Delete_management(joinres)
    arcpy.Delete_management(joinres2)
    arcpy.Delete_management(view)
    arcpy.Delete_management(view2)
    arcpy.Delete_management(view3)
    arcpy.Delete_management(view4)

    returnValue = errcount
    return returnValue
Beispiel #14
0
def Clockrefrence(errtype, inDB1, inDB2, inDB3, inDB4, inDB5, outDB, logDB):

    #inDB1 is CCTVInspection
    #inDB2 is Report
    #inDB3 is ReportFromToward
    #inDB4 is FraKnude
    #inDB5 is LateralConnection

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1, "tempview", "InActive = 0")
    view2 = arcpy.MakeTableView_management(inDB2, "tempview2")
    view3 = arcpy.MakeTableView_management(inDB3, "tempview3")

    joinres = arcpy.AddJoin_management(view, [
        x.name for x in arcpy.ListFields(view) if "ID" in x.name
    ][1], view2, [x.name for x in arcpy.ListFields(view2)
                  if "ID" in x.name][0], "KEEP_COMMON")

    joinres2 = arcpy.AddJoin_management(
        joinres,
        [x.name for x in arcpy.ListFields(joinres)
         if "ReportID" in x.name][0], view3,
        [x.name for x in arcpy.ListFields(view3)
         if "ReportID" in x.name][0], "KEEP_COMMON")

    joinfields = [
        x.name for x in arcpy.ListFields(joinres2)
        if "ObjectID" in x.name or "ClockAnalog" in x.name
        or "ReportNumber" in x.name or "DocumentName" in x.name
        or "FromNodeID" in x.name or "ReportTypeCode" in x.name
    ]

    cursorSwhere = arcpy.da.SearchCursor(joinres2, joinfields, [
        x.name
        for x in arcpy.ListFields(joinres2) if "ReportTypeCode" in x.name
    ][0] + " = 15 OR " + [
        x.name
        for x in arcpy.ListFields(joinres2) if "ReportTypeCode" in x.name
    ][0] + " = 17")

    #dict elements:
    #FromNodeID : [(ClockAnalog,ObjectID,ReportNumber,ReportName)]

    ReportClockDict = {}

    for row in cursorSwhere:
        if ReportClockDict.has_key(row[7]):
            ReportClock = ReportClockDict.pop(row[7])
            ReportClock.append((row[1], row[0], row[2], row[3]))
            ReportClockDict[row[7]] = ReportClock
        else:
            ReportClockDict[row[7]] = [(row[1], row[0], row[2], row[3])]

    del cursorSwhere
    arcpy.RemoveJoin_management(joinres2)
    arcpy.Delete_management(view)
    arcpy.Delete_management(view2)
    arcpy.Delete_management(view3)

    view4 = arcpy.MakeTableView_management(inDB4, "tempview4")  #Knude
    view5 = arcpy.MakeTableView_management(inDB5,
                                           "tempview5")  #lateralconnection

    joinres3 = arcpy.AddJoin_management(view4, "ObjectID", view5, [
        x.name for x in arcpy.ListFields(view5) if "NodeID" in x.name
    ][0], "KEEP_COMMON")

    joinfields2 = [
        x.name for x in arcpy.ListFields(joinres3) if "ObjectID" in x.name
        or "NodeName" in x.name or "ClockAnalog" in x.name
    ]

    #[u'GIS_VCS_DD_TEST.DANDAS.WW_Node.ObjectID',
    # u'GIS_VCS_DD_TEST.DANDAS.WW_Node.NodeName',
    #  u'GIS_VCS_DD_TEST.DANDAS.WW_Node.PreviousNodeName',
    #   u'GIS_VCS_DD_TEST.DANDAS.WW_LateralConnection.ObjectID',
    #    u'GIS_VCS_DD_TEST.DANDAS.WW_LateralConnection.ClockAnalogy']

    cursorSwhere = arcpy.da.SearchCursor(
        joinres3, joinfields2, "NOT " + [
            x.name
            for x in arcpy.ListFields(joinres3) if "ClockAnalog" in x.name
        ][0] + " IS NULL")

    cursorI = arcpy.da.InsertCursor(
        outDB, [x.name for x in arcpy.ListFields(outDB)[1:]])
    logcursorI = arcpy.da.InsertCursor(
        logDB, [x.name for x in arcpy.ListFields(logDB)[1:]])

    for row in cursorSwhere:

        checkclock = ReportClockDict.pop(row[0], [])
        #checkclocklist = [x for (x,y,z,w) in checkclock]

        for (ClockAnalog, ObjectID, ReportNumber, ReportName) in checkclock:
            #if row[4] not in checkclocklist and row[4] != ClockAnalog:

            if row[4] != ClockAnalog:
                #get Inspection ID, ReportID, ReportName, NodeID, NodeName,
                cursorI.insertRow([
                    "Join on Report, ReportFromToward and join on LateralConnection",
                    "CCTVInspection and Knude", "",
                    globalScriptSettings.getErrID(), ObjectID, ReportNumber,
                    ReportName, row[0], row[1]
                ])
                errcount += 1

    del cursorSwhere
    del cursorI
    logcursorI.insertRow(
        [dateofrun, errtype, errcount,
         globalScriptSettings.getRunCount()])
    del logcursorI
    arcpy.RemoveJoin_management(joinres3)
    arcpy.Delete_management(view4)
    arcpy.Delete_management(view5)

    returnValue = errcount
    return returnValue
Beispiel #15
0
def NodePipeCounting(errtype,inDB1,inDB2,outDB,logDB):

    #inDB1 is Pipe
    #inDB2 is Node

    returnValue = 0
    errcount = 0
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1,"tempview")
    view2 = arcpy.MakeTableView_management(inDB2,"tempview2")

    joinres = arcpy.AddJoin_management(view,[x.name for x in arcpy.ListFields(view) if "UpstreamNodeID" in x.name][0],view2,[x.name for x in arcpy.ListFields(view2) if "ObjectID" in x.name][0],"KEEP_COMMON")

    fields = [x.name for x in arcpy.ListFields(joinres) if "ObjectID" in x.name or "NodeTypeCode" in x.name]
    #[u'GIS_VCS_DD_TEST.DANDAS.WW_Pipe.ObjectID', u'GIS_VCS_DD_TEST.DANDAS.WW_Node.ObjectID', u'GIS_VCS_DD_TEST.DANDAS.WW_Node.NodeTypeCode']

    cursorS = arcpy.da.SearchCursor(joinres,fields)

    UpstreamDict = {}
    for row in cursorS:
        if UpstreamDict.has_key(row[1]):
            nodelist = UpstreamDict.pop(row[1])
            nodelist.append((row[0],row[2]))
            UpstreamDict[row[1]] = nodelist
        else:
            UpstreamDict[row[1]] = [(row[0],row[2])]

    arcpy.RemoveJoin_management(joinres)
    del cursorS

    joinres2 = arcpy.AddJoin_management(view,[x.name for x in arcpy.ListFields(view) if "DownstreamNodeID" in x.name][0],view2,[x.name for x in arcpy.ListFields(view2) if "ObjectID" in x.name][0],"KEEP_COMMON")

    cursorSearch = arcpy.da.SearchCursor(joinres2,fields)

    cursorI = arcpy.da.InsertCursor(outDB,[x.name for x in arcpy.ListFields(outDB)[1:]])
    logcursorI = arcpy.da.InsertCursor(logDB,[x.name for x in arcpy.ListFields(logDB)[1:]])

    caughtlist = set()
    for row in cursorSearch:

        #check here if Pipe only has 1 upstream and 1 downstream node. All Upstreams in dict. when typecode = 45, check list only contains 2.
        if row[2] == 45 and len(UpstreamDict.get(row[1],[])) != 1 and row[1] not in caughtlist:
            caughtlist.add(row[1])
            cursorI.insertRow(["Join with Node","Pipe","Typecode 45 with not exactly 1 upstream and downstream pipe",globalScriptSettings.getErrID(),row[1],row[2]])
            errcount += 1

        if UpstreamDict.has_key(row[1]):
            nodelist = UpstreamDict.pop(row[1])
            nodelist.append((row[0],row[2]))
            UpstreamDict[row[1]] = nodelist
        else:
            UpstreamDict[row[1]] = [(row[0],row[2])]

    for ID,pipelist in UpstreamDict.iteritems():
        if len(pipelist) > 2:
            if pipelist[0][1] != 1 and pipelist[0][1] != 20 and ID not in caughtlist:
                cursorI.insertRow(["Join with Node","Pipe","",globalScriptSettings.getErrID(),ID,pipelist[0][1]])
                errcount += 1

    del cursorSearch
    arcpy.RemoveJoin_management(joinres2)
    arcpy.Delete_management(view)
    arcpy.Delete_management(view2)
    del cursorI
    logcursorI.insertRow([dateofrun,errtype,errcount,globalScriptSettings.getRunCount()])
    del logcursorI

    returnValue = errcount
    return returnValue
def CoordinateCheck(errtype,inDB1,outDB,logDB):

    #inDB1 is Node

    returnValue = 0
    errcount = 0
    coverDict = {}
    dateofrun = datetime.datetime.now()

    view = arcpy.MakeTableView_management(inDB1,"tempview")

    fields = [x.name for x in arcpy.ListFields(inDB1) if "ObjectID" in x.name or "XCoordinate" in x.name or "YCoordinate" in x.name]
    fields.append("SHAPE@XY")

    #[u'ObjectID', u'XCoordinate', u'YCoordinate'] + SHAPE@

    cursorS = arcpy.da.SearchCursor(view,fields)

    cursorI = arcpy.da.InsertCursor(outDB,[x.name for x in arcpy.ListFields(outDB)[1:]])

    logcursorI = arcpy.da.InsertCursor(logDB,[x.name for x in arcpy.ListFields(logDB)[1:]])

    for row in cursorS:

        try:
            if abs(float(row[1]) - row[3][0]) > 0.05 or abs(float(row[2]) - row[3][1]) > 0.05:
                cursorI.insertRow(["Field, and Shapefile X and Y coordinates","Node","Node XY coordinate differs with shapefile",globalScriptSettings.getErrID(),row[0],max([abs(float(row[1]) - row[3][0]),abs(float(row[2]) - row[3][1])])])
                errcount += 1
        except:
            pass

    del cursorS
    arcpy.Delete_management(view)
    del cursorI
    logcursorI.insertRow([dateofrun,errtype,errcount,globalScriptSettings.getRunCount()])
    del logcursorI

    returnValue = errcount
    return returnValue