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")
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)
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
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")
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
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))
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
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
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)
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
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)
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")
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