Skip to content

Commit

Permalink
enhance extract
Browse files Browse the repository at this point in the history
* change default overfetch to 0.05
* add FeatureCollection region support
* print the number of tiles extracted per second
  • Loading branch information
bdon committed Sep 11, 2023
1 parent 17fcecd commit 544095d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pmtiles/extract.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions pmtiles/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
33 changes: 33 additions & 0 deletions pmtiles/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 544095d

Please sign in to comment.