def asignarAer(ubigeos, conexion=conexionDB, conn=conn):

    asignarIDAER()
    aers = r'{}\CPV_SEGMENTACION.dbo.TB_AER'.format(conexion)

    for ubigeo in ubigeos:
        print ubigeo
        ccppsmfl = arcpy.MakeQueryLayer_management(
            conexion, 'CCPP',
            "SELECT*FROM TB_CCPP WHERE UBIGEO = '{}' AND AREA = 2".format(
                ubigeo), 'LLAVE_CCPP', 'POINT', '4326',
            arcpy.SpatialReference(4326))
        ccpps_copy = arcpy.CopyFeatures_management(ccppsmfl, "in_memory\ccpps")
        ccpps = arcpy.MakeFeatureLayer_management(ccpps_copy, "ccpp")
        for aer in arcpy.da.SearchCursor(
                aers, ["SHAPE@", "AER_INI", "AER_FIN", "IDAER"],
                "UBIGEO = '{}'".format(ubigeo)):
            seleccion = arcpy.SelectLayerByLocation_management(
                ccpps, "INTERSECT", aer[0], "#", "NEW_SELECTION", "NOT_INVERT")
            listaCcpps = [
                x[0] for x in arcpy.da.SearchCursor(seleccion, ["LLAVE_CCPP"])
            ]
            if len(listaCcpps) > 0:
                expresion = funcionesGenerales.Expresion(
                    listaCcpps, "#", "LLAVE_CCPP")
                cursor = conn.cursor()
                cursor.execute(
                    "UPDATE TB_CCPP SET AER_INI = '{}', AER_FIN = '{}', IDAER = '{}' WHERE {}"
                    .format(aer[1], aer[2], aer[3], expresion))
                conn.commit()
                cursor.close()
            else:
                pass
def consistenciaCCPP(CALIDAD_AER_PRESEGM):
    informacion = []
    ubigeos = ubigeosDisponibles()
    expresion01 = funcionesGenerales.Expresion(ubigeos, "#", "UBIGEO")
    e1 = aer_E1(expresion01)
    informacion.extend(e1)
    expresion02 = aerCorregir(informacion)
    cargarTabla(informacion, expresion02, CALIDAD_AER_PRESEGM)
def aersenscr(idscr, conn=conn):
    cursor = conn.cursor()
    cursor.execute(
        "SELECT DISTINCT IDAER FROM SEGM_R_CCPPRUTA WHERE IDSCR = '{}' ".
        format(idscr))
    aers = [x[0] for x in cursor]
    sql = funcionesGenerales.Expresion(aers, "#", "IDAER")
    cursor.close()
    del cursor
    return sql
def dataruta(ubigeos, RUTA):
    sql = funcionesGenerales.Expresion(ubigeos, "#", "UBIGEO")
    # mfl = arcpy.MakeFeatureLayer_management(RUTA, "ruta_mfl", sql)        # FLUJO NORMAL
    # tb = arcpy.TableToTable_conversion(mfl, 'in_memory', 'ruta', sql)     # FLUJO NORMAL
    mfl = arcpy.MakeFeatureLayer_management(
        RUTA, "ruta_mfl", sql + "AND FLAG_NUEVO = 1 ")  # FLUJO CCPP NUEVOS
    tb = arcpy.TableToTable_conversion(
        mfl, 'in_memory', 'ruta',
        sql + "AND FLAG_NUEVO = 1 ")  # FLUJO CCPP NUEVOS
    return tb
def eliminarRegistrosRuta(ubigeos, conn=conn):
    sql = funcionesGenerales.Expresion(ubigeos, "#", "UBIGEO")
    cursor = conn.cursor()
    # cursor.execute("DELETE FROM SEGM_R_RUTA WHERE {}".format(sql))                    # FLUJO NORMAL
    cursor.execute(
        "DELETE FROM SEGM_R_RUTA WHERE {} AND FLAG_NUEVO = 1".format(
            sql))  # FLUJO CCPP NUEVOS
    conn.commit()
    informacion = [x[0] for x in cursor]
    cursor.close()
    return informacion
Example #6
0
def segmentacionmain(ubigeos):
    #### PROCESAMIENTO DE INFORMACION
    # UBIGEOS
    sql = funcionesGenerales.Expresion(ubigeos, "#", 'UBIGEO')
    Distritos_tmp = arcpy.MakeQueryLayer_management(
        conexionDB, 'DistritosTMP',
        "SELECT*FROM CPV_SEGMENTACION_GDB.sde.TB_LIMITE_DIS where {}".format(
            sql), 'UBIGEO', 'POLYGON', '4326', arcpy.SpatialReference(4326))

    # SEGMENTACION
    print "SEGMENTACION"
    arcpy.AddMessage("SEGMENTACION")
    Segmentacion_2.SegmentacionRural(WorkSpaceSegmentacion, Distritos_tmp,
                                     conexionDB, conexionGDB, SEGM_R_AER,
                                     SEGM_R_CCPP, SEGM_R_VIV, SEGM_R_AER_POST)
Example #7
0
def consistenciaCCPP(CALIDAD_CCPP_PRESEGM, ubigeos_input=[]):
    informacion = []
    if len(ubigeos_input) == 0:
        ubigeos = ubigeosDisponibles()
    else:
        ubigeos = ubigeos_input
    expresion01 = funcionesGenerales.Expresion(ubigeos, "#", "UBIGEO")
    print ubigeos
    e1 = ccpp_E1(expresion01)
    e2 = ccpp_E2(expresion01)
    e3 = ccpp_E3(expresion01)
    for x in [e1, e2, e3]:
        informacion.extend(x)
    expresion02 = ccppCorregir(informacion)
    cargarTabla(informacion, expresion02, CALIDAD_CCPP_PRESEGM)
Example #8
0
def consistenciaVIV(CALIDAD_VIV_PRESEGM, ubigeos_input=[]):
    informacion = []
    if len(ubigeos_input) == 0:
        ubigeos = ubigeosDisponibles()
    else:
        ubigeos = ubigeos_input
    expresion01 = funcionesGenerales.Expresion(ubigeos, "#", "UBIGEO")
    e1 = viv_E1(expresion01)
    e2 = viv_E2(expresion01)
    for x in [e1, e2]:
        informacion.extend(x)
    if len(informacion) > 0:
        expresion02 = vivCorregir(informacion)
        cargarTabla(informacion, expresion02, CALIDAD_VIV_PRESEGM)
    else:
        pass
Example #9
0
def vivCorregir(informacion):
    viviendas = [x[0] for x in informacion]
    expresion = funcionesGenerales.Expresion(viviendas, "#", "IDVIV")
    return expresion
Example #10
0
def ccppCorregir(informacion):
    ccpps = [x[0] for x in informacion]
    expresion = funcionesGenerales.Expresion(ccpps, "#", "LLAVE_CCPP")
    return expresion
def aerCorregir(informacion):
    aer = [x[0] for x in informacion]
    expresion = funcionesGenerales.Expresion(aer, "#", "IDAER")
    return expresion