Exemplo n.º 1
0
func main() {
	sph := tt.WGS1984()
	rdr := csv.NewReader(os.Stdin)

	xsum, ysum, zsum := 0.0, 0.0, 0.0
	blkcount, popcount := 0, 0

	for rec, err := rdr.Read(); err == nil; rec, err = rdr.Read() {
		slat, slon := rec[1], rec[2]
		spop := rec[3]
		lat, econv := strconv.ParseFloat(slat, 64)
		if econv != nil {
			log.Fatal(econv)
		}
		lon, econv := strconv.ParseFloat(slon, 64)
		if econv != nil {
			log.Fatal(econv)
		}
		pop, econv := strconv.Atoi(spop)
		if econv != nil {
			log.Fatal(econv)
		}

		xyz := sph.Geocentric(tt.LatLon(lat, lon), 0.0)
		blkcount++
		popcount += pop
		xsum += float64(pop) * xyz[0]
		ysum += float64(pop) * xyz[1]
		zsum += float64(pop) * xyz[2]
	}

	xsum /= float64(popcount)
	ysum /= float64(popcount)
	zsum /= float64(popcount)

	latlonm, _ := sph.GeocentricInv(tt.Vec{xsum, ysum, zsum})

	fmt.Printf("%d,%d,%.6f,%.6f\n", popcount, blkcount, latlonm.Lat(), latlonm.Lon())
}
func main() {
	sph := tt.WGS1984()
	rdr := csv.NewReader(os.Stdin)
	ps := make([]tt.Vec, 0, 10000)
	ws := make([]float64, 0, 10000)

	blkcount, popcount := 0, 0

	for rec, err := rdr.Read(); err == nil; rec, err = rdr.Read() {
		slat, slon := rec[1], rec[2]
		spop := rec[3]
		lat, econv := strconv.ParseFloat(slat, 64)
		if econv != nil {
			log.Fatal(econv)
		}
		lon, econv := strconv.ParseFloat(slon, 64)
		if econv != nil {
			log.Fatal(econv)
		}
		pop, econv := strconv.Atoi(spop)
		if econv != nil {
			log.Fatal(econv)
		}

		xyz := sph.Geocentric(tt.LatLon(lat, lon), 0.0)
		blkcount++
		popcount += pop

		ps = append(ps, xyz)
		ws = append(ws, float64(pop))
	}

	median := tt.MedianVecW(ps, ws)
	latlonm, _ := sph.GeocentricInv(median)

	fmt.Printf("%d,%d,%.6f,%.6f\n", popcount, blkcount, latlonm.Lat(), latlonm.Lon())
}
func main() {
	scn := bufio.NewScanner(os.Stdin)
	rec := make([]string, 0)
	for scn.Scan() {
		rec = append(rec, scn.Text())
	}

	p := make([]tt.LL, len(rec))
	for i := range p {
		ri := strings.Split(rec[i], ",")
		slat, slon := ri[5], ri[6]
		var deg, min, sec float64
		var econv error

		deg, econv = strconv.ParseFloat(slat[0:2], 64)
		if econv != nil {
			log.Fatal(econv)
		}
		min, econv = strconv.ParseFloat(slat[2:4], 64)
		if econv != nil {
			log.Fatal(econv)
		}
		sec, econv = strconv.ParseFloat(slat[4:6], 64)
		if econv != nil {
			log.Fatal(econv)
		}
		lat := deg + min/60.0 + sec/3600.0
		if strings.HasSuffix(slat, "S") {
			lat = -lat
		}

		deg, econv = strconv.ParseFloat(slon[0:3], 64)
		if econv != nil {
			log.Fatal(econv)
		}
		min, econv = strconv.ParseFloat(slon[3:5], 64)
		if econv != nil {
			log.Fatal(econv)
		}
		sec, econv = strconv.ParseFloat(slon[5:7], 64)
		if econv != nil {
			log.Fatal(econv)
		}
		lon := deg + min/60.0 + sec/3600.0
		if strings.HasSuffix(slon, "W") {
			lon = -lon
		}

		p[i] = tt.LatLon(lat, lon)
	}

	runtime.GOMAXPROCS(runtime.NumCPU())
	v := make(tt.Vector, len(p))
	sph := tt.WGS1984()
	for i, c := range p {
		tt.ParAndoyer(0, sph, c, p, v)
		onenorm := v.SumAbs()
		fmt.Print(rec[i], ",", onenorm)
		fmt.Println()
	}
}