Skip to content

Commit

Permalink
ComplexToGeoJSONLayers
Browse files Browse the repository at this point in the history
  • Loading branch information
sfomuseumbot committed Jul 9, 2024
1 parent 5ac9ae7 commit 84881b7
Showing 1 changed file with 42 additions and 2 deletions.
44 changes: 42 additions & 2 deletions campus/geojson.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ package campus

import (
"context"
"fmt"

"github.com/paulmach/orb/geojson"
"github.com/whosonfirst/go-reader"
wof_reader "github.com/whosonfirst/go-whosonfirst-reader"
)

func ToGeoJSON(ctx context.Context, c *Complex, r reader.Reader) error {
func ComplexToGeoJSONLayers(ctx context.Context, c *Complex, r reader.Reader) (map[string]*geojson.FeatureCollection, error) {

terminal_ids := make([]int64, 0)
boardingarea_ids := make([]int64, 0)
Expand Down Expand Up @@ -90,5 +93,42 @@ func ToGeoJSON(ctx context.Context, c *Complex, r reader.Reader) error {
}
}

return nil
feature_ids := map[string][]int64{
"terminals": terminal_ids,
"boardingareas": boardingarea_ids,
"commonareas": commonarea_ids,
"observationdecks": observationdeck_ids,
"gates": gate_ids,
"checkpoints": checkpoint_ids,
"galleries": gallery_ids,
"publicart": publicart_ids,
}

features := make(map[string]*geojson.FeatureCollection)

for k, ids := range feature_ids {

fc := geojson.NewFeatureCollection()

for _, id := range ids {

body, err := wof_reader.LoadBytes(ctx, r, id)

if err != nil {
return nil, fmt.Errorf("Failed to read %d, %w", id, err)
}

f, err := geojson.UnmarshalFeature(body)

if err != nil {
return nil, fmt.Errorf("Failed to unmarshal %d, %w", id, err)
}

fc.Append(f)
}

features[k] = fc
}

return features, nil
}

0 comments on commit 84881b7

Please sign in to comment.