Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
updates for Nov 2023
  • Loading branch information
Dan-Patterson authored Nov 26, 2023
1 parent 8bc2a6b commit 4824447
Show file tree
Hide file tree
Showing 16 changed files with 352 additions and 242 deletions.
60 changes: 31 additions & 29 deletions arcpro_npg/npg/npg/npGeo.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
----
"""
# pylint: disable=C0103,C0302,C0415
# pylint: disable=E1101,E1121
# pylint: disable=W0105,W0201,W0212,W0221,W0611,W0612,W0621

# pylint: disable=C0103,C0201,C0209,C0302,C0415
# pylint: disable=R0902,R0904,R0912,R0913,R0914,R0915
# pylint: disable=W0105,W0201,W0212,W0221,W0611,W0612,W0613,W0621
# pylint: disable=E0401,E0611,E1101,E1121

import sys
from textwrap import indent, dedent, wrap
Expand All @@ -24,8 +25,9 @@
from numpy.lib.recfunctions import unstructured_to_structured as uts
from numpy.lib.recfunctions import repack_fields

import npg # noqa
from npg import npg_geom as geom
from npg import (npg_helpers, npg_io, npg_prn) # npg_create)
from npg import npg_helpers, npg_io, npg_prn # npg_create)
from npg import npg_min_circ as sc

from npg.npg_helpers import (
Expand Down Expand Up @@ -53,10 +55,9 @@
TwoPI = np.pi * 2.0

__all__ = [
'Geo', 'is_Geo',
'roll_coords', 'roll_arrays', 'array_IFT', 'arrays_to_Geo',
'Geo', 'roll_coords', 'roll_arrays', 'array_IFT', 'arrays_to_Geo',
'Geo_to_arrays', 'Geo_to_lists', '_fill_float_array',
'is_Geo', 'reindex_shapes', 'remove_seq_dupl', 'check_geometry',
'remove_seq_dupl', 'check_geometry', 'is_Geo', 'reindex_shapes',
'dirr'
]

Expand Down Expand Up @@ -167,14 +168,14 @@ def __array_finalize__(self, src_arr):
self.UR = getattr(src_arr, 'UR', None)
self.Z = getattr(src_arr, 'Z', None)
self.SVG = getattr(src_arr, 'SVG', None)
return self

def __array_wrap__(self, out_arr, context=None):
"""Wrap it up."""
return np.ndarray.__array_wrap__(self, out_arr, context)

# ---- ------------------------------------------------------------------
# ---- End of class definition -------------------------------------------
#
# ---- ------------------------------------------------------------------
# ---- help : information
@property
def H(self):
Expand All @@ -189,12 +190,8 @@ def facts(self):
structure, and/or more records use the `prn_geo` method.
"""
info_ = self.IFT_str[:25]
frmt = """
{}\nExtents :\n LL {}\n UR {}
Shapes :{:>6.0f}
Parts :{:>6.0f}
Points :{:>6.0f}
\nSp Ref : {}
frmt = """{}\nExtents :\n LL {}\n UR {}\nShapes :{:>6.0f}\
\nParts :{:>6.0f}\nPoints :{:>6.0f}\nSp Ref : {}
"""
args = ["-" * 14, self.LL, self.UR, len(self.U), self.IFT.shape[0],
self.IFT[-1, 2], self.SR]
Expand Down Expand Up @@ -228,21 +225,21 @@ def geo_props(self):
w = wrap(t, 79)
print(">>> geo_info(geo_array)\n... Geo methods and properties.")
for i in w:
print(indent("{}".format(i), prefix=" "))
print(indent(f"{i}", prefix=" "))
print("\n... Geo base properties.")
s0 = set(srt)
s1 = set(Geo.__dict__.keys())
s0s1 = sorted(list(s0.difference(s1)))
t = ", ".join([str(i) for i in s0s1])
w = wrap(t, 79)
for i in w:
print(indent("{}".format(i), prefix=" "))
print(indent(f"{i}", prefix=" "))
print("\n... Geo special.")
s1s0 = sorted(list(s1.difference(s0)))
t = ", ".join([str(i) for i in s1s0])
w = wrap(t, 79)
for i in w:
print(indent("{}".format(i), prefix=" "))
print(indent(f"{i}", prefix=" "))
# return

# ---- ---------------------------
Expand Down Expand Up @@ -499,7 +496,7 @@ def first_part(self, asGeo=True):
Holes are retained. The IFT is altered to account for point removal.
"""
info = "{} first part".format(self.Info)
info = f"{self.Info} first part"
ift_s = self.IFT[self.PID == 1]
a_2d = [self.XY[ft[0]:ft[1]] for ft in self.FT]
if asGeo:
Expand Down Expand Up @@ -591,7 +588,7 @@ def lengths(self, by_shape=True):

def perimeters(self, by_shape=True):
"""Polyline lengths or polygon perimeter. Calls `lengths`."""
return self.lengths(by_shape=True)
return self.lengths(by_shape)

def centers(self, by_shape=True):
"""Return the center of outer ring points."""
Expand Down Expand Up @@ -879,7 +876,9 @@ def rotate(self, as_group=True, angle=0.0, clockwise=False):
#
def bounding_circles(self, angle=5, shift_back=False, return_xyr=False):
"""Bounding circles for features."""
chk = False if len(self.IFT) > 1 else True
chk = True
if len(self.IFT) > 1:
chk = False
chs = self.convex_hulls(chk, False, 50) # check for singlepart shapes
xyr = [sc.small_circ(s) for s in chs.shapes]
circs = []
Expand Down Expand Up @@ -979,7 +978,7 @@ def fill_holes(self):
cs = np.cumsum(tmp_ft)
id_too[1:, 0] = cs[:-1]
id_too[:, 1] = cs
info = "{} fill_holes".format(self.Info)
info = f"{self.Info} fill_holes"
tmp_ift[:, 1:3] = id_too
return Geo(a_2d, IFT=tmp_ift, Kind=2, Extent=self.XT, Info=info)

Expand Down Expand Up @@ -1164,8 +1163,7 @@ def segment_pnt_ids(self):
def to_segments(self, ignore_holes=True):
"""Segment poly* structures into (x0, y0, x1, y1) data per shape.
An object array is returned. Holes removed from polygons by default,
but multipart shapes are not.
An object array is returned. Holes in polygons can be removed.
See Also
--------
Expand All @@ -1185,7 +1183,7 @@ def to_segments(self, ignore_holes=True):
return segs

def common_segments(self, shift_back=False):
"""Return the common segments in poly features.
"""Return the common segments in poly* features.
The result is an array of from-to pairs of points. ft, tf pairs are
evaluated to denote common segments or duplicates.
Expand Down Expand Up @@ -1216,7 +1214,7 @@ def common_segments(self, shift_back=False):
return _fill_float_array(common) # , idx # stu(common)

def unique_segments(self, shift_back=False):
"""Return the unique segments in poly features.
"""Return the unique segments in poly* features.
The output is an ndarray of from-to pairs of points.
Expand Down Expand Up @@ -1301,8 +1299,10 @@ def sort_by_extent(self, extent_pnt='LB', key=0, just_indices=False):
ext_ids = self.shp_ids
xs = ext[:, 0]
ys = ext[:, 1]
azim = np.array([0, 45, 90, 135, 180, 225, 270, 315]) # azimuths
val = np.radians(azim[key]) # sort angle in radians
# azimuth dictionary
azim = {0: 0, 1: 45, 2: 90, 3: 135, 4: 180, 5: 225, 6: 270, 7: 315}
val = azim[key] if key in azim.keys() else 0
val = np.radians(val) # sort angle in radians
z = np.sin(val) * xs + np.cos(val) * ys # - sort by vector
idx = np.argsort(z) # sort order
sorted_ids = ext_ids[idx]
Expand Down Expand Up @@ -1824,7 +1824,9 @@ def dup_idx(sub, poly):
return sub[np.sort(idx)]

chunks = Geo_to_arrays(g)
poly = True if g.K == 2 else False
poly = False
if g.K == 2:
poly = True
out = []
for i, c in enumerate(chunks):
n = len(c.shape)
Expand Down
15 changes: 7 additions & 8 deletions arcpro_npg/npg/npg/npgDocs.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
'sort_by_extent_doc', 'array_IFT_doc', 'dirr_doc'
]

Modified = "2023-02-17"
Modified = "2023-10-09"
author_date = r"""
Author :
Expand All @@ -80,7 +80,7 @@ def _update_docstring(obj, doc):


# ----------------------------------------------------------------------------
# ---- (1) ...npGeo
# ---- (1) npGeo
#
npGeo_doc = author_date + Modified + r"""
Expand Down Expand Up @@ -250,8 +250,7 @@ def _update_docstring(obj, doc):
"""

# ---- (2) ... Geo class
# --- Geo_hlp
# ---- (2) Geo_hlp

Geo_hlp = r"""
Expand Down Expand Up @@ -339,7 +338,7 @@ def _update_docstring(obj, doc):
dtype=int64)
"""

# ---- (3) shapes_doc
# ---- (3) shapes
shapes_doc = r"""
Returns
Expand All @@ -354,7 +353,7 @@ def _update_docstring(obj, doc):
"""

# ---- (4) parts_doc
# ---- (4) parts
parts_doc = r"""
Returns
Expand Down Expand Up @@ -592,7 +591,7 @@ def _update_docstring(obj, doc):
"""


# ---- (17) ... array_IFT
# ---- (17) array_IFT
array_IFT_doc = r"""
Parameters
Expand Down Expand Up @@ -625,7 +624,7 @@ def _update_docstring(obj, doc):
"""


# ---- (18) ... dirr function
# ---- (18) dirr
dirr_doc = r"""
Source, ``arraytools.py_tools`` has a pure python equivalent.
Expand Down
39 changes: 18 additions & 21 deletions arcpro_npg/npg/npg/npg_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
Dan_Patterson@carleton.ca
Modified :
2023-08-23
2023-11-03
Purpose
-------
Expand All @@ -28,10 +28,11 @@
Derived from arraytools ``convex_hull, mst, near, n_spaced``
"""
# pylint: disable=C0103 # invalid-name
# pylint: disable=R0914 # Too many local variables
# pylint: disable=R1710 # inconsistent-return-statements
# pylint: disable=W0105 # string statement has no effect
# pylint: disable=C0103,C0201,C0209,C0302,C0415
# pylint: disable=R0902,R0904,R0912,R0913,R0914,R0915
# pylint: disable=W0105,W0201,W0212,W0221,W0611,W0612,W0613,W0621
# pylint: disable=E0401,E0611,E1101,E1121


# import sys
from textwrap import dedent
Expand Down Expand Up @@ -112,16 +113,12 @@ def n_check(a): # N=3, order=True):
----------
Two 2D array of X,Y coordinates required. Parse your data to comply.
"""
has_err = False
if isinstance(a, (list, tuple, np.ndarray)):
if (hasattr(a[0], '__len__')) and (len(a[0]) == 2):
return True
has_err = True
else:
has_err = True
if has_err:
print(n_check.__doc__)
return False
print(n_check.__doc__)
return False


def n_near(a, N=3, ordered=True, return_all=False):
Expand Down Expand Up @@ -289,24 +286,22 @@ def _x_sect_2(args):
s02_y = p0[1] - p2[1]
#
# -- Second check ---- np.cross(p1-p0, p3-p2)
denom = (s10_x * s32_y - s32_x * s10_y) # .item()
denom = s10_x * s32_y - s32_x * s10_y # .item()
if denom == 0.0: # collinear
return False, None
#
# -- Third check ---- np.cross(p1-p0, p0-p2)
positive_denom = denom > 0.0 # denominator greater than zero
s_numer = (s10_x * s02_y - s10_y * s02_x) # .item()
# if (s_numer < 0) == positive_denom:
# return False
s_numer = s10_x * s02_y - s10_y * s02_x # .item()
#
# -- Fourth check ---- np.cross(p3-p2, p0-p2)
t_numer = s32_x * s02_y - s32_y * s02_x
# if (t_numer < 0) == positive_denom:
# return False
#
if ((s_numer > denom) == positive_denom) or \
((t_numer > denom) == positive_denom):
if positive_denom in (s_numer > denom, t_numer > denom):
return False, None
# if ((s_numer > denom) == positive_denom) or \
# ((t_numer > denom) == positive_denom):
# return False, None
#
# -- check to see if the intersection point is one of the input points
# substitute p0 in the equation These are the intersection points
Expand Down Expand Up @@ -625,8 +620,10 @@ def _x_sect_(*args):
if (t_numer < 0) == den_gt0:
return False
#
if ((s_numer > denom) == den_gt0) or ((t_numer > denom) == den_gt0):
if den_gt0 in (s_numer > denom, t_numer > denom):
return False
# if ((s_numer > denom) == den_gt0) or ((t_numer > denom) == den_gt0):
# return False
#
# -- check if the intersection point is one of the input points
t = t_numer / denom
Expand All @@ -641,7 +638,7 @@ def _x_sect_(*args):
def _angle_(p0, p1, prv_ang=0):
"""Return the angle between two points and the previous angle, or."""
ang = np.arctan2(p0[1] - p1[1], p0[0] - p1[0])
a0 = (ang - prv_ang)
a0 = ang - prv_ang
a0 = a0 % (PI * 2) - PI
return a0

Expand Down
Loading

0 comments on commit 4824447

Please sign in to comment.