Skip to content

Commit

Permalink
added support for specifying geometry id as wps input (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
edisonguo committed Apr 25, 2019
1 parent c2324c2 commit 827e6a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions templates/WPS_DescribeProcess.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
<ows:Abstract>{{ .Abstract }}</ows:Abstract>
<LiteralData>
<ows:DataType ows:reference="{{ .DataTypeRef }}">{{ .DataType }}</ows:DataType>
{{ if .AllowedValues }}
<ows:AllowedValues>
{{ range $index, $value := .AllowedValues }}
<ows:Value>{{ . }}</ows:Value>
{{ end }}
</ows:AllowedValues>
{{ else }}
<ows:AnyValue />
{{ end }}
</LiteralData>
</Input>
{{ end }}
Expand Down
8 changes: 8 additions & 0 deletions utils/wps.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

type Data struct {
ComplexData string
LiteralData string
}

type Input struct {
Expand Down Expand Up @@ -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}
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 827e6a3

Please sign in to comment.