Пример #1
0
def _demo():
    """
    Notes:
    -----
    The xs and ys form pairs with the first and last points being identical
    The pairs are constructed using n-1 to ensure that you don't form a
    line from identical points.

    First split polygon as a sample of a multipart.  I had to add 0,0 and 0, 80
    back in

    xs = [0., 0., 80., 0, 0., 100., 100., 0.]
    ys = [0., 30., 30., 80., 100., 100., 0., 0.]
    a = np.array(list(zip(xs, ys))) * 1.0  # --- must be floats
    v = np.array([[50., 0], [50, 100.]])
    ext = np.array([[0., 0], [0, 100.],[100, 100.], [100., 0.], [0., 0.]])
    return a, v
    """
    in_pth = script.split("/")[:-2] + ["Polygon_lineTools.gdb"]
    in_fc = "/".join(in_pth) + "/r_concave_k3_polygon"
    out_fc = "/".join(in_pth) + "/c0"
    split_type = 'extent'
    desc = arcpy.da.Describe(in_fc)
    x_tent = str(desc['extent'])
    split_fac = 4
    split_per = 25.
    shp_fld, oid_fld, shp_type, SR = fc_info(in_fc)
    do_work(in_fc, out_fc, split_type, x_tent, split_fac, split_per)
    return None
Пример #2
0
def pnt_groups(in_fc):
    """Simple def to convert shapes to points from a featureclass
    """
    shp_fld, oid_fld, shp_type, SR = fc_info(in_fc)
    flds = ['OID@', 'SHAPE@X', 'SHAPE@Y']
    args = [in_fc, flds, None, None, True, (None, None)]
    cur = arcpy.da.SearchCursor(*args)
    a = cur._as_narray()
    a.dtype = [('IDs', '<i4'), ('Xs', '<f8'), ('Ys', '<f8')]
    del cur
    pts = []
    keys = np.unique(a['IDs'])
    for k in keys:
        w = np.where(a['IDs'] == k)[0]
        z = a[['Xs', 'Ys']][w[0]:w[-1] + 1]
        z = np.copy(z.view(np.float64).reshape(z.shape[0], 2))
        pts.append(z)
    return pts, a, SR
Пример #3
0
def pnt_groups(in_fc):
    """Simple def to convert shapes to points from a featureclass
    """
    shp_fld, oid_fld, shp_type, SR = fc_info(in_fc)
    flds = ['OID@', 'SHAPE@X', 'SHAPE@Y']
    args = [in_fc, flds, None, None, True, (None, None)]
    cur = arcpy.da.SearchCursor(*args)
    a = cur._as_narray()
    a.dtype = [('IDs', '<i4'), ('Xs', '<f8'), ('Ys', '<f8')]
    del cur
    pts = []
    keys = np.unique(a['IDs'])
    for k in keys:
        w = np.where(a['IDs'] == k)[0]
        z = a[['Xs', 'Ys']][w[0]:w[-1] + 1]
        z = np.copy(z.view(np.float64).reshape(z.shape[0], 2))
        pts.append(z)
    return pts, a, SR
Пример #4
0
def to_pnts(in_fc, out_fc, keep_flds=None, to_file=False):
    """Convert a featureclass to a point file with unique point id values
    added to indicate the points within the poly* features.  The output field
    names (keep_flds) can be specified or all will be used if '*' is used.

    Requires:
    ---------
        fc_array - from arcpytools_plt.py
    Notes:
    ------
    - a Pnt_id field is added to indicate the order of the points making the
      poly* feature
    - the duplicate last point is removed for polygon features
    - potentially troublesome field names are changed.
    """
    shp_fld, oid_fld, shp_type, SR = fc_info(in_fc)
    if keep_flds is None:
        keep_flds = "*"
    a, out_flds, SR = fc_array(in_fc, flds=keep_flds, allpnts=True)
    a_s = np.split(a, np.where(np.diff(a[oid_fld]))[0] + 1)
    out = []
    for i in a_s:
        ids = np.arange(i.shape[0])
        out.append(append_fld(i, name='Pnt_id', data=ids))
    # ---- remove duplicate last point and stack the points
    if shp_type == "Polygon":
        for i in range(len(a_s)):
            out[i] = out[i][:-1]
    out = np.hstack(out)
    # ---- replace dodgy field names
    kv = {
        'OBJECTID': 'Old_ID',
        'SHAPE@X': 'X_',
        'SHAPE@Y': 'Y_',
        'Shape_Length': 'Leng_orig',
        'Shape_Area': 'Area_orig'
    }
    change = [kv.get(i, i) for i in out.dtype.names]
    out.dtype.names = change
    if to_file:
        if arcpy.Exists(out_fc):
            arcpy.Delete_management(out_fc)
        arcpy.da.NumPyArrayToFeatureClass(out, out_fc, ['X_', 'Y_'], SR)
    return out
Пример #5
0
def do_work(in_fc, out_fc, split_type, x_tent, split_fac, split_per):
    """Do the actual work for either the demo or the tool

    Requires:
    --------
    in_fc : feautureclass
        polygon or polyline featureclass
    out_fc : featureclass
        same as input
    split_type : choice of `extent` or `areas`
        `extent` uses the bounds with `split_fac` to subdivide the range into
        sub-polygons

    **extent option**

    x_tent : extent parameter
        LBRT L(eft), B(ottom), R(ight), T(op) in the featureclass units
    split_fac : integer
        Integer representing the divisions, for example, a factor of 2 is the
        same as half (1/2) or 50%

    **area option**

    split_per : double
        Percentage of the total area representing sub-area size. 25% would
        result in 4 sub-areas with approximately 25% of the total area.
    """
    shp_fld, oid_fld, shp_type, SR = fc_info(in_fc)
    desc = arcpy.da.Describe(in_fc)
    x_tent = x_tent.split(" ")[:4]
    L, B, R, T = [float(i) for i in x_tent]
    split_fac = float(split_fac)
    #
    if split_type == 'extent':
        dx = (R - L) / split_fac
        lefts = np.arange(L + dx, R,
                          step=dx)  #[304000, 304500, 305000, 305500, 306000]
        splitters = np.array([[[l, B], [l, T]] for l in lefts])
        cutters = []
        for s in splitters:
            s = s.tolist()
            c = arcpy.Polyline(arcpy.Array([arcpy.Point(*xy) for xy in s]), SR)
            cutters.append(c)
        polygons = []
        with arcpy.da.SearchCursor(in_fc, ["SHAPE@"]) as cursor:
            for row in cursor:
                poly = row[0]
                p_right = poly
                for i in cutters:
                    pieces = p_right.cut(i)
                    p_left = pieces[0]
                    p_right = pieces[1]
                    polygons.append(p_left)
                if p_right is not None or len(p_right) > 0:
                    polygons.append(p_right)
    #
    elif split_type == 'area':
        #        ar= e_area(xy)
        print("None")
    #
    # ---- create the output, overwite any existing versions
    if arcpy.Exists(out_fc):
        arcpy.Delete_management(out_fc)
    arcpy.CopyFeatures_management(polygons, out_fc)
Пример #6
0
# ---- demo and tool section -------------------------------------------------
#
"""

"""

if len(sys.argv) == 1:
    testing = True
    in_pth = script.split("/")[:-2] + ["Polygon_lineTools.gdb"]
    in_fc = "/".join(in_pth) + "/shapes_mtm9"
    out_fc = "/".join(in_pth) + "/c0"
    s_type = 'extent'
    s_fac = 4
    s_axis = 'X'
    shp_fld, oid_fld, shp_type, SR = fc_info(in_fc)
    out_polys, out_ids = get_polys(in_fc)

else:
    in_fc = sys.argv[1]
    out_fc = sys.argv[2]
    s_type = sys.argv[3]
    # --- extent parameters
    s_fac = int(sys.argv[4])
    s_axis = sys.argv[5]
    shp_fld, oid_fld, shp_type, SR = fc_info(in_fc)
    out_polys, out_ids = do_work(in_fc, out_fc, s_type, s_fac, s_axis)
    for p in out_polys:
        if not (p.area > 0.):
            out_polys.remove(p)
    if arcpy.Exists(out_fc):
Пример #7
0
if len(sys.argv) == 1:
    in_pth = script.split("/")[:-2] + ["Polygon_lineTools.gdb"]
    in_fc = "/".join(in_pth) + "/shapes_mtm9"#    in_fc = r"C:\Git_Dan\a_Data\arcpytools_demo.gdb\xy1000_tree"
    out_fc = "/".join(in_pth) + '/x2'
    fact = 2
    out_type = 'Polygon'  # 'Polyline' or 'Points'
    testing = False
else:
    in_fc = sys.argv[1]  #
    out_fc = sys.argv[2]  #
    fact = int(sys.argv[3])  #
    out_type = sys.argv[4]  # Polygon, Polyline are options
    testing = False


shp_fld, oid_fld, shp_type, SR = fc_info(in_fc)
temp = out_fc + "tmp"
if arcpy.Exists(temp):
    arcpy.Delete_management(temp)
arcpy.MultipartToSinglepart_management(in_fc, temp)
polys = _get_shapes(temp)
a = densify(polys, fact=fact, sp_ref=SR)
b, _, _ = fc_array(in_fc, flds="*", allpnts=False) #_get_attributes(temp)
dt = b.dtype.descr
dtn = [(i[0].replace("@", "_"), i[1]) for i in dt]
b.dtype = np.dtype(dtn)
out_shps = arcpnts_poly(a, out_type=out_type, SR=SR)
#
# ---- if not testing, save the geometry and extend (join) the attributes
if not testing:
    if arcpy.Exists(out_fc):