FATHOM5CORP/ais

Build ais.Match examples to remove tugs

Closed this issue · 1 comments

From @zacsketches on November 9, 2018 18:14

Copied from original issue: FATHOM5/Seattle_Reasonable_Track2#17

The example for a notTug ais.Match function is provided in the solution to HACKtheMACHINE Track2, available here:
https://github.com/FATHOM5/Seattle_Reasonable_Track2/blob/master/src/interaction/data_cleaning/main.go
and repeated for convenience here:

// Remove tugs and vessels with no VesselType
	fmt.Println("Removing tugs and vessels with no VesselType...")
	var notTug ais.Match
	typeIndex, ok := rs.Headers().Contains("VesselType")
	if !ok {
		panic("recordset does not contain header VesselType")
	}
	tugSet := make(map[int64]bool)
	for _, t := range []int64{21, 22, 31, 32, 52, 1023, 1025} {
		tugSet[t] = true
	}
	notTug = func(rec *ais.Record) bool {
		// See https://marinecadastre.gov/ais/AIS%20Documents/VesselTypeCodes2018.pdf for
		// vessel type codes that correspond to working boats commonly classed as Tugs.
		if vtString := (*rec)[typeIndex]; vtString == "" {
			return false // will not be included
		}
		vt, err := rec.ParseInt(typeIndex)
		if err != nil {
			panic(err)
		}
		_, ok := tugSet[vt]
		return !ok
	}
	rs, err = rs.Matching(notTug)
	if err != nil {
		panic(err)
	}