Skip to content

Commit

Permalink
updated version and enabled pnts
Browse files Browse the repository at this point in the history
  • Loading branch information
lausdahl committed Feb 15, 2024
1 parent a5c8f44 commit f1ac2c1
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 27 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
# For a discussion on single-sourcing the version across setup.py and the
# project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.4.5', # Required
version='1.4.6', # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down
57 changes: 39 additions & 18 deletions src/isoxmlviz/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def show_task_file(version_prefix, name, tree, save_pdf: bool = False, save_svg:
if not groups:
groups = WebGroups()

part_fields = root.findall(".//PFD")+root.findall(".//TSK")
part_fields = root.findall(".//PFD") + root.findall(".//TSK")

if not use_subplot or len(part_fields) == 1:
fig = plt.figure()
Expand All @@ -205,6 +205,7 @@ def show_task_file(version_prefix, name, tree, save_pdf: bool = False, save_svg:
ax.title.set_text(pfd.attrib.get("C"))
plot_all_pln(ax, parent_map, web_map, ref, pfd, groups.polygon_type_groups)
plot_all_lsg(ax, parent_map, web_map, ref, pfd, gpn_filter=gpn_filter, line_type_groups=groups.line_type_groups)
plot_all_pnt(ax, parent_map, web_map, ref, pfd)
plot_center_name(name, pfd, ref, web_map, group=groups.field_name_group)

ax.axis("equal")
Expand Down Expand Up @@ -305,7 +306,7 @@ def plot_all_pln(ax, parent_map, web_map, ref, root, polygon_type_groups):

web_map.add(polygon, tooltip=designator, style={'color': color, 'fillOpacity': '0.1'}, group=group)
elif polygon_type == 3: # water
patch = PolygonPatch([polygon], linewidth=2, facecolor="blue", alpha=0.1)
patch = PolygonPatch(polygon, linewidth=2, facecolor="blue", alpha=0.1)
web_map.add(polygon, tooltip=designator, style={'color': 'blue', 'fillOpacity': '0.1'}, group=group)
elif polygon_type == 6: # obstacle
patch = PolygonPatch(polygon.buffer(0), alpha=0.1, zorder=2, facecolor="red")
Expand Down Expand Up @@ -339,18 +340,35 @@ def get_color(attrib, key, default_colour):
return default_colour


def get_pnts(node, ref, pnt_type_filter=None) -> [shapely.geometry.Point]:
points_elements = node.findall("./PNT") if not pnt_type_filter else node.findall(
"./PNT[@A='%s']" % pnt_type_filter)
point_data = [pnt_to_pair(pelement) for pelement in points_elements]
return [pymap3d.geodetic2enu(p[0], p[1], 0, ref[0], ref[1], 0, ell=ell_wgs84, deg=True) for p in
point_data]

def plot_all_pnt(ax, parent_map, web_map, ref, root, line_type_groups=None, gpn_filter=None):
for pnt in root.findall("./PNT"):
print("Processing line '%s'" % pnt.attrib.get("B") if 'B' in pnt.attrib else 'No Designator')
p_type = int(pnt.attrib.get("A"))
if p_type not in [1,2,3,4,5,10,11]:
continue

point_data = [pnt_to_pair(pelement) for pelement in [pnt]]
point=SHP.Point( [pymap3d.geodetic2enu(p[0], p[1], 0, ref[0], ref[1], 0, ell=ell_wgs84, deg=True) for p in
point_data][0])

web_map.add_point(pnt.attrib.get("B") if 'B' in pnt.attrib else 'Type %d' % p_type,
point, style={'color': get_color(pnt.attrib, 'F', 'black')}, group=None)
ax.plot(point.x, point.y)



def plot_all_lsg(ax, parent_map, web_map, ref, root, line_type_groups, gpn_filter=None):
for line in root.findall(".//LSG"):
print("Processing line '%s'" % line.attrib.get("B"))

def get_pnts(pnt_type_filter=None) -> [shapely.geometry.Point]:
points_elements = line.findall("./PNT") if not pnt_type_filter else line.findall(
"./PNT[@A='%s']" % pnt_type_filter)
point_data = [pnt_to_pair(pelement) for pelement in points_elements]
return [pymap3d.geodetic2enu(p[0], p[1], 0, ref[0], ref[1], 0, ell=ell_wgs84, deg=True) for p in
point_data]

points = get_pnts()
points = get_pnts(line, ref)

type = int(line.attrib.get("A"))
designator = line.attrib.get("B")
Expand Down Expand Up @@ -386,9 +404,9 @@ def get_pnts(pnt_type_filter=None) -> [shapely.geometry.Point]:
designator = parent.attrib.get('B')

if gpn_type == 4:
center_pnts = get_pnts('8')
a_pnts = get_pnts('6')
b_pnts = get_pnts('7')
center_pnts = get_pnts(line, ref, '8')
a_pnts = get_pnts(line, ref, '6')
b_pnts = get_pnts(line, ref, '7')

# if len(a_pnts)>0:
# web_map.add_marker(designator + '-A-pivot', shapely.geometry.Point(a_pnts[0]), group=guidance_plot_group)
Expand Down Expand Up @@ -475,9 +493,10 @@ def filter_pivot_line_ab(line):
# if pivot_cutout:
# guidance_lines = [extract_lines_within(line,[ pivot_cutout],invert=True) for line in lines]

patchc = LineCollection(get_coordinates([item for sublist in guidance_lines for item in sublist]),
linewidths=1,
edgecolors="purple", zorder=5, alpha=0.5)
patchc = LineCollection(
get_coordinates([item for sublist in guidance_lines for item in sublist]),
linewidths=1,
edgecolors="purple", zorder=5, alpha=0.5)

ax.add_collection(patchc)

Expand Down Expand Up @@ -606,7 +625,8 @@ def getExtrapoledLine(p1, p2, ext_length, from_start=False):
if len(lines) > 0:
guidance_lines = [extract_lines_within(line, boundary_polygons) for line in lines]

patchc = LineCollection(get_coordinates([item for sublist in guidance_lines for item in sublist]), linewidths=1,
patchc = LineCollection(get_coordinates([item for sublist in guidance_lines for item in sublist]),
linewidths=1,
edgecolors="purple", zorder=5, alpha=0.5)

ax.add_collection(patchc)
Expand All @@ -619,7 +639,8 @@ def getExtrapoledLine(p1, p2, ext_length, from_start=False):

# plot the baseline
# https://stackoverflow.com/questions/19877666/add-legends-to-linecollection-plot
patch = LineCollection(get_coordinates( extract_lines_within(base_line_string, boundary_polygons)), linewidths=1.5,
patch = LineCollection(get_coordinates(extract_lines_within(base_line_string, boundary_polygons)),
linewidths=1.5,
edgecolors="goldenrod", zorder=7)
ax.add_collection(patch)

Expand Down
30 changes: 22 additions & 8 deletions src/isoxmlviz/webmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

ell_wgs84 = pymap3d.Ellipsoid.from_name('wgs84')


def flatten(matrix):
return [item for row in matrix for item in row]


def transform(shape, func):
''' Apply a function to every coordinate in a geometry.
'''
Expand All @@ -16,12 +18,11 @@ def transform(shape, func):
parts = [transform(geom, func) for geom in shape.geoms]
return construct(parts)

if shape.geom_type in ( 'LineString'):
if shape.geom_type in ('LineString'):
return construct(map(func, shape.coords))
if shape.geom_type in ('Point'):
return construct(flatten(map(func, shape.coords)))


if shape.geom_type == 'Polygon':
exterior = map(func, shape.exterior.coords)
rings = [list(map(func, ring.coords)) for ring in shape.interiors]
Expand Down Expand Up @@ -55,15 +56,16 @@ def set_refernce(self, ref_lat, ref_lng):
self.ref_lat = ref_lat
self.ref_lng = ref_lng

def add(self, geom, tooltip=None, style={'fillColor': 'red', 'lineColor': '#228B22', 'opacity': '1'},group=None):
def add(self, geom, tooltip=None, style={'fillColor': 'red', 'lineColor': '#228B22', 'opacity': '1'}, group=None):
mkt = lambda x: folium.features.Popup(tooltip) if tooltip else None

ff = lambda c: [c[1], c[0], c[2]]
folium.GeoJson(transform(geom, lambda p: ff(
pymap3d.enu2geodetic(p[0], p[1], 0, self.ref_lat, self.ref_lng, 0, ell=ell_wgs84, deg=True))),
style_function=lambda x: style, tooltip=mkt(tooltip), popup=mkt(tooltip)).add_to(self.m if not group else group)
style_function=lambda x: style, tooltip=mkt(tooltip), popup=mkt(tooltip)).add_to(
self.m if not group else group)

def addPoly(self, geom, tooltip=None, style={'color': 'red', 'lineColor': '#228B22', 'opacity': '1'},group=None):
def addPoly(self, geom, tooltip=None, style={'color': 'red', 'lineColor': '#228B22', 'opacity': '1'}, group=None):
mkt = lambda x: folium.features.Popup(tooltip) if tooltip else None
ff = lambda c: [c[0], c[1]]
g = transform(geom, lambda p: ff(
Expand All @@ -76,12 +78,24 @@ def addPoly(self, geom, tooltip=None, style={'color': 'red', 'lineColor': '#228B
folium.PolyLine(locations=g.coords, tooltip=mkt(tooltip), color=style['color'],
opacity=style['opacity'] if 'opacity' in style else 1).add_to(self.m if not group else group)

def add_marker(self,name,geom,group=None):
ff = lambda c: [c[0], c[1],c[2]]
def add_marker(self, name, geom, group=None):
ff = lambda c: [c[0], c[1], c[2]]
g = transform(geom, lambda p: ff(
pymap3d.enu2geodetic(p[0], p[1], 0, self.ref_lat, self.ref_lng, 0, ell=ell_wgs84, deg=True)))

folium.Marker(location=[c[:-1] for c in g.coords][0], popup=folium.features.Popup(name)).add_to(
self.m if not group else group)

def add_point(self, name, geom, group=None, style={'color': 'red', 'lineColor': '#228B22', 'opacity': '1'}):
ff = lambda c: [c[0], c[1], c[2]]
g = transform(geom, lambda p: ff(
pymap3d.enu2geodetic(p[0], p[1], 0, self.ref_lat, self.ref_lng, 0, ell=ell_wgs84, deg=True)))

folium.Marker(location=[c[:-1] for c in g.coords][0],popup=folium.features.Popup(name)).add_to(self.m if not group else group)
folium.CircleMarker(location=[c[:-1] for c in g.coords][0],
radius=2,
weight=5, color=style['color'],
opacity=style['opacity'] if 'opacity' in style else 1,
popup=folium.features.Popup(name)).add_to(self.m if not group else group)

def create_group(self, name):
return folium.FeatureGroup(name=name).add_to(self.m)
Expand Down

0 comments on commit f1ac2c1

Please sign in to comment.