updated input map generation

I made a map for Nutopia's "Pole to pole" and it involved cleaning up some of this old code.  I may have broken the graticules; I didn't test ti.
This commit is contained in:
Justin Kunimune 2022-12-17 20:38:24 -10:00
parent d78764aa0d
commit eaaadbb188
3 changed files with 40 additions and 12 deletions

View File

@ -14,7 +14,7 @@ from generate_labels import generate_topographical_labels, label_shapes, label_p
def compose_landmasses():
print('\t<g transform="matrix(1,0,0,-1,180,90)">')
print('\t\t<g class="land">')
plot_shapes('ne_50m_land', trim_antarctica=True)
plot_shapes('ne_50m_land', trim_antarctica=True, mark_antarctica=True)
print('\t\t</g>')
print('\t\t<g class="water">')
plot_shapes('ne_50m_lakes', max_rank=4)
@ -38,7 +38,7 @@ def compose_graticule2():
def compose_compound():
print('\t<g transform="matrix(1,0,0,-1,180,90)">')
print('\t\t<g class="land">')
plot_shapes('ne_50m_land', trim_antarctica=True)
plot_shapes('ne_50m_land', trim_antarctica=True, mark_antarctica=True)
print('\t\t</g>')
print('\t\t<g class="river">')
plot_shapes('ne_50m_rivers_lake_centerlines', max_rank=4)
@ -51,6 +51,25 @@ def compose_compound():
print('\t\t</g>')
print('\t</g>')
def compose_poster():
print('\t<g transform="matrix(1,0,0,-1,180,90)">')
print('\t\t<g class="ice">')
plot_shapes('ne_50m_antarctic_ice_shelves_polys')
print('\t\t</g>')
print('\t\t<g class="land">')
plot_shapes('ne_50m_land', trim_antarctica=True, mark_antarctica=True)
print('\t\t</g>')
print('\t\t<g class="river">')
plot_shapes('ne_50m_rivers_lake_centerlines', max_rank=4)
print('\t\t</g>')
print('\t\t<g class="lakes">')
plot_shapes('ne_50m_lakes', max_rank=4)
print('\t\t</g>')
print('\t\t<g class="graticule">')
generate_graticule(10, 1, include_tropics=True, adjust_poles=True)
print('\t\t</g>')
print('\t</g>')
def compose_indicatrices():
print('\t<g transform="matrix(1,0,0,-1,180,90)">')
print('\t\t<g class="land">')
@ -144,8 +163,9 @@ if __name__ == '__main__':
# compose_landmasses()
# compose_graticule()
# compose_compound()
compose_poster()
# compose_indicatrices()
# compose_indicatrices2(-0)
# compose_political()
# compose_orthodromes()
compose_everything()
# compose_everything()

View File

@ -24,8 +24,9 @@ def generate_graticule(spacing, granularity, include_tropics=False, adjust_poles
if adjust_poles: #if this is True, reduce the number of meridians as you approach the pole
old_num = 1
for p in range(0, 90, spacing):
new_num = old_num*int(1/math.cos(math.radians(p+spacing/2))/old_num)
while NUM_BASE%new_num != 0: new_num -= 1
new_num = 2*old_num*int(1/math.cos(math.radians(p+spacing/2))/old_num)
while NUM_BASE%new_num != 0:
new_num -= 1
if new_num >= 2*old_num:
for i in range(len(cuts)):
if i%old_num == 0 and i%new_num != 0:

View File

@ -5,7 +5,7 @@ import shapefile
from helpers import plot, trim_edges, lengthen_edges
def plot_shapes(filename, max_rank=float('inf'), clazz=None, trim_antarctica=False, flesh_out_antarctica=False, filter_field=None, filter_vals=['']):
def plot_shapes(filename, max_rank=float('inf'), clazz=None, trim_antarctica=False, flesh_out_antarctica=False, mark_antarctica=False, filter_field=None, filter_vals=['']):
"""data from http://www.naturalearthdata.com/"""
sf = shapefile.Reader("shapefiles/{}".format(filename))
rank_idx, filter_idx = None, None
@ -17,12 +17,19 @@ def plot_shapes(filename, max_rank=float('inf'), clazz=None, trim_antarctica=Fal
for record, shape in zip(sf.records(), sf.shapes()):
if filter_idx is not None and record[filter_idx] not in filter_vals:
continue # skip it if it is filtered out
if rank_idx is None or record[rank_idx] <= max_rank:
if trim_antarctica:
if shape.points[0][1] < -60: #if it is Antarctica (this will have a few false positives, but that's fine)
if len(shape.points) == 0:
continue # skip it if it is empty
if rank_idx is None or record[rank_idx] is None or record[rank_idx] <= max_rank:
clazz_for_this_section = clazz
if shape.points[0][1] < -60: #if it is Antarctica (this will have a few false positives, but that's fine)
if trim_antarctica:
shape.points = trim_edges(shape.points, shape.parts)
elif flesh_out_antarctica:
if shape.points[0][1] < -60:
elif flesh_out_antarctica:
shape.points = lengthen_edges(shape.points)
if mark_antarctica:
if clazz_for_this_section is None:
clazz_for_this_section = "antarctic"
elif "antarctic" not in clazz_for_this_section:
clazz_for_this_section += " antarctic"
plot(shape.points, midx=shape.parts, close=False, clazz=clazz, fourmat='xd')
plot(shape.points, midx=shape.parts, close=False, clazz=clazz_for_this_section, fourmat='xd')