Example #1
0
func LoadPolygonFromFile(ctx *gin.Context, conn *store.Connection) {

	filename := "./tnassemble.geojson"
	f_coll := new(geojson.FeatureCollection)
	file, _ := os.Open(filename)
	log.Debugf(conn.Context, fmt.Sprintf("file %#v", file))
	jsonParser := json.NewDecoder(file)
	log.Debugf(conn.Context, fmt.Sprintf("jsonParser %#v", jsonParser))
	jsonParser.Decode(&f_coll)
	log.Debugf(conn.Context, fmt.Sprintf("profiles %#v", f_coll))
	for _, feature := range f_coll.Features {
		p := make([]Point, 0)
		constituency := &Constituency{}
		prop := feature.Properties
		constituency.Assemb_Const = prop["ac_name"].(string)
		constituency.Parl_Const = prop["pc_name"].(string)
		constituency.State = prop["state"].(string)
		geom, _ := feature.GetGeometry()
		multiline := geom.GetGeometry()
		mli := multiline.(geojson.MultiLine)
		for _, coord := range mli {
			for _, point := range coord {
				lon := float64(point[0])
				lat := float64(point[1])
				p = append(p, Point{Lat: lat, Lng: lon})
			}
		}
		constituency.Points = p
		conn.Add(constituency)
	}
	file.Close()
}