def _cut_poly(poly, p_id, step=1.0, split_axis="X", split_fac=4, SR=None): """Perform the poly* cutting and return the result. step : number fractional step for division, 1.0 equates to 1% split_face : number number of areas to produce, 4, means split into 4 equal areas """ L, B, R, T = _poly_ext(poly) # s_fac = math.ceil((R - L)/step) # lefts = np.linspace(L+dx, R, num=s_fac, endpoint=True) dx = step dy = step if split_axis == "X": lefts = np.arange(L+dx, R+dx, dx, dtype='float') splitters = np.array([[[l, B-1.0], [l, T+1.0]] for l in lefts]) elif s_axis == 'Y': tops = np.arange(B+dy, T+dy, dy, dtype='float') splitters = np.array([[[R+1.0, t], [L-1.0, t]] for t in tops]) cutters = [] for s in splitters: s = s.tolist() c = arcpy.Polyline(arcpy.Array([arcpy.Point(*xy) for xy in s]), SR) cutters.append(c) # ---- cuts = [] for i in cutters: rght = poly if i.crosses(poly): try: left, rght = poly.cut(i) if rght is None: cuts.append(left) cuts.append(left) poly = rght rght = left except RuntimeError: tweet("Issues with poly...{}".format(p_id)) continue else: cuts.append(rght) return cuts, cutters
def _cut_poly(poly, p_id, step=1.0, split_axis="X", split_fac=4, SR=None): """Perform the poly* cutting and return the result. step : number fractional step for division, 1.0 equates to 1% split_face : number number of areas to produce, 4, means split into 4 equal areas """ L, B, R, T = _poly_ext(poly) # s_fac = math.ceil((R - L)/step) # lefts = np.linspace(L+dx, R, num=s_fac, endpoint=True) dx = step dy = step if split_axis == "X": lefts = np.arange(L + dx, R + dx, dx, dtype='float') splitters = np.array([[[l, B - 1.0], [l, T + 1.0]] for l in lefts]) elif s_axis == 'Y': tops = np.arange(B + dy, T + dy, dy, dtype='float') splitters = np.array([[[R + 1.0, t], [L - 1.0, t]] for t in tops]) cutters = [] for s in splitters: s = s.tolist() c = arcpy.Polyline(arcpy.Array([arcpy.Point(*xy) for xy in s]), SR) cutters.append(c) # ---- cuts = [] for i in cutters: rght = poly if i.crosses(poly): try: left, rght = poly.cut(i) if rght is None: cuts.append(left) cuts.append(left) poly = rght rght = left except RuntimeError: tweet("Issues with poly...{}".format(p_id)) continue else: cuts.append(rght) return cuts, cutters
def __cut__(poly, p_id, cutters): """Perform the poly* cutting and return the result. """ cuts = [] for i in cutters: rght = poly if i.crosses(poly): try: left, rght = poly.cut(i) if rght is None: cuts.append(left) cuts.append(left) poly = rght rght = left except RuntimeError: tweet("Issues with poly...{}".format(p_id)) continue else: cuts.append(rght) return cuts
def final_cut(cutters, poly): """ final cut """ cuts = [] for i in cutters: rght = poly if i.crosses(poly): try: left, rght = poly.cut(i) if rght is None: cuts.append(left) cuts.append(left) poly = rght rght = left except RuntimeError: tweet("Issues with poly...{}".format(p_id)) continue else: cuts.append(rght) return cuts # , cutters
def _cut_poly(poly, p_id, step=1.0, split_fac=4, SR=None): """Perform the poly* cutting and return the result. step : number fractional step for division, 1.0 equates to 1% split_face : number number of areas to produce, 4, means split into 4 equal areas """ L, B, R, T = _poly_ext(poly) dx = 100.0 / step s_fac = math.ceil((R - L) / dx) lefts = np.linspace(L + dx, R, num=s_fac, endpoint=True) splitters = np.array([[[l, B - 1.0], [l, T + 1.0]] for l in lefts]) # n = [] # for i in splitters: # n.append(trans_rot(i, 45)) # splitters = np.array(n) cutters = [] for s in splitters: s = s.tolist() c = arcpy.Polyline(arcpy.Array([arcpy.Point(*xy) for xy in s]), SR) cutters.append(c) # ---- cuts = [] for i in cutters: rght = poly if i.crosses(poly): try: left, rght = poly.cut(i) if rght is None: cuts.append(left) cuts.append(left) poly = rght rght = left except RuntimeError: tweet("Issues with poly...{}".format(p_id)) continue else: cuts.append(rght) return cuts, cutters
def _cut_poly(poly, p_id, step=1.0, split_fac=4, SR=None): """Perform the poly* cutting and return the result. step : number fractional step for division, 1.0 equates to 1% split_face : number number of areas to produce, 4, means split into 4 equal areas """ L, B, R, T = _poly_ext(poly) dx = 100.0/step s_fac = math.ceil((R - L)/dx) lefts = np.linspace(L+dx, R, num=s_fac, endpoint=True) splitters = np.array([[[l, B-1.0], [l, T+1.0]] for l in lefts]) # n = [] # for i in splitters: # n.append(trans_rot(i, 45)) # splitters = np.array(n) cutters = [] for s in splitters: s = s.tolist() c = arcpy.Polyline(arcpy.Array([arcpy.Point(*xy) for xy in s]), SR) cutters.append(c) # ---- cuts = [] for i in cutters: rght = poly if i.crosses(poly): try: left, rght = poly.cut(i) if rght is None: cuts.append(left) cuts.append(left) poly = rght rght = left except RuntimeError: tweet("Issues with poly...{}".format(p_id)) continue else: cuts.append(rght) return cuts, cutters
idxs = cal_area(poly, cuts, cutters, s_fac) f_cutters = [cutters[i] for i in idxs] r = final_cut(f_cutters, poly) result_.extend(r) if not testing: if arcpy.Exists(out_fc): arcpy.Delete_management(out_fc) arcpy.CopyFeatures_management(result_, out_fc) out_ids = np.repeat(out_ids, s_fac) id_fld = np.zeros((len(result_), ), dtype=[("key", "<i4"), ("Old_ID", "<i4")]) id_fld["key"] = np.arange(1, len(result_) + 1) id_fld["Old_ID"] = out_ids arcpy.da.ExtendTable(out_fc, oid_fld, id_fld, "key") else: msg = """ ----------------------------------------------------------------- Input data is not in a projected coordinate system.... bailing... ----------------------------------------------------------------- """ tweet(msg) # ---------------------------------------------------------------------- # __main__ .... code section if __name__ == "__main__": """Optionally... : - print the script source name. : - run the _demo """
idxs = cal_area(poly, cuts, cutters, s_fac) f_cutters = [cutters[i] for i in idxs] r = final_cut(f_cutters, poly) result_.extend(r) if not testing: if arcpy.Exists(out_fc): arcpy.Delete_management(out_fc) arcpy.CopyFeatures_management(result_, out_fc) out_ids = np.repeat(out_ids, s_fac) id_fld = np.zeros((len(result_),), dtype=[("key", "<i4"), ("Old_ID", "<i4")]) id_fld["key"] = np.arange(1, len(result_) + 1) id_fld["Old_ID"] = out_ids arcpy.da.ExtendTable(out_fc, oid_fld, id_fld, "key") else: msg = """ ----------------------------------------------------------------- Input data is not in a projected coordinate system.... bailing... ----------------------------------------------------------------- """ tweet(msg) # ---------------------------------------------------------------------- # __main__ .... code section if __name__ == "__main__": """Optionally... : - print the script source name. : - run the _demo """
arcpy.Delete_management(out_fc) arcpy.da.NumPyArrayToFeatureClass(out, out_fc, ['X_', 'Y_'], SR) return out # ---- Do the work # if len(sys.argv) == 1: testing = True in_pth = script.split("/")[:-2] + ["Polygon_lineTools.gdb"] in_fc = "/".join(in_pth) + "/Polygons" out_fc = "/".join(in_pth) + "/poly_pnts" keep_flds = "*" out = to_pnts(in_fc, out_fc, keep_flds, to_file=True) else: in_fc = sys.argv[1] out_fc = sys.argv[2] keep_flds = sys.argv[3] if keep_flds not in ("#", "", " ", None): keep_flds = keep_flds.split(";") tweet(keep_flds) out = to_pnts(in_fc, out_fc, keep_flds, to_file=True) # ---------------------------------------------------------------------- # __main__ .... code section if __name__ == "__main__": """Optionally... : - print the script source name. : - run the _demo """