Beispiel #1
0
def pgon_to_pline(in_fc, out_fc):
    """Polygon to polyline conversion.  Multipart shapes are converted to
    singlepart.  The singlepart geometry is used to produce the polylines."""
    result = check_path(out_fc)
    if result[0] is None:
        print(result[1])
        return result[1]
    gdb, name = result
    SR = getSR(in_fc)
    temp = arcpy.MultipartToSinglepart_management(in_fc, r"memory\in_fc_temp")
    a, IFT, IFT_2 = fc_geometry(temp, SR)
    tweet("\n(1) fc_geometry complete...")
    d = fc_data(temp)
    tweet("\n(2) featureclass data complete...")
    info = "pgon to pline"
    b = Geo(a, IFT=IFT, Kind=1, Info=info)  # create the geo array
    tweet("\n(3) Geo array complete...")
    done = geometry_fc(b, IFT, p_type="POLYLINE", gdb=gdb, fname=name, sr=SR)
    tweet("\n(4) " + done)
    if arcpy.Exists(out_fc):
        import time
        time.sleep(1.0)
    try:
        arcpy.da.ExtendTable(out_fc, 'OBJECTID', d, 'OID_')
        tweet("\n(5) ExtendTable complete...")
    finally:
        tweet("\narcpy.da.ExtendTable failed... try a spatial join after.")
    msg = """\n
        ----
        Multipart shapes have been converted to singlepart, so view any data
        carried over during the extendtable join as representing those from
        the original data.  Recalculate values where appropriate.
        ----
        """
    tweet(dedent(msg))
Beispiel #2
0
def extent_poly(in_fc, gdb, name, kind):
    """Feature envelope to polygon demo.

    Parameters
    ----------
    in_fc : string
        Full geodatabase path and featureclass filename.
    kind : integer
        2 for polygons, 1 for polylines

    References
    ----------
    `Feature Envelope to Polygon
    <https://pro.arcgis.com/en/pro-app/tool-reference/data-management/feature
    -envelope-to-polygon.htm>`_.

    >>> data = fc_data(in_fc)
    """
    SR = getSR(in_fc)
    kind, k = shape_K(in_fc)
    tmp, IFT = fc_geometry(in_fc, SR=SR, IFT_rec=False)
    m = np.nanmin(tmp, axis=0)                   # shift to LB of extent
    info = "extent to polygons"
    a = tmp - m
    g = Geo(a, IFT, k, Info=info)   # create the geo array
    ext = g.extent_rectangles()   # create the extent array
    ext = ext + m                 # shift back, construct the output features
    ext = Update_Geo(ext, K=k, id_too=None, Info=info)
    # ---- produce the geometry
    p = kind.upper()
    geometry_fc(ext, ext.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    return "{} completed".format("Extents")
Beispiel #3
0
def bounding_circles(in_fc, out_fc, kind=2):
    """Minimum area bounding circles.  Change `angle=5` to a smaller value for
    denser points on circle perimeter.
    """
    result = check_path(out_fc)
    if result[0] is None:
        print(result[1])
        return result[1]
    gdb, name = result
    SR = getSR(in_fc)  # getSR, shape_to_K  and fc_geometry from
    kind = shape_to_K(in_fc)  # npGeo_io
    tmp, IFT, IFT_2 = fc_geometry(in_fc, SR)
    m = np.nanmin(tmp, axis=0)  # shift to bottom left of extent
    info = "bounding circles"
    a = tmp - m
    g = Geo(a, IFT=IFT, Kind=kind, Info=info)  # create the geo array
    out = g.bounding_circles(angle=2, return_xyr=False)
    circs = [arr + m for arr in out]
    circs = Update_Geo(circs, K=2, id_too=None, Info=info)
    # ---- produce the geometry
    p = "POLYGON"
    if kind == 1:
        p = "POLYLINE"
    geometry_fc(circs, circs.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    return "{} completed".format(out_fc)
Beispiel #4
0
def p_uni_pnts(in_fc):
    """Implements `_polys_to_unique_pnts_` in ``npg_helpers``.
    """
    SR = getSR(in_fc)
    tmp, IFT = fc_geometry(in_fc, SR=SR, IFT_rec=False)
    info = "unique points"
    a = Geo(tmp, IFT=IFT, Kind=0, Info=info)     # create the geo array
    out = _polys_to_unique_pnts_(a, as_structured=True)
    return out, SR
Beispiel #5
0
def sort_extent(in_fc, gdb, name, key):
    """Sort features by extent, area, length
    """
    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)
    info = "sort features"
    a = Geo(a, IFT=IFT, Kind=k, Info=info)
    srt = a.sort_by_extent(key, just_indices=False)
    p = kind.upper()
    geometry_fc(srt, srt.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    return
Beispiel #6
0
def convex_hull_polys(in_fc, gdb, name, kind):
    """Determine the convex hulls on a shape basis"""
    SR = getSR(in_fc)
    kind, k = shape_K(in_fc)
    tmp, IFT = fc_geometry(in_fc, SR=SR, IFT_rec=False)
    info = "convex hulls to polygons"
    g = Geo(tmp, IFT, k, info)                   # create the geo array
    ch_out = g.convex_hulls(by_part=False, threshold=50)
    ch_out = Update_Geo(ch_out, K=k, id_too=None, Info=info)
    # ---- produce the geometry
    p = kind.upper()
    geometry_fc(ch_out, ch_out.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    return "{} completed".format("Convex Hulls")
Beispiel #7
0
def p_uni_pnts(in_fc, out_fc):
    """Implements _polys_to_unique_pnts_ in ``npg_helpers``.
    """
    result = check_path(out_fc)
    if result[0] is None:
        print(result[1])
        return result[1]
    gdb, name = result
    SR = getSR(in_fc)
    a, IFT, IFT_2 = fc_geometry(in_fc, SR)
    info = "unique points"
    a = Geo(a, IFT=IFT, Kind=0, Info=info)  # create the geo array
    out = _polys_to_unique_pnts_(a, as_structured=True)
    return out, SR
Beispiel #8
0
def f2pnts(in_fc):
    """Features to points.
    `getSR`, `shape_K` and `fc_geometry` from `npGeo_io`
    """
    SR = getSR(in_fc)
    kind, k = shape_K(in_fc)
    tmp, ift = fc_geometry(in_fc, SR=SR, IFT_rec=False)
    m = np.nanmin(tmp, axis=0)                   # shift to LB of whole extent
    info = "feature to points"
    a = tmp - m
    g = Geo(a, IFT=ift, Kind=k, Info=info)    # create the geo array
    cent = g.centroids + m                       # create the centroids
    dt = np.dtype([('Xs', '<f8'), ('Ys', '<f8')])
    cent = uts(cent, dtype=dt)
    return cent, SR
Beispiel #9
0
def sort_geom(in_fc, gdb, name, sort_kind):
    """Sort features by area, length
    """
    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)
    info = "sort features"
    a = Geo(a, IFT=IFT, Kind=k, Info=info)
    if sort_kind == 'area':
        srt = a.sort_by_area(ascending=True, just_indices=False)
    elif sort_kind == 'length':
        srt = a.sort_by_length(ascending=True, just_indices=False)
    p = kind.upper()
    geometry_fc(srt, srt.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    return
Beispiel #10
0
def split_at_vertices(in_fc, out_fc):
    """Unique segments retained when poly geometry is split at vertices.
    """
    gdb, _ = check_path(out_fc)
    if gdb is None:
        return None
    SR = getSR(in_fc)
    tmp, IFT = fc_geometry(in_fc, SR=SR, IFT_rec=False)
    ag = Geo(tmp, IFT)
    od = ag.polys_to_segments(as_basic=False, as_3d=False)
    tmp = "memory/tmp"
    if Exists(tmp):
        Delete_management(tmp)
    ags.da.NumPyArrayToTable(od, tmp)
    xyxy = list(od.dtype.names[:4])
    args = [tmp, out_fc] + xyxy + ["GEODESIC", "Orig_id", SR]
    XYToLine_management(*args)
    return
Beispiel #11
0
def f2pnts(in_fc):
    """Features to points"""
    result = check_path(out_fc)
    if result[0] is None:
        print(result[1])
        return result[1]
    gdb, name = result
    SR = getSR(in_fc)  # getSR, shape_to_K  and fc_geometry from
    kind = shape_to_K(in_fc)  # npGeo_io
    tmp, IFT, IFT_2 = fc_geometry(in_fc, SR)
    m = np.nanmin(tmp, axis=0)  # shift to bottom left of extent
    info = "feature to points"
    a = tmp - m
    g = Geo(a, IFT=IFT, Kind=kind, Info=info)  # create the geo array
    cent = g.centroids  # create the centroids
    cent = cent + m
    dt = np.dtype([('Xs', '<f8'), ('Ys', '<f8')])
    cent = uts(cent, dtype=dt)
    return cent, SR
Beispiel #12
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
Beispiel #13
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
Beispiel #14
0
def extent_poly(in_fc, out_fc, kind):
    """Feature envelop to polygon demo.

    Parameters
    ----------
    in_fc : string
        Full geodatabase path and featureclass filename.
    kind : integer
        2 for polygons, 1 for polylines

    References
    ----------
    `Feature Envelope to Polygon
    <https://pro.arcgis.com/en/pro-app/tool-reference/data-management/feature
    -envelope-to-polygon.htm>`_.

    >>> data = fc_data(in_fc)
    """
    result = check_path(out_fc)
    if result[0] is None:
        tweet(result[1])
        return result[1]
    gdb, name = result
    # ---- done checks
    SR = getSR(in_fc)
    tmp, IFT, IFT_2 = fc_geometry(in_fc, SR)
    SR = getSR(in_fc)
    m = np.nanmin(tmp, axis=0)  # shift to bottom left of extent
    info = "extent to polygons"
    a = tmp - m
    g = Geo(a, IFT=IFT, Kind=kind, Info=info)  # create the geo array
    ext = g.extent_rectangles()  # create the extent array
    ext = ext + m  # shift back, construct the output features
    ext = Update_Geo(ext, K=kind, id_too=None, Info=info)
    #
    # ---- produce the geometry
    p = "POLYGON"
    if kind == 1:
        p = "POLYLINE"
    geometry_fc(ext, ext.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    return "{} completed".format(out_fc)
Beispiel #15
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
Beispiel #16
0
def circles(in_fc, gdb, name, kind):
    """Minimum area bounding circles.  Change `angle=2` to a smaller value for
    denser points on circle perimeter.
    `getSR`, `shape_k`  and `fc_geometry` are from npg_io.
    """
    SR = getSR(in_fc)
    kind, k = shape_K(in_fc)
    tmp, IFT = fc_geometry(in_fc, SR=SR, IFT_rec=False)
    m = np.nanmin(tmp, axis=0)                   # shift to LB of whole extent
    info = "bounding circles"
    a = tmp - m
    g = Geo(a, IFT, k, info)                     # create the geo array
    out = g.bounding_circles(angle=2, return_xyr=False)
    circs = [arr + m for arr in out]
    k = 1
    if kind == 'Polygons':
        k = 2
    circs = Update_Geo(circs, K=k, id_too=None, Info=info)
    # produce the geometry
    p = kind.upper()
    geometry_fc(circs, circs.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    return "{} completed".format("Circles")
Beispiel #17
0
def convex_hull_polys(in_fc, out_fc, kind):
    """Determine the convex hulls on a shape basis"""
    result = check_path(out_fc)
    if result[0] is None:
        tweet(result[1])
        return result[1]
    gdb, name = result
    # ---- done checks
    SR = getSR(in_fc)
    tmp, IFT, IFT_2 = fc_geometry(in_fc, SR)
    SR = getSR(in_fc)
    info = "convex hulls to polygons"
    g = Geo(tmp, IFT=IFT, Kind=kind, Info=info)  # create the geo array
    ch_out = g.convex_hulls(by_part=False, threshold=50)
    ch_out = Update_Geo(ch_out, K=kind, id_too=None, Info=info)
    #
    # ---- produce the geometry
    p = "POLYGON"
    if kind == 1:
        p = "POLYLINE"
    geometry_fc(ch_out, ch_out.IFT, p_type=p, gdb=gdb, fname=name, sr=SR)
    return "{} completed".format(out_fc)
Beispiel #18
0
def split_at_vertices(in_fc, out_fc):
    """Unique segments retained when poly geometry is split at vertices.
    """
    result = check_path(out_fc)
    if result[0] is None:
        print(result[1])
        return result[1]
    gdb, name = result
    SR = getSR(in_fc)
    a, IFT, IFT_2 = fc_geometry(in_fc, SR)
    ag = Geo(a, IFT)
    #    fr_to = ag.unique_segments()  # geo method
    fr_to = ag.polys_to_segments()
    dt = np.dtype([('X_orig', 'f8'), ('Y_orig', 'f8'), ('X_dest', 'f8'),
                   ('Y_dest', 'f8')])
    od = uts(fr_to, dtype=dt)  # ---- unstructured to structured
    tmp = "memory/tmp"
    if arcpy.Exists(tmp):
        arcpy.Delete_management(tmp)
    arcpy.da.NumPyArrayToTable(od, tmp)
    args = [tmp, out_fc] + list(od.dtype.names) + ["GEODESIC", "", SR]
    arcpy.XYToLine_management(*args)
    return
Beispiel #19
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