Exemplo n.º 1
0
def rotater(in_fc, gdb, name, as_group, angle, clockwise):
    """Rotate features separately or as a group.
    """
    SR = getSR(in_fc)
    kind, k = shape_K(in_fc)                        # geometry type, 0, 1, 2
    a, IFT = fc_geometry(in_fc, SR=SR, IFT_rec=False)
    tmp = MultipartToSinglepart_management(in_fc, r"memory\in_fc_temp")
    info = "rotate features"
    a = Geo(a, IFT=IFT, Kind=k, Info=info)       # create the geo array
    s = a.rotate(as_group=as_group, angle=angle, clockwise=clockwise)
    p = kind.upper()
    geometry_fc(s, s.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    out = "{}/{}".format(gdb, name)
    if Exists(out):
        import time
        time.sleep(1.0)
        d = fc_data(tmp)
        da.ExtendTable(out, 'OBJECTID', d, 'OID_')
    return
Exemplo n.º 2
0
def fill_holes(in_fc, gdb, name):
    """Fill holes in a featureclass.  See the Eliminate part tool.
    """
    SR = getSR(in_fc)
    kind, k = shape_K(in_fc)                        # geometry type, 0, 1, 2
    tmp = MultipartToSinglepart_management(in_fc, r"memory\in_fc_temp")
    a, IFT = fc_geometry(tmp, SR=SR, IFT_rec=False)
    info = "fill holes"
    a = Geo(a, IFT=IFT, Kind=k, Info=info)       # create the geo array
    oring = a.outer_rings(True)
    p = kind.upper()
    geometry_fc(oring, oring.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    out = "{}/{}".format(gdb, name)
    if Exists(out):
        import time
        time.sleep(1.0)
        d = fc_data(tmp)
        da.ExtendTable(out, 'OBJECTID', d, 'OID_')
    return
Exemplo n.º 3
0
def pgon_to_pline(in_fc, gdb, name):
    """Polygon to polyline conversion.  Multipart shapes are converted to
    singlepart.  The singlepart geometry is used to produce the polylines."""
#    gdb, name = check_path(out_fc)
#    if gdb is None:
#        return None
    SR = getSR(in_fc)
    tmp = MultipartToSinglepart_management(in_fc, r"memory\in_fc_temp")
    a, IFT = fc_geometry(tmp, SR=SR, IFT_rec=False)
    info = "pgon to pline"
    # create the geo array, convert it, then create the output featureclass
    a = Geo(a, IFT=IFT, Kind=1, Info=info)       # create the geo array
    geometry_fc(a, IFT, p_type="POLYLINE", gdb=gdb, fname=name, sr=SR)
    out = "{}/{}".format(gdb, name)
    if Exists(out):
        d = fc_data(tmp)
        import time
        time.sleep(1.0)
        da.ExtendTable(out, 'OBJECTID', d, 'OID_')
    tweet(dedent(msg_mp_sp))
    return
Exemplo n.º 4
0
def shifter(in_fc, gdb, name, dX, dY):
    """Shift features to a new location by delta X and Y values.  Multipart
    shapes are converted to singlepart shapes.
    """
    SR = getSR(in_fc)
    desc = da.Describe(in_fc)
    kind = desc['shapeType']
    kind, k = shape_K(in_fc)                        # geometry type, 0, 1, 2
    a, IFT = fc_geometry(in_fc, SR=SR, IFT_rec=False)
    tmp = MultipartToSinglepart_management(in_fc, r"memory\in_fc_temp")
    info = "shift features"
    # create the geo array, shift it, then create the output featureclass
    a = Geo(a, IFT=IFT, Kind=k, Info=info)
    s = a.shift(dX, dY)
    p = kind.upper()
    geometry_fc(s, s.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    out = "{}/{}".format(gdb, name)
    if Exists(out):
        import time
        time.sleep(1.0)
        d = fc_data(tmp)
        da.ExtendTable(out, 'OBJECTID', d, 'OID_')
    return
Exemplo n.º 5
0
def pick_tool(tool, in_fc, out_fc, gdb, name):
    """Pick the tool and run the option.
    """
    # ---- Geometry tools ----------------------------------------------------
    #
    # ---- Containers
    if tool in ['Bounding Circles', 'Convex Hulls', 'Extent Polys']:
        kind = sys.argv[4].upper()
        if tool == 'Bounding Circles':           # ---- (1) bounding circles
            circles(in_fc, gdb, name, kind)
        elif tool == 'Convex Hulls':             # ---- (2) convex hulls
            convex_hull_polys(in_fc, gdb, name, kind)
        elif tool == 'Extent Polys':             # ---- (3) extent_poly
            extent_poly(in_fc, gdb, name, kind)
        tweet("...\n{} as {}".format(tool, kind.title()))
    #
    # ---- Conversion
    elif tool in ['Features to Points', 'Vertices to Points']:
        if tool == 'Features to Points':         # ---- (1) features to point
            out, SR = f2pnts(in_fc)
        elif tool == 'Vertices to Points':       # ---- (2) feature to vertices
            out, SR = p_uni_pnts(in_fc)
        ags.da.NumPyArrayToFeatureClass(out, out_fc, ['Xs', 'Ys'], SR)
        tweet("...\n{} as {}".format(tool, 'Points'))
    elif tool == 'Polygons to Polylines':        # ---- (3) polygon to polyline
        tweet("...\nPolygons to Polylines...\n")
        pgon_to_pline(in_fc, gdb, name)
    elif tool == 'Split at Vertices':            # ---- (4) split at vertices
        tweet("...\n{} as {}".format(tool, 'Lines'))
        split_at_vertices(in_fc, out_fc)
    #
    # ---- Alter geometry
    elif tool == 'Rotate Features':              # ---- (1) rotate
        clockwise = False
        as_group = False
        rot_type = str(sys.argv[4])  # True, extent center, False, shape center
        angle = float(sys.argv[5])
        clockwise = str(sys.argv[6])
        if rot_type == "shape center":
            as_group = True
        if clockwise.lower() == "true":
            clockwise = True
        tweet("...\n{} {}".format(tool, 'Features'))
        rotater(in_fc, gdb, name, as_group, angle, clockwise)
    elif tool == 'Shift Features':               # ---- (5) shift
        dX = float(sys.argv[4])
        dY = float(sys.argv[5])
        tweet("...\n{} {}".format(tool, 'Features'))
        shifter(in_fc, gdb, name, dX=dX, dY=dY)
    elif tool == 'Fill Holes':
        tweet("not implemented yet")
        fill_holes(in_fc, gdb, name)
    #
    # ---- Sort geometry
    elif tool in ['Area Sort', 'Length Sort', 'Geometry Sort']:
        srt_type = tool.split(" ")[0].lower()
        tweet("...\n{} as {}".format(tool, 'input'))
        sort_geom(in_fc, gdb, name, srt_type)
    elif tool == 'Extent Sort':
        srt_type = int(sys.argv[4][0])
        tweet("...\n{} as {}".format(tool, 'input'))
        sort_extent(in_fc, gdb, name, srt_type)
    #
    # ---- Attribute tools --------------------------------------------------
    elif tool == 'Crosstabulate':                # ---- (1) freq and stats
        cls_flds = sys.argv[4]
        stat_fld = sys.argv[5]
        cls_flds = cls_flds.split(";")  # multiple to list, singleton a list
        if stat_fld in (None, 'NoneType', ""):
            stat_fld = None
        a = ags.da.TableToNumPyArray(in_fc, "*")  # use the whole array
        tweet("result...\n{}".format(a))
        out = freq(a, cls_flds, stat_fld)        # do freq analysis
        if Exists(out_fc) and env.overwriteOutput:
            Delete_management(out_fc)
        ags.da.NumPyArrayToTable(out, out_fc)
    elif tool == 'Attribute sort':
        sort_flds = str(sys.argv[4])  # just tool and in_fc, extend to existing
        sort_flds = sort_flds.split(";")
        msg = """\
        ------------------
        Sorting      : {}
        Using fields : {}
        Output field : {}
        -----------------
        """
        tweet(dedent(msg).format(in_fc, sort_flds, "Sorted_"))
        oid_fld = da.Describe(in_fc)['OIDFieldName']
        flds = [oid_fld] + sort_flds
        a = ags.da.TableToNumPyArray(in_fc, flds)
        out = attr_sort(a, oid_fld, sort_flds)    # do the work... attr_sort
        da.ExtendTable(in_fc, oid_fld, out, oid_fld, append_only=False)
    else:
        tweet("tool {} not found".format(tool))
        return None