cinder / Cinder

Cinder is a community-developed, free and open source library for professional-quality creative coding in C++.
http://libcinder.org
Other
5.34k stars 944 forks source link

Earthquake Sample Lat/Lon mismatch to GeoJSON data #2229

Open rogerallen opened 3 years ago

rogerallen commented 3 years ago

Trying out the Earthquake sample, I was confused by where the earthquakes were appearing. I tracked it down to swapped latitude, longitude usage.

In https://github.com/cinder/Cinder/blob/master/samples/Earthquake/src/EarthquakeApp.cpp parseEarthquakes() the code parses the coordinates of the earthquakes via:

auto &coords = feature["geometry"]["coordinates"];

and inserts them like so:

mEarth.addQuake( coords[0].getValue<float>(), coords[1].getValue<float>(), mag, title );

The addQuake routine signature expects coords in the order Lat, Lon

void Earth::addQuake( float aLat, float aLong, float aMag, const std::string &aTitle )

but the earthquake data in GeoJSON is in Lon, Lat order. See: https://earthquake.usgs.gov/earthquakes/feed/v1.0/geojson.php

      geometry: {
        type: "Point",
        coordinates: [
          longitude,
          latitude,
          depth
        ]

swapping the coordinate order to the call fixes this:

mEarth.addQuake( coords[1].getValue<float>(), coords[0].getValue<float>(), mag, title );