Exemplo n.º 1
0
Arquivo: main.go Projeto: xeonx/raster
func main() {
	flag.Parse()

	//Open the data source
	if len(*srcDriver) == 0 {
		*srcDriver = raster.FindDriverName(*src)
	}
	input, err := raster.Open(*srcDriver, *src)
	if err != nil {
		log.Fatal("Open data source: ", err)
	}
	if c, ok := input.(closer); ok {
		defer c.Close()
	}
	var tileReader raster.TileReader
	if len(*srcLayer) > 0 {
		tileReader, err = input.OpenTileLayer(*srcLayer)
	} else {
		tileReader, err = raster.OpenTileLayerAt(input, 0)
	}
	if err != nil {
		log.Fatal("Open layer: ", err)
	}

	log.Print("Connected to data set '", *src, "'")

	//Configure HTTP handlers
	http.Handle("/tiles/", &raster.Server{
		TileReader: tileReader,
		ZeroIsTop:  false,
	})
	http.Handle("/", mapPageHandler{
		Name:   *src,
		Reader: tileReader,
	})

	//Start HTTP server
	log.Print("Starting to listen on ", *addr)
	err = http.ListenAndServe(*addr, nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
Exemplo n.º 2
0
Arquivo: main.go Projeto: xeonx/raster
func main() {
	flag.Parse()

	poly := geos.Must(geos.FromWKT(*aoi))
	bbox, err := geosconverter.GetBoundingBox(poly)
	if err != nil {
		log.Fatal(err)
	}

	//Source
	if len(*srcDriver) == 0 {
		*srcDriver = raster.FindDriverName(*src)
	}
	input, err := raster.Open(*srcDriver, *src)
	if err != nil {
		log.Fatal(err)
	}
	if c, ok := input.(closer); ok {
		defer c.Close()
	}
	var inputReader raster.TileReader
	if len(*srcLayer) > 0 {
		inputReader, err = input.OpenTileLayer(*srcLayer)
	} else {
		inputReader, err = raster.OpenTileLayerAt(input, 0)
	}
	if err != nil {
		log.Fatal(err)
	}

	//Destination
	if len(*dstDriver) == 0 {
		*dstDriver = raster.FindDriverName(*dst)
	}
	outputReader, err := raster.Open(*dstDriver, *dst)
	if err != nil {
		log.Fatal(err)
	}
	output, ok := outputReader.(raster.WritableTileSource)
	if !ok {
		log.Fatal("Output driver does not allow writing")
	}
	if c, ok := output.(closer); ok {
		defer c.Close()
	}
	outputWriter, err := output.CreateTileLayer(*dstLayer)
	if err != nil {
		log.Fatal(err)
	}

	//Initialize the copy
	copier, err := raster.NewCopier(inputReader, outputWriter)
	if err != nil {
		log.Fatal(err)
	}

	polygonFilter := geosconverter.IntersectsFilter(poly)
	if *replace {
		copier.Filter = polygonFilter
	} else {
		copier.Filter = raster.Any(outputWriter.Contains, polygonFilter)
	}

	//Iterate on each requested level and performs the copy
	for level := *lvlmin; level <= *lvlmax; level++ {
		log.Print("Level: ", level)

		if *replace {
			log.Print("Level ", level, " clearing in database")
			err := outputWriter.Clear(level)
			if err != nil {
				log.Fatal(err)
			}
			log.Print("Level ", level, " cleared in database")
		}

		tiles, err := raster.GetTileBlock(bbox, level)
		if err != nil {
			log.Fatal(err)
		}
		log.Print("BBOX (tiles): ", tiles)

		log.Print("Nb tiles in BBOX: ", tiles.Count())

		bar := pb.StartNew(tiles.Count())

		processed, err := copier.CopyBlock(tiles, func(level, x, y int, processed bool) {
			bar.Increment()
		})
		if err != nil {
			log.Fatal(err)
		}
		bar.FinishPrint("End")
		log.Print("Nb tiles processed: ", processed)
	}

}