예제 #1
0
파일: polygon.go 프로젝트: sankark/kyp
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()
}
예제 #2
0
파일: polygon.go 프로젝트: sankark/kyp
func PointInPolygon(ctx *gin.Context, conn *store.Connection, lat float64, lon float64) store.Response {

	chans := make([]<-chan int64, 0)
	search := geo.NewPoint(lat, lon)
	resp := conn.ListKeys(Constituency{})
	keys := resp.Data.([]*datastore.Key)
	for _, k := range keys {
		if Cache[k.IntID()] == nil {
			con := &Constituency{Id: k.IntID()}
			resp = conn.Get(con)
			Cache[k.IntID()] = BuildPolygon(con)
		}
		chans = append(chans, Process(k.IntID(), search))
	}
	resp.Data = new(map[string]string)
	for n := range merge(chans) {
		if n != 0 {
			con := &Constituency{Id: n}
			resp = conn.Get(con)
			con.Points = nil
			resp.Data = con
		}
	}
	return resp
}