Skip to content

Instantly share code, notes, and snippets.

@apcj
Last active August 29, 2015 14:02
Show Gist options
  • Save apcj/0e5dd0b69723ee2178a5 to your computer and use it in GitHub Desktop.
Save apcj/0e5dd0b69723ee2178a5 to your computer and use it in GitHub Desktop.
World cup country Geo location
MATCH (c1:Country)
MATCH (c2:Country)
WHERE c1 <> c2
WITH c1, c2, 2 * 6371 * asin(sqrt(haversin(radians(c1.lat - c2.lat))+ cos(radians(c1.lat))*
cos(radians(c2.lat))* haversin(radians(c1.lon - c2.lon)))) AS dist
WHERE dist > 0
RETURN c1.name, c2.name, dist
ORDER BY dist
LIMIT 1000
LOAD CSV WITH HEADERS FROM "http://techslides.com/demos/country-capitals.csv" AS line
WITH line, CASE line.CountryName
WHEN 'South Korea' THEN ['Korea Republic']
WHEN 'United Kingdom' THEN ['England', 'Scotland', 'Wales']
WHEN 'United States' THEN ['USA']
WHEN "Cote d'Ivoire" THEN ["Côte d'Ivoire"]
WHEN 'North Korea' THEN ['Korea DPR']
WHEN 'Serbia' THEN ['Serbia and Montenegro', 'Yugoslavia']
WHEN 'Japan' THEN ['Korea/Japan']
WHEN 'China' THEN ['China PR']
WHEN 'Ireland' THEN ['Republic of Ireland', 'Northern Ireland']
WHEN 'Russia' THEN ['Soviet Union']
WHEN 'Germany' THEN ['Germany FR', 'German DR']
WHEN 'Czech Republic' THEN ['Czechoslovakia']
WHEN 'Republic of Congo' THEN ['Zaire']
WHEN 'Indonesia' THEN ['Dutch East Indies']
END as countryNames
MATCH (country:Country)
WHERE country.name IN countryNames OR country.name = line.CountryName
// data is screwed up for United States, because captial city field contains a comma!
SET country.lon = toFloat(CASE line.CountryName WHEN 'United States' THEN line.CountryCode ELSE line.CapitalLongitude END)
SET country.lat = toFloat(CASE line.CountryName WHEN 'United States' THEN line.CapitalLongitude ELSE line.CapitalLatitude END)
RETURN count(country)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment