Fix a bug in the GeoJSON handling when there are no active polygons
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
@@ -33,6 +33,11 @@ type GeoJSONProperties struct {
|
||||
DN *int `json:"DN"`
|
||||
}
|
||||
|
||||
type geometryMetadata struct {
|
||||
Type string `json:"type"`
|
||||
Geometries []json.RawMessage `json:"geometries"`
|
||||
}
|
||||
|
||||
// DecodeGeoJSON decodes an SPC GeoJSON outlook product and compacts feature
|
||||
// geometry JSON for stable downstream storage.
|
||||
func DecodeGeoJSON(raw []byte) (GeoJSONFeatureCollection, error) {
|
||||
@@ -50,6 +55,16 @@ func DecodeGeoJSON(raw []byte) (GeoJSONFeatureCollection, error) {
|
||||
return collection, nil
|
||||
}
|
||||
|
||||
// IsEmptyGeometryCollection reports whether raw is SPC's no-polygon placeholder
|
||||
// geometry shape: a GeometryCollection with no child geometries.
|
||||
func IsEmptyGeometryCollection(raw json.RawMessage) bool {
|
||||
var meta geometryMetadata
|
||||
if err := json.Unmarshal(raw, &meta); err != nil {
|
||||
return false
|
||||
}
|
||||
return meta.Type == "GeometryCollection" && len(meta.Geometries) == 0
|
||||
}
|
||||
|
||||
func (p *GeoJSONProperties) UnmarshalJSON(raw []byte) error {
|
||||
type alias GeoJSONProperties
|
||||
var aux struct {
|
||||
|
||||
Reference in New Issue
Block a user