comparison cmd/wfs/main.go @ 1608:427f9010b4a9

WFS download: Started with GET downloader (paged and unpaged).
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 17 Dec 2018 18:27:57 +0100
parents e80e35b26f17
children f59550310143
comparison
equal deleted inserted replaced
1607:38f91897ca69 1608:427f9010b4a9
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> 12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de>
13 13
14 package main 14 package main
15 15
16 import ( 16 import (
17 "bufio"
18 "flag" 17 "flag"
19 "fmt"
20 "log" 18 "log"
21 "os"
22 19
23 "gemma.intevation.de/gemma/pkg/wfs" 20 "gemma.intevation.de/gemma/pkg/wfs"
24 ) 21 )
25 22
26 func loadCapabilities(fname string) (*wfs.Capabilities, error) {
27 f, err := os.Open(fname)
28 if err != nil {
29 return nil, err
30 }
31 defer f.Close()
32 return wfs.ParseCapabilities(bufio.NewReader(f))
33 }
34
35 func main() { 23 func main() {
24 var (
25 dumpCaps = flag.Bool("dump-caps", false, "Dump capabilities document")
26 featureType = flag.String("features", "ws-wamos:ienc_wtwaxs", "feature to get")
27 )
36 flag.Parse() 28 flag.Parse()
37 29
38 for _, arg := range flag.Args() { 30 for _, arg := range flag.Args() {
39 caps, err := loadCapabilities(arg) 31 caps, err := wfs.GetCapabilities(arg)
40 if err != nil { 32 if err != nil {
41 log.Fatalf("error: %v\n", err) 33 log.Fatalf("error: %v\n", err)
42 } 34 }
35 if *dumpCaps {
36 dump(caps)
37 }
43 38
44 fmt.Println("service identification") 39 if err := wfs.GetFeaturesGET(caps, *featureType); err != nil {
45 fmt.Println("----------------------") 40 log.Fatalf("error: %v\n", err)
46 fmt.Printf("title: %s\n", caps.ServiceIdentification.Title)
47 var abstract string
48 if len(caps.ServiceIdentification.Abstract) > 40 {
49 abstract = fmt.Sprintf("%.40s...", caps.ServiceIdentification.Abstract)
50 } else {
51 abstract = caps.ServiceIdentification.Abstract
52 }
53 fmt.Printf("abstract: %s\n", abstract)
54 if len(caps.ServiceIdentification.Keywords.Keywords) > 0 {
55 fmt.Println("keywords:")
56 for _, kw := range caps.ServiceIdentification.Keywords.Keywords {
57 fmt.Printf("\t%s\n", kw.Value)
58 }
59 }
60 fmt.Printf("type: %s\n", caps.ServiceIdentification.ServiceType)
61 fmt.Printf("version: %s\n", caps.ServiceIdentification.ServiceTypeVersion)
62 fmt.Println()
63 fmt.Println("operations meta data")
64 fmt.Println("--------------------")
65 if len(caps.OperationsMetadata.Operations) > 0 {
66 fmt.Println("operations:")
67 for _, operation := range caps.OperationsMetadata.Operations {
68 fmt.Printf("\t%s\n", operation.Name)
69 if operation.DCP.HTTP.Get != nil {
70 fmt.Printf("\t\tGet: %s\n", operation.DCP.HTTP.Get.HRef)
71 }
72 if operation.DCP.HTTP.Post != nil {
73 fmt.Printf("\t\tPost: %s\n", operation.DCP.HTTP.Post.HRef)
74 }
75
76 if len(operation.Parameters) > 0 {
77 fmt.Println("\t\tparameters:")
78 for _, p := range operation.Parameters {
79 fmt.Printf("\t\t\tparameter: %s\n", p.Name)
80 for _, av := range p.AllowedValues.Values {
81 fmt.Printf("\t\t\t\t%s\n", av.Value)
82 }
83 }
84 }
85 if len(operation.Constraints) > 0 {
86 fmt.Println("\t\tconstraints:")
87 for _, c := range operation.Constraints {
88 fmt.Printf("\t\t\tname: %s\n", c.Name)
89 if c.DefaultValue != nil {
90 fmt.Printf("\t\t\t\tdefault: %s\n", c.DefaultValue.Value)
91 }
92 if len(c.AllowedValues.Values) > 0 {
93 fmt.Println("\t\t\tallowed values:")
94 for _, av := range c.AllowedValues.Values {
95 fmt.Printf("\t\t\t\t%s", av.Value)
96 }
97 }
98 }
99 }
100 }
101 }
102 if len(caps.OperationsMetadata.Constraints) > 0 {
103 fmt.Println("constraints:")
104 for _, c := range caps.OperationsMetadata.Constraints {
105 fmt.Printf("\tname: %s\n", c.Name)
106 if c.DefaultValue != nil {
107 fmt.Printf("\t\tdefault: %s\n", c.DefaultValue.Value)
108 }
109 if len(c.AllowedValues.Values) > 0 {
110 fmt.Println("\tallowed values:")
111 for _, av := range c.AllowedValues.Values {
112 fmt.Printf("\t\t%s\n", av.Value)
113 }
114 }
115 }
116 }
117 fmt.Println()
118 fmt.Println("feature type list")
119 fmt.Println("------------------")
120 if len(caps.FeatureTypeList.FeatureTypes) > 0 {
121 fmt.Println("features:")
122 for _, ft := range caps.FeatureTypeList.FeatureTypes {
123 fmt.Printf("\tname: %s\n", ft.Name)
124 fmt.Printf("\ttitle: %s\n", ft.Title)
125 var abstract string
126 if len(ft.Abstract) > 40 {
127 abstract = fmt.Sprintf("%.40s...", ft.Abstract)
128 } else {
129 abstract = ft.Abstract
130 }
131 fmt.Printf("\tabstract: %s\n", abstract)
132 fmt.Printf("\tdefault CRS: %s\n", ft.DefaultCRS)
133 if len(ft.OtherCRSs) > 0 {
134 fmt.Println("\tother CRSs:")
135 for _, crs := range ft.OtherCRSs {
136 fmt.Printf("\t\t%s\n", crs)
137 }
138 }
139 if ft.WGS84BoundingBox != nil {
140 fmt.Printf("\tWGS84 bounding box: (%s) - (%s)\n",
141 ft.WGS84BoundingBox.LowerCorner, ft.WGS84BoundingBox.UpperCorner)
142 }
143 if len(ft.Keywords.Keywords) > 0 {
144 fmt.Println("\tkeywords:")
145 for _, kw := range ft.Keywords.Keywords {
146 fmt.Printf("\t\t%s\n", kw.Value)
147 }
148 }
149 if len(ft.Namespaces) > 0 {
150 fmt.Println("\tnamespaces:")
151 for _, ns := range ft.Namespaces {
152 fmt.Printf("\t\t%s:%s\n", ns.Space, ns.Local)
153 }
154 }
155 }
156 } 41 }
157 } 42 }
158 } 43 }