Skip to content

Commit

Permalink
fixed data_available_dates for the regions without data (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
edisonguo authored Oct 31, 2019
1 parent 1d906ee commit 38145ac
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 75 deletions.
138 changes: 73 additions & 65 deletions processor/feature_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,95 +26,103 @@ func GetFeatureInfo(ctx context.Context, params utils.WMSParams, conf *utils.Con

out := `"bands": {`

hasData := true
if len(ftInfo.Raster) == 1 {
if rs, ok := ftInfo.Raster[0].(*utils.ByteRaster); ok {
if rs.NameSpace == "ZoomOut" {
var msg string
switch rs.NameSpace {
case "ZoomOut":
msg = "zoom in to view"
hasData = false
case utils.EmptyTileNS:
msg = "n/a"
hasData = false
}

if !hasData {
for i, ns := range ftInfo.Namespaces {
out += fmt.Sprintf(`"%s":"zoom in to view"`, ns)
out += fmt.Sprintf(`"%s":"%s"`, ns, msg)
if i < len(ftInfo.Namespaces)-1 {
out += ","
}
}
out += `}`
return out, nil
}

if rs.NameSpace == utils.EmptyTileNS {
return "", fmt.Errorf("data unavailable")
}
}
}

width, height, _, err := utils.ValidateRasterSlice(ftInfo.Raster)
if err != nil {
return "", err
}
if hasData {
width, height, _, err := utils.ValidateRasterSlice(ftInfo.Raster)
if err != nil {
return "", err
}

x := *params.X
y := *params.Y
x := *params.X
y := *params.Y

offset := y*width + x
if offset >= width*height {
return "", fmt.Errorf("x or y out of bound")
}
offset := y*width + x
if offset >= width*height {
return "", fmt.Errorf("x or y out of bound")
}

for i, ns := range ftInfo.Namespaces {
r := ftInfo.Raster[i]
var valueStr string
for i, ns := range ftInfo.Namespaces {
r := ftInfo.Raster[i]
var valueStr string

switch t := r.(type) {
case *utils.SignedByteRaster:
noData := int8(t.NoData)
value := t.Data[offset]
if value == noData {
valueStr = `"n/a"`
} else {
valueStr = fmt.Sprintf("%v", value)
}

switch t := r.(type) {
case *utils.SignedByteRaster:
noData := int8(t.NoData)
value := t.Data[offset]
if value == noData {
valueStr = `"n/a"`
} else {
valueStr = fmt.Sprintf("%v", value)
}
case *utils.ByteRaster:
noData := uint8(t.NoData)
value := t.Data[offset]
if value == noData {
valueStr = `"n/a"`
} else {
valueStr = fmt.Sprintf("%v", value)
}

case *utils.ByteRaster:
noData := uint8(t.NoData)
value := t.Data[offset]
if value == noData {
valueStr = `"n/a"`
} else {
valueStr = fmt.Sprintf("%v", value)
}
case *utils.Int16Raster:
noData := int16(t.NoData)
value := t.Data[offset]
if value == noData {
valueStr = `"n/a"`
} else {
valueStr = fmt.Sprintf("%v", value)
}

case *utils.Int16Raster:
noData := int16(t.NoData)
value := t.Data[offset]
if value == noData {
valueStr = `"n/a"`
} else {
valueStr = fmt.Sprintf("%v", value)
}
case *utils.UInt16Raster:
noData := uint16(t.NoData)
value := t.Data[offset]
if value == noData {
valueStr = `"n/a"`
} else {
valueStr = fmt.Sprintf("%v", value)
}

case *utils.UInt16Raster:
noData := uint16(t.NoData)
value := t.Data[offset]
if value == noData {
valueStr = `"n/a"`
} else {
valueStr = fmt.Sprintf("%v", value)
case *utils.Float32Raster:
noData := float32(t.NoData)
value := t.Data[offset]
if value == noData {
valueStr = `"n/a"`
} else {
valueStr = fmt.Sprintf("%v", value)
}
}

case *utils.Float32Raster:
noData := float32(t.NoData)
value := t.Data[offset]
if value == noData {
valueStr = `"n/a"`
} else {
valueStr = fmt.Sprintf("%v", value)
out += fmt.Sprintf(`"%s": %s`, ns, valueStr)
if i < len(ftInfo.Namespaces)-1 {
out += ","
}
}

out += fmt.Sprintf(`"%s": %s`, ns, valueStr)
if i < len(ftInfo.Namespaces)-1 {
out += ","
}
out += `}`
}
out += `}`

if len(ftInfo.DsDates) > 0 {
out += `, "data_available_for_dates":[`
Expand Down
2 changes: 1 addition & 1 deletion processor/tile_merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ func (enc *RasterMerger) Run(bandExpr *utils.BandExpressions, verbose bool) {
}

if len(nameSpaces) == 0 {
enc.Out <- []utils.Raster{&utils.ByteRaster{Data: make([]uint8, 0), Height: 0, Width: 0}}
enc.Out <- []utils.Raster{&utils.ByteRaster{Data: make([]uint8, 0), NameSpace: utils.EmptyTileNS, Height: 0, Width: 0}}
return
}

Expand Down
25 changes: 16 additions & 9 deletions processor/tile_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (dp *TilePipeline) GetFileList(geoReq *GeoTileRequest, verbose bool) ([]*Ge

if hasFusedBand {
grans, err := dp.getDepFileList(geoReq, verbose)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -248,7 +249,7 @@ func (dp *TilePipeline) processDeps(geoReq *GeoTileRequest, verbose bool) ([]*Fl
case res := <-tp.Process(req, verbose):
timeDelta := time.Second * time.Duration(-idx)
hasScaleParams := !(req.ScaleParams.Offset == 0 && req.ScaleParams.Scale == 0 && req.ScaleParams.Clip == 0)
allFilled := true
allFilled := false
if req.FusionUnscale == 0 && hasScaleParams {
scaleParams := utils.ScaleParams{Offset: req.ScaleParams.Offset,
Scale: req.ScaleParams.Scale,
Expand All @@ -270,9 +271,11 @@ func (dp *TilePipeline) processDeps(geoReq *GeoTileRequest, verbose bool) ([]*Fl
for j := range norm {
norm[j].NoData = 0xFF
flex, filled := getFlexRaster(j, timestamp.Add(timeDelta), geoReq, norm[j], nil)
rasters = append(rasters, flex)
if !filled {
allFilled = filled
if flex != nil {
rasters = append(rasters, flex)
if !filled {
allFilled = filled
}
}
}
} else {
Expand All @@ -281,11 +284,12 @@ func (dp *TilePipeline) processDeps(geoReq *GeoTileRequest, verbose bool) ([]*Fl
normRaster = res[0]
}
flex, filled := getFlexRaster(j, timestamp.Add(timeDelta), geoReq, res[j], normRaster)
rasters = append(rasters, flex)
if !filled {
allFilled = filled
if flex != nil {
rasters = append(rasters, flex)
if !filled {
allFilled = filled
}
}

}
}

Expand All @@ -309,7 +313,7 @@ func (dp *TilePipeline) processDeps(geoReq *GeoTileRequest, verbose bool) ([]*Fl

if len(rasters) == 0 {
for idx := 0; idx < len(geoReq.BandExpr.ExprNames); idx++ {
emptyRaster := &utils.ByteRaster{Data: make([]uint8, geoReq.Height*geoReq.Width), NoData: 0, Height: geoReq.Height, Width: geoReq.Width, NameSpace: utils.EmptyTileNS}
emptyRaster := &utils.ByteRaster{Data: make([]uint8, geoReq.Height*geoReq.Width), NoData: 0, Height: geoReq.Height, Width: geoReq.Width, NameSpace: utils.EmptyTileNS + "_dummy"}
emptyFlex, _ := getFlexRaster(idx, timestamp, geoReq, emptyRaster, nil)
rasters = append(rasters, emptyFlex)
}
Expand Down Expand Up @@ -503,6 +507,9 @@ func getFlexRaster(idx int, timestamp time.Time, req *GeoTileRequest, raster uti
}

case *utils.ByteRaster:
if t.NameSpace == utils.EmptyTileNS {
return nil, false
}
flex.Type = "Byte"
flex.NoData = t.NoData
flex.Data = t.Data
Expand Down

0 comments on commit 38145ac

Please sign in to comment.