view pkg/wfs/global.go @ 2703:c887666b110f

import_overview: increase log fontsize. errors in log are marked red
author Thomas Junk <thomas.junk@intevation.de>
date Mon, 18 Mar 2019 15:49:41 +0100
parents d7ef169fd0d3
children 3956de9b6b32
line wrap: on
line source

// This is Free Software under GNU Affero General Public License v >= 3.0
// without warranty, see README.md and license for details.
//
// SPDX-License-Identifier: AGPL-3.0-or-later
// License-Filename: LICENSES/AGPL-3.0.txt
//
// Copyright (C) 2019 by via donau
//   – Österreichische Wasserstraßen-Gesellschaft mbH
// Software engineering by Intevation GmbH
//
// Author(s):
//  * Sascha L. Teichmann <sascha.teichmann@intevation.de>

package wfs

import (
	"io"
	"log"
	"os/exec"
)

var (
	FormatGeoJSON = []string{"geojson", "application/json"}
	FormatGML     = []string{
		"gml2", "gml3", "gml32",
		"text/xml; subtype=gml/2.1.2",
		"text/xml; subtype=gml/3.1.1",
		"text/xml; subtype=gml/3.2",
	}
)

type (
	Downloader interface {
		Download(handler func(string, io.Reader) error) error
	}

	GeoJSONDownloader []string
	GMLDownloader     []string
)

var GetFeatures = setup()

func setup() func(*Capabilities, string, string) (Downloader, error) {
	path, err := exec.LookPath("ogr2ogr")
	if err != nil {
		log.Println("info: ogr2ogr not installed. Using direct GeoJSON WFS download.")
		return GetFeaturesGeoJSON
	}
	log.Printf("info: ogr2ogr found at %s. Using GML WFS download.\n", path)
	return GetFeaturesGML
}

func GetFeaturesGeoJSON(
	caps *Capabilities,
	featureTypeName string,
	sortBy string,
) (Downloader, error) {
	urls, err := GetFeaturesGET(
		caps,
		featureTypeName,
		FormatGeoJSON,
		sortBy)
	return GeoJSONDownloader(urls), err
}

func GetFeaturesGML(
	caps *Capabilities,
	featureTypeName string,
	sortBy string,
) (Downloader, error) {
	urls, err := GetFeaturesGET(
		caps,
		featureTypeName,
		FormatGML,
		sortBy)
	return GMLDownloader(urls), err
}

func (gjd GeoJSONDownloader) Download(handler func(string, io.Reader) error) error {
	return DownloadURLs([]string(gjd), handler)
}

func (gmd GMLDownloader) Download(handler func(string, io.Reader) error) error {
	// TODO: Implement, me!
	return nil
}