view cmd/wfs/dump.go @ 5404:47b12e8308bf marking-single-beam

SR-Upload dialogue migrated towards "surveytype" In order to handle the import of singlebeam profiles of the type "marking" the upload dialogue was chnaged, that there is now the configuration key "survey-type" available, which has the three possible values "single", "multi", marking. This key is present in the meta.json as well. As before unless otherwise specified "multi" is the default type.
author Thomas Junk <thomas.junk@intevation.de>
date Tue, 06 Jul 2021 12:35:57 +0200
parents 2b6f73c30016
children
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 (
	"errors"
	"fmt"
	"io"
	"log"

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

func parseFeatures(user, password string, downloader wfs.Downloader, defaultCRS string) error {

	return downloader.Download(user, password, 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 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)
				}
			}
		}
	}
}