Here's how you read the CSV, reformat the dates, sort the quakes by date, convert lat/long to x/y/z then output each row as a text object on the outside of a hypothetical sphere (with the object name set to the date of the quake in YYYY-MM-DD format) with the text oriented so that it sits flat on the surface. Fonts and materials and other tweaks to be supplied by you. :)
Based this off https://stackoverflow.com/questions/10473852/convert-latitude-and-longitude-to-point-in-3d-space
# imports to make all the things work
from math import sin, cos, radians, pi, atan, tan
import csv
import bpy
# define some helpful functions for later
# a function to make, scale and rotate text objects into place
def makeathing(coords, scale, lat, long, date):
rotation = (radians(lat - 270), pi, radians(long - 90))
bpy.ops.object.text_add(location=(coords), rotation=(rotation))
ob = bpy.context.object
# set object properties here
ob.data.body = "{:.1f}".format(float(scale))
ob.data.align = 'CENTER'
ob.rotation_mode = 'YXZ'
ob.data.size = 0.03
ob.data.extrude = 0.002
ob.data.name = date
ob.name = date
# a function to turn 3D polar coordinates into 3D cartesian coordinates
def latlonger(lat_deg, lon_deg):
lat = radians(lat_deg)
lon = radians(lon_deg)
# see: http://www.mathworks.de/help/toolbox/aeroblks/llatoecefposition.html
alt = 0.01
rad = 2 # radius of sphere in BUs
f = 0.0 # flattening
ls = atan((1 - f)**2 * tan(lat)) # lambda
x = rad * cos(lat) * cos(lon) + alt * cos(lat) * cos(lon)
y = rad * cos(lat) * sin(lon) + alt * cos(lat) * sin(lon)
z = rad * sin(lat) + alt * sin(lat)
return (x, y, z)
# NB: no code has executed yet, we're just setting up functions we use further down
# read in the CSV file containing quake data
file = csv.reader(open('\\Users\mcsweend2c\Desktop\Bearthquakes 6-9.csv', newline=''), delimiter=',')
# make a blank dict variable to put quake data into
quakes = {}
# iterate through the CSV row by row and pull the data into variables
# then put the variables into a tuple and use a corrected date as the dict key
# see the last line of the for block for data order
# NB: could have used a dict instead of a tuple
# would have meant looking up e.g. quakes[x]['scale'] instead of quakes[x][0]
for idx, (scale, date, lat, lon) in enumerate(file):
(yd, m, dy) = date.split("/")
if int(yd) > int(dy):
year = yd
day = dy
else:
year = dy
day = yd
key = "{}-{:02g}-{:02g}".format( year, int(m), int(day) )
quakes[key] = (scale, lat, lon)
# go through the sorted dates in the quakes dict
# get latitude and longitude and turn into x/y/z coords with latlonger function
# then send x/y/z coordinates to makeathing function to create them in 3D space
for k in sorted(quakes.keys()):
latitude = float(quakes[k][1])
longitude = float(quakes[k][2])
coords = latlonger(latitude, longitude)
makeathing(coords, quakes[k][0], latitude, longitude, k)
You may need to offset the X of the world map texture to align the letters to their correct positions on the globe, e.g. using this texture map I had to offset X by 0.25.
10/08/1997
and1873/12/15
, and it goes backwards in time (which makes sense) $\endgroup$