From 827e6a3dbf6c27dd67d01ca81232e28397be0a5d Mon Sep 17 00:00:00 2001 From: edisonguo Date: Thu, 25 Apr 2019 12:27:35 +1000 Subject: [PATCH] added support for specifying geometry id as wps input (#264) --- ows.go | 12 +++++++++++- templates/WPS_DescribeProcess.tpl | 4 ++++ utils/wps.go | 8 ++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/ows.go b/ows.go index 073ede9b..881fab55 100644 --- a/ows.go +++ b/ows.go @@ -1049,7 +1049,17 @@ func serveWPS(ctx context.Context, params utils.WPSParams, conf *utils.Config, r ctx, ctxCancel := context.WithCancel(ctx) defer ctxCancel() errChan := make(chan error, 100) - suffix := fmt.Sprintf("_%04d", rand.Intn(1000)) + + var suffix string + if params.GeometryId != nil { + geoId := strings.TrimSpace(*params.GeometryId) + if len(geoId) > 0 { + suffix = fmt.Sprintf("_%s", geoId) + } + } + if len(suffix) < 2 { + suffix = fmt.Sprintf("_%04d", rand.Intn(1000)) + } for ids, dataSource := range process.DataSources { if *verbose { diff --git a/templates/WPS_DescribeProcess.tpl b/templates/WPS_DescribeProcess.tpl index 79a7f3b9..23af21c5 100644 --- a/templates/WPS_DescribeProcess.tpl +++ b/templates/WPS_DescribeProcess.tpl @@ -12,11 +12,15 @@ {{ .Abstract }} {{ .DataType }} + {{ if .AllowedValues }} {{ range $index, $value := .AllowedValues }} {{ . }} {{ end }} + {{ else }} + + {{ end }} {{ end }} diff --git a/utils/wps.go b/utils/wps.go index 36c38e65..5e32b151 100644 --- a/utils/wps.go +++ b/utils/wps.go @@ -20,6 +20,7 @@ import ( type Data struct { ComplexData string + LiteralData string } type Input struct { @@ -62,6 +63,8 @@ func ParsePost(rc io.ReadCloser) (map[string][]string, error) { parsedBody["end_datetime"] = []string{input.Data.ComplexData} } else if inputID == "geometry" { parsedBody["geometry"] = []string{fmt.Sprintf(`geometry=%s`, input.Data.ComplexData)} + } else if inputID == "geometry_id" { + parsedBody["geometry_id"] = []string{input.Data.LiteralData} } } @@ -78,6 +81,7 @@ type WPSParams struct { EndDateTime *string `json:"end_datetime"` Product *string `json:"product"` FeatCol geo.FeatureCollection `json:"feature_collection"` + GeometryId *string `json:"geometry_id"` } // WPSRegexpMap maps WPS request parameters to @@ -201,6 +205,10 @@ func WPSParamsChecker(params map[string][]string, compREMap map[string]*regexp.R } + if geometryId, geometryIdOk := params["geometry_id"]; geometryIdOk { + jsonFields = append(jsonFields, fmt.Sprintf(`"geometry_id":"%s"`, geometryId[0])) + } + jsonParams := fmt.Sprintf("{%s}", strings.Join(jsonFields, ",")) var wpsParamms WPSParams err := json.Unmarshal([]byte(jsonParams), &wpsParamms)