view cmd/wfs/dump.go @ 2624:9dbaf69c7a66

Improve geoserver config to better calculate bounding boxes * Disable the use of estimated extents for the postgis storage configuration for geoserver, which is set via the gemma middleware. This way we are able to get better bounding boxes for many layers where the postgis function `ST_EstimatedExtent()` would be far off.
author Bernhard Reiter <bernhard@intevation.de>
date Wed, 13 Mar 2019 16:18:39 +0100
parents 2b72f5e005aa
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) 2018 by via donau
//   – Österreichische Wasserstraßen-Gesellschaft mbH
// Software engineering by Intevation GmbH
//
// Author(s):
//  * Sascha L. Teichmann <sascha.teichmann@intevation.de>

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"log"
	"os"

	"gemma.intevation.de/gemma/pkg/wfs"
)

func parseFeatures(urls []string, defaultCRS string) error {

	return wfs.DownloadURLs(urls, func(url string, r io.Reader) error {
		log.Printf("Get features from: '%s'\n", url)
		rfc, err := wfs.ParseRawFeatureCollection(r)
		if err != nil {
			return err
		}
		var crsName string
		if rfc.Features == nil {
			return errors.New("no features given")
		}
		if rfc.CRS != nil {
			crsName = rfc.CRS.Properties.Name
		} else {
			crsName = defaultCRS
		}
		fmt.Printf("CRS: %s\n", crsName)
		epsg, err := wfs.CRSToEPSG(crsName)
		if err != nil {
			log.Printf("error: %v\n", err)
		} else {
			fmt.Printf("EPSG: %d\n", epsg)
		}
		types := map[string]int{}
		for _, feature := range rfc.Features {
			types[feature.Geometry.Type]++
		}
		fmt.Printf("found types in %d features:\n", len(rfc.Features))
		for typ, cnt := range types {
			fmt.Printf("\t%s: %d\n", typ, cnt)
		}
		return nil
	})
}

func dumpURLs(urls []string) error {
	out := bufio.NewWriter(os.Stdout)
	if err := wfs.DownloadURLs(urls, func(url string, r io.Reader) error {
		log.Printf("Get features from: '%s'\n", url)
		_, err := io.Copy(out, r)
		return err
	}); err != nil {
		return err
	}
	return out.Flush()
}

func dump(caps *wfs.Capabilities) {
	fmt.Println("service identification")
	fmt.Println("----------------------")
	fmt.Printf("title: %s\n", caps.ServiceIdentification.Title)
	var abstract string
	if len(caps.ServiceIdentification.Abstract) > 40 {
		abstract = fmt.Sprintf("%.40s...", caps.ServiceIdentification.Abstract)
	} else {
		abstract = caps.ServiceIdentification.Abstract
	}
	fmt.Printf("abstract: %s\n", abstract)
	if len(caps.ServiceIdentification.Keywords.Keywords) > 0 {
		fmt.Println("keywords:")
		for _, kw := range caps.ServiceIdentification.Keywords.Keywords {
			fmt.Printf("\t%s\n", kw.Value)
		}
	}
	fmt.Printf("type: %s\n", caps.ServiceIdentification.ServiceType)
	fmt.Printf("version: %s\n", caps.ServiceIdentification.ServiceTypeVersion)
	fmt.Println()
	fmt.Println("operations meta data")
	fmt.Println("--------------------")
	if len(caps.OperationsMetadata.Operations) > 0 {
		fmt.Println("operations:")
		for _, operation := range caps.OperationsMetadata.Operations {
			fmt.Printf("\t%s\n", operation.Name)
			if operation.DCP.HTTP.Get != nil {
				fmt.Printf("\t\tGet: %s\n", operation.DCP.HTTP.Get.HRef)
			}
			if operation.DCP.HTTP.Post != nil {
				fmt.Printf("\t\tPost: %s\n", operation.DCP.HTTP.Post.HRef)
			}

			if len(operation.Parameters) > 0 {
				fmt.Println("\t\tparameters:")
				for _, p := range operation.Parameters {
					fmt.Printf("\t\t\tparameter: %s\n", p.Name)
					for _, av := range p.AllowedValues.Values {
						fmt.Printf("\t\t\t\t%s\n", av.Value)
					}
				}
			}
			if len(operation.Constraints) > 0 {
				fmt.Println("\t\tconstraints:")
				for _, c := range operation.Constraints {
					fmt.Printf("\t\t\tname: %s\n", c.Name)
					if c.DefaultValue != nil {
						fmt.Printf("\t\t\t\tdefault: %s\n", c.DefaultValue.Value)
					}
					if len(c.AllowedValues.Values) > 0 {
						fmt.Println("\t\t\tallowed values:")
						for _, av := range c.AllowedValues.Values {
							fmt.Printf("\t\t\t\t%s", av.Value)
						}
					}
				}
			}
		}
	}
	if len(caps.OperationsMetadata.Constraints) > 0 {
		fmt.Println("constraints:")
		for _, c := range caps.OperationsMetadata.Constraints {
			fmt.Printf("\tname: %s\n", c.Name)
			if c.DefaultValue != nil {
				fmt.Printf("\t\tdefault: %s\n", c.DefaultValue.Value)
			}
			if len(c.AllowedValues.Values) > 0 {
				fmt.Println("\tallowed values:")
				for _, av := range c.AllowedValues.Values {
					fmt.Printf("\t\t%s\n", av.Value)
				}
			}
		}
	}
	fmt.Println()
	fmt.Println("feature type list")
	fmt.Println("------------------")
	if len(caps.FeatureTypeList.FeatureTypes) > 0 {
		fmt.Println("features:")
		for _, ft := range caps.FeatureTypeList.FeatureTypes {
			fmt.Printf("\tname: %s\n", ft.Name)
			fmt.Printf("\ttitle: %s\n", ft.Title)
			var abstract string
			if len(ft.Abstract) > 40 {
				abstract = fmt.Sprintf("%.40s...", ft.Abstract)
			} else {
				abstract = ft.Abstract
			}
			fmt.Printf("\tabstract: %s\n", abstract)
			fmt.Printf("\tdefault CRS: %s\n", ft.DefaultCRS)
			if len(ft.OtherCRSs) > 0 {
				fmt.Println("\tother CRSs:")
				for _, crs := range ft.OtherCRSs {
					fmt.Printf("\t\t%s\n", crs)
				}
			}
			if ft.WGS84BoundingBox != nil {
				fmt.Printf("\tWGS84 bounding box: (%s) - (%s)\n",
					ft.WGS84BoundingBox.LowerCorner, ft.WGS84BoundingBox.UpperCorner)
			}
			if len(ft.Keywords.Keywords) > 0 {
				fmt.Println("\tkeywords:")
				for _, kw := range ft.Keywords.Keywords {
					fmt.Printf("\t\t%s\n", kw.Value)
				}
			}
			if len(ft.Namespaces) > 0 {
				fmt.Println("\tnamespaces:")
				for _, ns := range ft.Namespaces {
					fmt.Printf("\t\t%s:%s\n", ns.Space, ns.Local)
				}
			}
		}
	}
}