Skip to content

Instantly share code, notes, and snippets.

@vvzen
Last active August 26, 2017 21:09
Show Gist options
  • Save vvzen/4f1d7e8b68ad637fdd6c691372e606dd to your computer and use it in GitHub Desktop.
Save vvzen/4f1d7e8b68ad637fdd6c691372e606dd to your computer and use it in GitHub Desktop.
# see https://en.wikipedia.org/wiki/Spherical_coordinate_system
def spherical_to_cartesian(lat, lon, radius):
latitude = math.radians(lat)
longitude = math.radians(lon)
x = radius * math.sin(latitude) * math.cos(longitude)
y = radius * math.sin(latitude) * math.sin(longitude)
z = radius * math.cos(latitude)
return x, y, z
''' example from the geojson dataset:
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { "osm_id": "4245316", "code": 5115, "fclass": "tertiary", "name": "Corso Vittorio Emanuele II", "ref": null, "oneway": "F", "maxspeed": 50, "layer": "0", "bridge": "F", "tunnel": "F" }, "geometry": { "type": "MultiLineString", "coordinates": [ [ [ 12.4664084, 41.8995935 ], [ 12.4662495, 41.8997611 ] ] ] } },
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment