view cmd/wfs/dump.go @ 5095:e21cbb9768a2

Prevent duplicate fairway areas In principal, there can be only one or no fairway area at each point on the map. Since polygons from real data will often be topologically inexact, just disallow equal geometries. This will also help to avoid importing duplicates with concurrent imports, once the history of fairway dimensions will be preserved.
author Tom Gottfried <tom@intevation.de>
date Wed, 25 Mar 2020 18:10:02 +0100
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)
				}
			}
		}
	}
}