diff --git a/main.go b/main.go index 19b30f6..f2e2151 100644 --- a/main.go +++ b/main.go @@ -52,7 +52,7 @@ var cli struct { Maxzoom int8 `default:-1 help:"Maximum zoom level, inclusive."` DownloadThreads int `default:4 help:"Number of download threads."` DryRun bool `help:"Calculate tiles to extract, but don't download them."` - Overfetch float32 `default:0.1 help:"What ratio of extra data to download to minimize # requests; 0.2 is 20%"` + Overfetch float32 `default:0.05 help:"What ratio of extra data to download to minimize # requests; 0.2 is 20%"` } `cmd:"" help:"Create an archive from a larger archive for a subset of zoom levels or geographic region."` Verify struct { diff --git a/pmtiles/extract.go b/pmtiles/extract.go index 2a744fb..476b982 100644 --- a/pmtiles/extract.go +++ b/pmtiles/extract.go @@ -534,7 +534,7 @@ func Extract(logger *log.Logger, bucketURL string, key string, maxzoom int8, reg } } - fmt.Printf("Completed in %v with %v download threads.\n", time.Since(start), download_threads) + fmt.Printf("Completed in %v with %v download threads (%v tiles/s).\n", time.Since(start), download_threads, float64(len(reencoded))/float64(time.Since(start).Seconds())) total_requests := 2 // header + root total_requests += num_overfetch_leaves // leaves total_requests += 1 // metadata diff --git a/pmtiles/region.go b/pmtiles/region.go index 1b3b608..b73ea69 100644 --- a/pmtiles/region.go +++ b/pmtiles/region.go @@ -7,6 +7,23 @@ import ( ) func UnmarshalRegion(data []byte) (orb.MultiPolygon, error) { + fc, err := geojson.UnmarshalFeatureCollection(data) + + if err == nil { + retval := make([]orb.Polygon, 0) + for _, f := range fc.Features { + switch v := f.Geometry.(type) { + case orb.Polygon: + retval = append(retval, v) + case orb.MultiPolygon: + retval = append(retval, v...) + } + } + if len(retval) > 0 { + return retval, nil + } + } + f, err := geojson.UnmarshalFeature(data) if err == nil { diff --git a/pmtiles/region_test.go b/pmtiles/region_test.go index 329d3df..ad17466 100644 --- a/pmtiles/region_test.go +++ b/pmtiles/region_test.go @@ -46,3 +46,36 @@ func TestRawMultiPolygonFeatureRegion(t *testing.T) { assert.Nil(t, err) assert.Equal(t, 1, len(result)) } + +func TestFeatureCollectionRegion(t *testing.T) { + result, err := UnmarshalRegion([]byte(`{ + "type": "FeatureCollection", + "features": [ + { + "type": "Feature", + "geometry": { + "type": "MultiPolygon", + "coordinates": [[[[0, 0],[0,1],[1,1],[0,0]]]] + } + }, + { + "type": "Feature", + "geometry": { + "type": "Polygon", + "coordinates": [[[1, 1],[1,2],[2,2],[1,1]]] + } + } + ] + }`)) + assert.Nil(t, err) + assert.Equal(t, 2, len(result)) +} + +func TestEmptyFeatureCollectionRegion(t *testing.T) { + _, err := UnmarshalRegion([]byte(`{ + "type": "FeatureCollection", + "features": [ + ] + }`)) + assert.NotNil(t, err) +}