Ejemplo n.º 1
0
Archivo: main.go Proyecto: fg1/mugiss
func main() {
	daddr, err := net.ResolveTCPAddr("tcp", "0.0.0.0:8080")
	if err != nil {
		log.Fatal(err)
	}

	options := struct {
		CityFiles     []string      `goptions:"-d, description='Data files to load'"`
		CountryNames  string        `goptions:"-c, description='CSV file holding country names'"`
		CountryShapes string        `goptions:"-c, description='CSV file holding country shapes'"`
		Help          goptions.Help `goptions:"-h, --help, description='Show this help'"`
		ListenAddr    *net.TCPAddr  `goptions:"-l, --listen, description='Listen address for HTTP server'"`
	}{
		CountryNames:  "data/countries_en.csv",
		CountryShapes: "data/countries.csv.bz2",
		ListenAddr:    daddr,
	}
	goptions.ParseAndFail(&options)

	rt_countries = rtreego.NewTree(2, 10, 20)
	_, err = load_freegeodb_countries_csv(rt_countries, options.CountryShapes)
	if err != nil {
		log.Fatal(err)
	}

	countries_exp, err = load_country_names(options.CountryNames)
	if err != nil {
		log.Fatal(err)
	}

	rt = rtreego.NewTree(2, 25, 50)
	total_loaded_cities := 0
	start_t := time.Now()
	for _, fname := range options.CityFiles {
		loaded, err := load_gisgraphy_cities_csv(rt, fname)
		if err != nil {
			log.Fatal(err)
		}
		total_loaded_cities += loaded
	}
	if total_loaded_cities > 0 {
		log.Println("Loaded", total_loaded_cities, "cities in", time.Now().Sub(start_t))
	}

	log.Println("Starting HTTP server on", options.ListenAddr)
	http.HandleFunc("/rg/", reverseGeocodingHandler)
	http.HandleFunc("/gj/", serveGeoJson)
	http.Handle("/", http.FileServer(http.Dir("html")))
	err = http.ListenAndServe(options.ListenAddr.String(), nil)
	if err != nil {
		log.Fatal(err)
	}
}
Ejemplo n.º 2
0
func NewPointInPolygon(source string, cache_size int, cache_trigger int, logger *log.WOFLogger) (*WOFPointInPolygon, error) {

	rtree := rtreego.NewTree(2, 25, 50)

	cache, err := lru.New(cache_size)

	if err != nil {
		return nil, err
	}

	metrics := NewPointInPolygonMetrics()

	placetypes := make(map[string]int)

	pip := WOFPointInPolygon{
		Rtree:        rtree,
		Source:       source,
		Cache:        cache,
		CacheSize:    cache_size,
		CacheTrigger: cache_trigger,
		Placetypes:   placetypes,
		Metrics:      metrics,
		Logger:       logger,
	}

	return &pip, nil
}
Ejemplo n.º 3
0
func PointInPolygon(source string) *WOFPointInPolygon {

	rt := rtreego.NewTree(2, 25, 50)

	return &WOFPointInPolygon{
		Rtree:  rt,
		Source: source,
	}
}
Ejemplo n.º 4
0
func NewTree(MinChildren, MaxChildren int) *Tree {
	tree := Tree{}
	tree.Rtree = rtreego.NewTree(2, MinChildren, MaxChildren)
	tree.Mutex = sync.RWMutex{}
	tree.dim = 2 //only 2-dim is supported
	tree.minChildren = MinChildren
	tree.maxChildren = MaxChildren

	return &tree
}
Ejemplo n.º 5
0
func (_ Test) RTree() {
	calcSetup()
	rt := rtreego.NewTree(2, 25, 50)

	points := []*Somewhere{
		{rtreego.Point{55.711311, 9.536354}, "Vejle", 1},
		{rtreego.Point{57.725004, 10.579186}, "Skagen", 1},
		{rtreego.Point{56.162939, 10.203921}, "Århus", 1},
		{rtreego.Point{56.315499, 10.317270}, "Hornslet", 2},
		{rtreego.Point{56.363358, 10.235109}, "Hønebjergvej 31", 3},
		{rtreego.Point{56.460584, 10.036539}, "Randers", 4},
		{rtreego.Point{56.037247, 9.929799}, "Skanderborg", 5},
		{rtreego.Point{56.176362, 9.554922}, "Silkeborg", 6},
		{rtreego.Point{55.728449, 9.112366}, "Billund", 7},
	}

	for i := range points {
		rt.Insert(points[i])
	}
	rt.Delete(points[0])

	// Get a slice of the k objects in rt closest to q:
	here := points[3]
	num := rt.Size()
	results := rt.NearestNeighbors(num, here.location) // num must be less or equal to the size of the RTree
	e.InfoLog.Println("\nHvad er nærmest", here.name, ":")
	for i := range results {
		there := results[i].(*Somewhere)
		distance := calcDist(here.location, there.location)
		rounded := RoundPlus(distance, 1)
		Int := int(rounded * 10)

		km, remainder := Int/10, Int%10
		str := conv.String(km) + "." + conv.String(remainder)

		e.InfoLog.Println(i, ": ", there.name, ". Afstand: ", str, "full: ", RoundPlus(distance, 4))
	}
}
Ejemplo n.º 6
0
func NewIndex(source string, cache_size int, cache_trigger int, logger *log.WOFLogger) (*WOFIndex, error) {

	rtree := rtreego.NewTree(2, 25, 50)

	cache, err := lru.New(cache_size)

	if err != nil {
		return nil, err
	}

	placetypes := make(map[string]int)

	idx := WOFIndex{
		RTree:        rtree,
		Source:       source,
		Cache:        cache,
		CacheSize:    cache_size,
		CacheTrigger: cache_trigger,
		Placetypes:   placetypes,
		Logger:       logger,
	}

	return &idx, nil
}