Example #1
0
func processGeohash(arg string) (string, error) {
	box, err := geohash.Decode(arg)
	if err != nil {
		return "", err
	}

	var p geohash.Point
	if flagRound {
		p = box.Round()
	} else {
		p = box.Center()
	}

	return fmt.Sprintf("%v,%v", p.Lat, p.Lon), nil
}
Example #2
0
func compute_bulk_geohash(polygon_arr []string, uuids []string, bbox_arr []string, feature_types []string, url_names []string, names []string, init_val, end_val, precision int) int {
	count := 0
	var val bool
	counter := 0
	client := redis.NewClient(&redis.Options{
		Addr:     "localhost:6379",
		Password: "", // no password set
		DB:       0,  // use default DB
	})
	for index, bbox := range bbox_arr {
		geoPoly := compute_polygon_from_string(polygon_arr[index])
		bbox_coords := compute_array_points(bbox, init_val, end_val)
		current_uuid := uuids[index]
		current_polygon := polygon_arr[index]
		current_feature_type := feature_types[index]
		current_url_name := url_names[index]
		current_name := names[index]
		bbox_new := compute_bbox(bbox_coords)
		coverage := cover_bounding_box(bbox_new.top_left_lat, bbox_new.top_left_lon, bbox_new.bottom_left_lat, bbox_new.bottom_left_lon, precision)
		count = coverage.count
		var new_bboxes []string
		for _, hash := range coverage.hashes {
			box, _ := geohash.Decode(hash)
			bbox_hash := &BBox{box.Lat.Max, box.Lon.Min, box.Lat.Min, box.Lon.Max}
			val = IntersectsBBox(geoPoly, bbox_hash)
			// fmt.Println(hash)
			if val {
				// fmt.Println(hash)
				redis_value := fmt.Sprintf("%s::%s::%s::%s::%s::&&", current_uuid, current_feature_type, current_polygon, current_url_name, current_name)
				client.RPush(hash, redis_value)
				// client.RPush(current_uuid,hash)
				// fmt.Println(result)
				counter += 1
				new_bboxes = append(new_bboxes, hash)
			}
		}
		coverage.hashes = new_bboxes
		// if current_uuid == "f7f5d7f50dde9452144e" {
		// 	fmt.Println("Precision ==>", current_uuid,precision,coverage.hashes)
		// }
	}
	fmt.Println(counter)
	return count
}