Code formatting; minor fixes
This commit is contained in:
parent
a9f987c079
commit
85b3742c43
36
qsomap.py
36
qsomap.py
|
@ -140,17 +140,6 @@ def svg_make_inverse_country_path(doc, map_radius, polygon, **kwargs):
|
||||||
def render(ref_lat, ref_lon, output_stream):
|
def render(ref_lat, ref_lon, output_stream):
|
||||||
random.seed(0)
|
random.seed(0)
|
||||||
|
|
||||||
""" Test code
|
|
||||||
test_lat = [np.pi/2, np.pi/4, 0, -np.pi/4, -np.pi/2]
|
|
||||||
test_lon = np.arange(-np.pi, np.pi, np.pi/4)
|
|
||||||
|
|
||||||
for lat in test_lat:
|
|
||||||
for lon in test_lon:
|
|
||||||
x, y = map_azimuthal_equidistant(np.array([lat]), np.array([lon]), np.pi/2, 0)
|
|
||||||
|
|
||||||
print(f"{lat*180/np.pi:6.3f}, {lon*180/np.pi:6.3f} => {x[0]:6.3f}, {y[0]:6.3f}", file=sys.stderr)
|
|
||||||
"""
|
|
||||||
|
|
||||||
print("Loading Geodata…", file=sys.stderr)
|
print("Loading Geodata…", file=sys.stderr)
|
||||||
|
|
||||||
with open('geo-countries/data/countries.geojson', 'r') as jfile:
|
with open('geo-countries/data/countries.geojson', 'r') as jfile:
|
||||||
|
@ -159,11 +148,13 @@ def render(ref_lat, ref_lon, output_stream):
|
||||||
print("Finding boundaries…", file=sys.stderr)
|
print("Finding boundaries…", file=sys.stderr)
|
||||||
|
|
||||||
# key: 3-letter country identifier
|
# key: 3-letter country identifier
|
||||||
# data: {full_name, numpy.array(coordinates), numpy.array(proj_coordinates)}.
|
# data: {full_name,
|
||||||
# coordinates is a list of 2xN arrays, where N is the number of points. Row 0
|
# numpy.array(coordinates),
|
||||||
# contains the longitude, Row 1 the latitude.
|
# numpy.array(proj_coordinates)}.
|
||||||
# proj_coordinates is a list of 2xN arrays, where N is the number of points.
|
# coordinates is a list of 2xN arrays, where N is the number of points.
|
||||||
# Row 0 contains the projected x, Row 1 the projected y.
|
# Row 0 contains the longitude, Row 1 the latitude.
|
||||||
|
# proj_coordinates is a list of 2xN arrays, where N is the number of
|
||||||
|
# points. Row 0 contains the projected x, Row 1 the projected y.
|
||||||
simplegeodata = {}
|
simplegeodata = {}
|
||||||
|
|
||||||
features = geojson['features']
|
features = geojson['features']
|
||||||
|
@ -311,9 +302,10 @@ def render(ref_lat, ref_lon, output_stream):
|
||||||
|
|
||||||
if is_point_in_polygon((antipodal_lon, antipodal_lat),
|
if is_point_in_polygon((antipodal_lon, antipodal_lat),
|
||||||
v['coordinates'][i].T):
|
v['coordinates'][i].T):
|
||||||
print("!!! Found polygon containing the antipodal point!")
|
print("!!! Found polygon containing the antipodal point!",
|
||||||
obj = svg_make_inverse_country_path(doc, R, np.flipud(points), **{
|
file=sys.stderr)
|
||||||
'class': 'country',
|
obj = svg_make_inverse_country_path(doc, R, np.flipud(points),
|
||||||
|
**{'class': 'country',
|
||||||
'fill': color})
|
'fill': color})
|
||||||
else:
|
else:
|
||||||
obj = doc.polygon(points, **{
|
obj = doc.polygon(points, **{
|
||||||
|
@ -328,8 +320,8 @@ def render(ref_lat, ref_lon, output_stream):
|
||||||
# generate equidistant circles
|
# generate equidistant circles
|
||||||
|
|
||||||
d_max = 40075/2
|
d_max = 40075/2
|
||||||
for distance in [500, 1000, 2000, 3000, 4000, 5000, 6000, 8000, 10000, 12000,
|
for distance in [500, 1000, 2000, 3000, 4000, 5000, 6000, 8000, 10000,
|
||||||
14000, 16000, 18000, 20000]:
|
12000, 14000, 16000, 18000, 20000]:
|
||||||
r = R * distance / d_max
|
r = R * distance / d_max
|
||||||
doc.add(doc.circle(center=(R, R), r=r,
|
doc.add(doc.circle(center=(R, R), r=r,
|
||||||
**{'class': 'dist_circle'}))
|
**{'class': 'dist_circle'}))
|
||||||
|
@ -394,7 +386,7 @@ def render(ref_lat, ref_lon, output_stream):
|
||||||
sectorname = chr(ord('A')+x) + chr(ord('A')+y)
|
sectorname = chr(ord('A')+x) + chr(ord('A')+y)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
print(f"Writing output…", file=sys.stderr)
|
print("Writing output…", file=sys.stderr)
|
||||||
doc.write(output_stream, pretty=True)
|
doc.write(output_stream, pretty=True)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue