feat: use center coordinates of faces in output filenames
This commit is contained in:
parent
87c76064b7
commit
519f6b2ea9
1 changed files with 23 additions and 2 deletions
25
map.py
25
map.py
|
@ -74,6 +74,8 @@ class Face:
|
|||
def __init__(self, vs):
|
||||
self.vertices = vs
|
||||
self.tris = []
|
||||
avg = np.average(self.vertices, axis=0)
|
||||
self.center = convert_to_spherical(*avg)
|
||||
# Sort vertices so that so that the normal points "outward"
|
||||
if np.dot(self.vertices[0], np.cross(self.vertices[1] - self.vertices[0], self.vertices[2] - self.vertices[0])) < 0:
|
||||
self.vertices = self.vertices[::-1]
|
||||
|
@ -82,6 +84,14 @@ class Face:
|
|||
self.plane_coords = [self.tris[0].plane_coords(v) for v in self.vertices]
|
||||
|
||||
|
||||
def convert_to_spherical(x, y, z):
|
||||
xy = sqrt(x**2+y**2)
|
||||
lon = atan2(z, xy)*180/pi
|
||||
lat = atan2(y, x)*180/pi
|
||||
mag = sqrt(x**2+y**2+z**2)
|
||||
return np.array([lon, lat, mag])
|
||||
|
||||
|
||||
def convert_to_cartesian(lon, lat):
|
||||
x = cos(lon*pi/180)
|
||||
y = sin(lon*pi/180)
|
||||
|
@ -139,7 +149,18 @@ def main(ns):
|
|||
maxy = max(v[1] for v in face.plane_coords)
|
||||
w = maxx - minx
|
||||
h = maxy - miny
|
||||
outfile = ns.out.format(faces=os.path.basename(ns.faces).rsplit('.', 1)[0], geojson=ns.geojson, face=i)
|
||||
formatters = dict(
|
||||
faces=os.path.basename(ns.faces).rsplit('.', 1)[0],
|
||||
geojson=ns.geojson,
|
||||
face=i,
|
||||
lon=face.center[0],
|
||||
lat=face.center[1],
|
||||
mag=face.center[2],
|
||||
ilon=int(face.center[0]),
|
||||
ilat=int(face.center[1]),
|
||||
imag=int(face.center[2]),
|
||||
)
|
||||
outfile = ns.out.format(**formatters)
|
||||
os.makedirs(os.path.dirname(outfile), exist_ok=True)
|
||||
with open(outfile, 'w') as svg:
|
||||
svg.write(f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="{minx} {miny} {w} {h}" width="{w}" height="{h}" id="face{i}">\n')
|
||||
|
@ -163,7 +184,7 @@ if __name__ == '__main__':
|
|||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument('--geojson', '-g', default='countries.geojson')
|
||||
ap.add_argument('--faces', '-f', default='shapes/cube.json')
|
||||
ap.add_argument('--out', '-o', default='faces/{faces}/face{face}.svg')
|
||||
ap.add_argument('--out', '-o', default='faces/{faces}/face{face}_{ilat}_{ilon}.svg')
|
||||
ap.add_argument('--scale', '-s', type=float, default=1)
|
||||
ns = ap.parse_args()
|
||||
main(ns)
|
||||
|
|
Loading…
Reference in a new issue