def main(): utilities.start_time() # Se crean los campos (CODSECTOR, CODSUBSECTOR) en BBDD utilities.add_field(constants.FC_SUBSECTORS, "CODSECTOR", "TEXT", 2, "Sector") utilities.add_field(constants.FC_SUBSECTORS, "CODSUBSECTOR", "TEXT", 1, "SubSector") count_subsectors = int( arcpy.GetCount_management(constants.FC_SUBSECTORS).getOutput(0)) count = 0 for subsector in arcpy.da.SearchCursor(constants.FC_SUBSECTORS, ['OID@', 'SubSector']): utilities.update_progress_bar(count, count_subsectors, param_prefix=constants.PB_PREFIX.format( str(1))) split = subsector[1].split('-', len(subsector[1])) utilities.update_subsector(subsector[0], split[0], split[1]) count += 1 utilities.update_progress_bar(count, count_subsectors, param_prefix=constants.PB_PREFIX.format( str(1))) utilities.stop_time('subsectors', count_subsectors, count)
def main(args): utilities.start_time() # Se crean los campos (CODSECTOR, CODSUBSECTOR) en BBDD utilities.add_field(constants.FC_BLOCKS, "CODSECTOR", "TEXT", 2, "Sector") utilities.add_field(constants.FC_BLOCKS, "CODSUBSECTOR", "TEXT", 3, "SubSector") where_clause = utilities.get_arguments_filter(args.s, args.sb, None) arcpy.MakeFeatureLayer_management(constants.FC_SUBSECTORS, "subsectors_count", where_clause) count_subsectors = int( arcpy.GetCount_management("subsectors_count").getOutput(0)) count_total_blocks = int( arcpy.GetCount_management(constants.FC_BLOCKS).getOutput(0)) count_subsec = 0 count_blocks = 0 arcpy.MakeFeatureLayer_management(constants.FC_BLOCKS, "manzanas_lyr") for subsector in arcpy.da.SearchCursor( constants.FC_SUBSECTORS, ['OID@', 'CODSECTOR', 'CODSUBSECTOR', 'SHAPE@'], where_clause): utilities.update_progress_bar(count_subsec, count_subsectors, param_prefix=constants.PB_PREFIX.format( str(2))) arcpy.SelectLayerByLocation_management("manzanas_lyr", "COMPLETELY_WITHIN", subsector[3], "", "NEW_SELECTION") oids = arcpy.Describe("manzanas_lyr").FIDSet for oidmanzana in oids.split(";"): oid = int(oidmanzana.strip()) utilities.update_block(oid, subsector[1], subsector[2]) count_blocks += 1 count_subsec += 1 utilities.update_progress_bar(count_subsec, count_subsectors, param_prefix=constants.PB_PREFIX.format( str(2))) utilities.stop_time('blocks', count_total_blocks, count_blocks) print("\t error_blocks: {0}".format(count_total_blocks - count_blocks))
def main(args): utilities.start_time() count = 0 count_steps = 10 # Borramos algunos campos... si están en la capa el join nunca coge estos campos de la capa de manzanas arcpy.DeleteField_management(constants.FC_PLOTS, ['CODSECTOR', 'CODSUBSECTOR', 'CODMANZANA']) count += 1 utilities.update_progress_bar(count, count_steps, param_prefix=constants.PB_PREFIX.format( str(5))) arcpy.SpatialJoin_analysis( constants.FC_PLOTS, constants.FC_BLOCKS, constants.FC_JOIN_PLOTS, "JOIN_ONE_TO_ONE", "KEEP_ALL", "RefName \"RefName\" true true false 255 Text 0 0 ,First,#," + constants.FC_PLOTS + ",RefName,-1,-1;" "Text \"Text\" true true false 255 Text 0 0 ,First,#," + constants.FC_PLOTS + ",Text,-1,-1;" "TxtAngle \"TxtAngle\" true true false 8 Double 0 0 ,First,#," + constants.FC_PLOTS + ",TxtAngle,-1,-1;" "TxtMemo \"TxtMemo\" true true false 2048 Text 0 0 ,First,#," + constants.FC_PLOTS + ",TxtMemo,-1,-1;" "Shape_Length \"Shape_Length\" false true true 8 Double 0 0 ,First,#," + constants.FC_PLOTS + ",Shape_Length,-1,-1;" "Shape_Area \"Shape_Area\" false true true 8 Double 0 0 ,First,#," + constants.FC_PLOTS + ",Shape_Area,-1,-1;" "CODLOTE \"Lote\" true true false 10 Text 0 0 ,First,#," + constants.FC_PLOTS + ",CODLOTE,-1,-1;" "NUMLOTE \"Numero Lote\" true true false 4 Text 0 0 ,First,#," + constants.FC_PLOTS + ",NUMLOTE,-1,-1;" "CODSECTOR \"Sector\" true true false 2 Text 0 0 ,First,#," + constants.FC_BLOCKS + ",CODSECTOR,-1,-1;" "CODSUBSECTOR \"Subsector\" true true false 3 Text 0 0 ,First,#," + constants.FC_BLOCKS + ",CODSUBSECTOR,-1,-1;" "CODMANZANA \"Manzana\" true true false 7 Text 0 0 ,First,#," + constants.FC_BLOCKS + ",CODMANZANA,-1,-1", "HAVE_THEIR_CENTER_IN", "", "") count += 1 utilities.update_progress_bar(count, count_steps, param_prefix=constants.PB_PREFIX.format( str(5))) arcpy.DeleteFeatures_management(constants.FC_PLOTS) count += 1 utilities.update_progress_bar(count, count_steps, param_prefix=constants.PB_PREFIX.format( str(5))) utilities.add_field(constants.FC_PLOTS, "CODSECTOR", "TEXT", 2, "Sector") count += 1 utilities.add_field(constants.FC_PLOTS, "CODSUBSECTOR", "TEXT", 3, "SubSector") count += 1 utilities.add_field(constants.FC_PLOTS, "CODMANZANA", "TEXT", 6, "Manzana") count += 1 utilities.add_field(constants.FC_PLOTS, "CODLOTE", "TEXT", 10, "Lote") count += 1 utilities.add_field(constants.FC_PLOTS, "NUMLOTE", "TEXT", 4, "Numero Lote") count += 1 utilities.update_progress_bar(count, count_steps, param_prefix=constants.PB_PREFIX.format( str(5))) arcpy.Append_management( constants.FC_JOIN_PLOTS, constants.FC_PLOTS, "NO_TEST", "RefName \"RefName\" true true false 255 Text 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",RefName,-1,-1;" "Text \"Text\" true true false 255 Text 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",Text,-1,-1;" "TxtAngle \"TxtAngle\" true true false 8 Double 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",TxtAngle,-1,-1;" "TxtMemo \"TxtMemo\" true true false 2048 Text 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",TxtMemo,-1,-1;" "Shape_Length \"Shape_Length\" false true true 8 Double 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",Shape_Length,-1,-1;" "Shape_Area \"Shape_Area\" false true true 8 Double 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",Shape_Area,-1,-1;" "CODLOTE \"CODLOTE\" true true false 10 Text 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",CODLOTE,-1,-1;" "NUMLOTE \"NUMLOTE\" true true false 4 Text 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",NUMLOTE,-1,-1;" "CODSECTOR \"CODSECTOR\" true true false 0 Text 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",CODSECTOR,-1,-1;" "CODSUBSECTOR \"CODSUBSECTOR\" true true false 0 Text 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",CODSUBSECTOR,-1,-1;" "CODMANZANA \"CODMANZANA\" true true false 0 Text 0 0 ,First,#," + constants.FC_JOIN_PLOTS + ",CODMANZANA,-1,-1;") count += 1 utilities.update_progress_bar(count, count_steps, param_prefix=constants.PB_PREFIX.format( str(5))) arcpy.Delete_management(constants.FC_JOIN_PLOTS, "") count += 1 utilities.update_progress_bar(count, count_steps, param_prefix=constants.PB_PREFIX.format( str(5))) utilities.stop_time('steps', count_steps, count)
def main(args): utilities.start_time() where_clause = utilities.get_arguments_filter(args.s, args.sb, args.b) arcpy.MakeFeatureLayer_management(constants.FC_BLOCKS, "blocks_count", where_clause) count_blocks = int(arcpy.GetCount_management("blocks_count").getOutput(0)) count = 0 count_done = 0 for block in arcpy.da.SearchCursor(constants.FC_BLOCKS, [ 'OID@', 'SHAPE@', 'CODSECTOR', 'CODSUBSECTOR', 'CODMANZANA', 'Texto_10' ], where_clause): if not utilities.check_already_done(block[5]): utilities.update_progress_bar( count, count_blocks, param_prefix=constants.PB_PREFIX.format(str(6))) if block is not None and block[0] is not None and block[ 1] is not None and block[2] is not None and block[ 3] is not None and block[4] is not None: plot_points_list = [] plot_list = [] plot_shape_list = [] first = True t_union = None for lote in arcpy.da.SearchCursor( constants.FC_PLOTS, ['SHAPE@'], """{0} = '{1}'""".format("CODMANZANA", str(block[4]))): if lote is not None and lote[0] is not None: if first: t_union = lote[0] first = False else: t_union = t_union.union(lote[0]) if t_union is not None: boundary = t_union.boundary() for lote in arcpy.da.SearchCursor( constants.FC_PLOTS, [ 'OID@', 'SHAPE@', 'CODSECTOR', 'CODSUBSECTOR', 'CODMANZANA', 'CODLOTE', 'SHAPE@XY' ], """{0} = '{1}'""".format("CODMANZANA", str(block[4]))): if lote is not None and lote[0] is not None and lote[ 1] is not None and lote[2] is not None and lote[ 3] is not None and lote[4] is not None: plot_shape_list.append(lote[1]) for part in lote[1]: if part is not None: for pnt in part: if pnt is not None and boundary.buffer( 2).contains(pnt, 'BOUNDARY'): plot_points_list.append({ 'pnt': pnt, 'idPlot': lote[0], 'shape': lote[1], 'distance': boundary.measureOnLine(pnt, False) }) plot_list.append({ 'shape': lote[1], 'idPlot': lote[0] }) plot_points_list.sort(key=utilities.order_by_distance) if plot_points_list: indexNorte = search_north_point(plot_points_list) done = [] count_plot_id = 10 for index in range(len(plot_points_list)): current = plot_points_list[(indexNorte + index) % len(plot_points_list)] if current['idPlot'] not in done: utilities.update_plot( current['idPlot'], block[2], block[3], block[4], block[4] + str(count_plot_id).zfill(4)) count_done += 1 done.append(current['idPlot']) count_plot_id += 10 count += 1 utilities.update_progress_bar(count, count_blocks, param_prefix=constants.PB_PREFIX.format( str(6))) utilities.stop_time('blocks', count_blocks, count_done)
def main(args): utilities.start_time() # Create field (CODMANZANA) utilities.add_field(constants.FC_BLOCKS, "CODMANZANA", "TEXT", 6, "Manzana") where_clause = utilities.get_arguments_filter(args.s, args.sb, None) arcpy.MakeFeatureLayer_management(constants.FC_BLOCKS, "blocks_count", where_clause) count_blocks = int(arcpy.GetCount_management("blocks_count").getOutput(0)) count = 0 num = 0 for subsector in arcpy.da.SearchCursor(constants.FC_SUBSECTORS, ['OID@', 'CODSUBSECTOR', 'SHAPE@'], where_clause): utilities.update_progress_bar(num, count_blocks, param_prefix=constants.PB_PREFIX.format( str(3))) envelop = subsector[2].extent band_num = 1 block_list = get_blocks_list(subsector[1]) select_blocks_done = get_blocks_list_done(subsector[1]) blocks_done = [] orden = [] while len(block_list) > 0: north_block = search_north_block(block_list) band_heigth = get_band_heigth(north_block) blocks_inside_band = get_blocks_inside_band( band_heigth, (envelop.XMin if not utilities.is_even(band_num) else envelop.XMax, envelop.YMax), block_list) blocks_inside_band.sort(key=utilities.order_by_distance) for x in blocks_inside_band: orden.append(x['id']) blocks_done.append(x['id']) num += 1 band_num += 1 block_list = [x for x in block_list if x[0] not in blocks_done] where_clause = """{0} = '{1}' AND {2} <> {3}""".format( "CODSUBSECTOR", str(subsector[1]).zfill(3), "Shape_Area", 0) with arcpy.da.UpdateCursor( constants.FC_BLOCKS, ['OID@', 'CODSECTOR', 'CODSUBSECTOR', 'CODMANZANA', 'Texto_10'], where_clause) as cursor: for row in cursor: if not utilities.check_already_done(row[4]): block_oido = str( get_nice_oido((str(row[2]) + str(orden.index(row[0]) + 1).zfill(3)), select_blocks_done)) code = block_oido select_blocks_done.append(block_oido) row[3] = code cursor.updateRow(row) count += 1 utilities.update_progress_bar(num, count_blocks, param_prefix=constants.PB_PREFIX.format( str(3))) utilities.stop_time('blocks', count_blocks, count)
def main(args): utilities.simplify_blocks_fc_polygons() where_clause = utilities.get_arguments_filter(args.s, args.sb, args.b) if where_clause is None: utilities.create_feature_class( constants.FC_PATH_BASE_CARTOGRAPHY, "Esquinas", "POINT", spatial_reference=arcpy.Describe( constants.FC_BLOCKS).spatialReference) else: # Si no existe creamos la capa de Esquinas if not (arcpy.Exists(constants.FC_CORNERS)): arcpy.CreateFeatureclass_management( constants.FC_PATH_BASE_CARTOGRAPHY, "Esquinas", "POINT", spatial_reference=arcpy.Describe( constants.FC_BLOCKS).spatialReference) else: # La capa ya existía, y tenemos un filtro... borramos lo que cumpla el criterio del filtro with arcpy.da.UpdateCursor(constants.FC_CORNERS, ['OID@'], where_clause) as cursor: for row in cursor: cursor.deleteRow() utilities.start_time() arcpy.MakeFeatureLayer_management(constants.FC_BLOCKS, "blocks_count", where_clause) count_blocks = int(arcpy.GetCount_management("blocks_count").getOutput(0)) errors = [] count = 0 contesquinas = 0 for block in arcpy.da.SearchCursor(constants.FC_GENERALIZED_BLOCKS, [ 'OID@', 'SHAPE@', 'CODSECTOR', 'CODSUBSECTOR', 'CODMANZANA', 'Texto_10' ], where_clause): if not utilities.check_already_done(block[5]): utilities.update_progress_bar( count, count_blocks, param_prefix=constants.PB_PREFIX.format(str(4))) if block is not None and block[0] is not None and block[ 1] is not None and block[2] is not None and block[ 3] is not None and block[4] is not None: envelop = block[1].extent noreste = {'x': envelop.XMax, 'y': envelop.YMax} noroeste = {'x': envelop.XMin, 'y': envelop.YMax} if block[1].isMultipart: errors.append(block) for part in block[1]: cursor = arcpy.da.InsertCursor(constants.FC_CORNERS, [ 'SHAPE@', 'CODSECTOR', 'CODSUBSECTOR', 'CODMANZANA', 'CODESQUINA' ]) corner_list = [] index = 0 for pnt in part: dont = False for x in corner_list: if x['shape'].equals(pnt): dont = True break if not dont: corner_list.append({ 'shape': pnt, 'distanceNE': distanceTo(pnt, noreste), 'distanceNO': distanceTo(pnt, noroeste), 'idOrig': index }) index += 1 if args.o == 'N' or args.o is None: order = sorted(corner_list, key=lambda i: (i['shape'].Y, i['distanceNE']), reverse=True) elif args.o == 'NE': order = sorted(corner_list, key=orderByDistanceToNO) elif args.o == 'NO': order = sorted(corner_list, key=orderByDistanceToNO) corner_list = numerarEsquinas(corner_list, order[0]) corner_list = sorted(corner_list, key=orderByPosFinal) for x in range(len(corner_list)): cursor.insertRow(( arcpy.Point(corner_list[x]["shape"].X, corner_list[x]["shape"].Y), block[2], block[3], block[4], str(block[4]).zfill(6) + str(x + 1).zfill(2), )) contesquinas += 1 del cursor count += 1 utilities.update_progress_bar(count, count_blocks, param_prefix=constants.PB_PREFIX.format( str(4))) utilities.stop_time('blocks', count_blocks, count)