Skip to content

Commit

Permalink
added field center markers
Browse files Browse the repository at this point in the history
  • Loading branch information
lausdahl committed Oct 9, 2023
1 parent 81a2fa1 commit 4a57c7f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 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.1.13', # Required
version='1.2.0', # Required

# This is a one-line description or tagline of what your project does. This
# corresponds to the "Summary" metadata field:
Expand Down
15 changes: 13 additions & 2 deletions src/isoxmlviz/visualize.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from descartes.patch import PolygonPatch
from matplotlib import pyplot as plt
from matplotlib.collections import PatchCollection, LineCollection
from shapely.geometry import LineString, JOIN_STYLE, MultiLineString
from shapely.geometry import LineString, JOIN_STYLE, MultiLineString, MultiPoint
import math
from isoxmlviz.LineStringUtil import extract_lines_within
from isoxmlviz.webmap import WebMap
Expand Down Expand Up @@ -135,11 +135,13 @@ def show_task_file(version_prefix, name, tree, save_pdf: bool = False, save_svg:
fig, axes = plt.subplots(nrows=round(len(part_fields) / cols), ncols=cols)
part_fields_ax = zip(axes.flat, part_fields)

field_marker_group =web_map.create_group("Field names")
for (ax, pfd) in part_fields_ax:
if use_subplot:
ax.title.set_text(pfd.attrib.get("C"))
plot_all_pln(ax, parent_map, web_map, ref, pfd)
plot_all_lsg(ax, parent_map, web_map, ref, pfd, gpn_filter=gpn_filter)
plot_center_name(name,pfd,ref,web_map,group=field_marker_group)

ax.axis("equal")
ax.axis("off")
Expand All @@ -160,6 +162,15 @@ def show_task_file(version_prefix, name, tree, save_pdf: bool = False, save_svg:
plt.cla()
plt.clf()

def plot_center_name(name, pfd,ref,web_map,group=None):
points_elements = pfd.findall('.//PNT')
if len(points_elements) == 0:
return
point_data = [pnt_to_pair(pelement) for pelement in points_elements]
points = [pymap3d.geodetic2enu(p[0], p[1], 0, ref[0], ref[1], 0, ell=ell_wgs84, deg=True) for p in
point_data]
field_name= str( pfd.attrib.get("C"))
web_map.add_marker(name+' '+field_name,MultiPoint( points).centroid,group=group)

def get_line_points(ref, line: ET.ElementTree):
points_elements = line.findall('./PNT')
Expand Down Expand Up @@ -187,7 +198,7 @@ def get_polygon(ref, pln):

def plot_all_pln(ax, parent_map, web_map, ref, root):
for pln in root.findall(".//PLN"):
designator = pln.attrib.get("B")
designator = pln.attrib.get("C")
print("Processing line '%s'" % designator)

polygon = get_polygon(ref, pln)
Expand Down
13 changes: 12 additions & 1 deletion src/isoxmlviz/webmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

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 @@ -14,8 +16,11 @@ def transform(shape, func):
parts = [transform(geom, func) for geom in shape.geoms]
return construct(parts)

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


if shape.type == 'Polygon':
exterior = map(func, shape.exterior.coords)
Expand Down Expand Up @@ -71,6 +76,12 @@ 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]]
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 create_group(self, name):
return folium.FeatureGroup(name=name).add_to(self.m)
Expand Down

0 comments on commit 4a57c7f

Please sign in to comment.