Last active
June 28, 2020 08:04
-
-
Save ntrel/1958c700ad0af9c05e3a12cf61cfea6b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import std.file; | |
import std.algorithm.iteration; | |
import std.range; | |
import std.conv; | |
void main() | |
{ | |
auto bytes = read("geo_points.txt"); | |
auto s = cast(string)bytes; // avoid Unicode validation of readText | |
double lat_tot = 0; | |
double lon_tot = 0; | |
ulong line_cnt = 0; | |
foreach (line; s.splitter('\n')) | |
{ | |
++line_cnt; | |
auto fields = line.splitter(',').array; | |
lat_tot += fields[0].to!double; | |
lon_tot += fields[1].to!double; | |
} | |
double centroid_lat = lat_tot / line_cnt; | |
double centroid_lon = lon_tot / line_cnt; | |
writefln("Total number of points: %d", line_cnt); | |
writefln("Centroid { lat: %f, lon: %f }", centroid_lat, centroid_lon); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment