代码拉取完成,页面将自动刷新
同步操作将从 exlimit/tiler 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
package main
import (
"database/sql"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync"
"github.com/paulmach/orb"
"github.com/paulmach/orb/geojson"
"github.com/paulmach/orb/maptile"
"github.com/paulmach/orb/maptile/tilecover"
log "github.com/sirupsen/logrus"
)
func saveToMBTile(tile Tile, db *sql.DB) error {
_, err := db.Exec("insert into tiles (zoom_level, tile_column, tile_row, tile_data) values (?, ?, ?, ?);", tile.T.Z, tile.T.X, tile.flipY(), tile.C)
// _, err := db.Exec("insert or ignore into tiles (zoom_level, tile_column, tile_row, tile_data) values (?, ?, ?, ?);", tile.T.Z, tile.T.X, tile.flipY(), tile.C)
if err != nil {
return err
}
return nil
}
func saveToFiles(tile Tile, rootdir string) error {
dir := filepath.Join(rootdir, fmt.Sprintf(`%d`, tile.T.Z), fmt.Sprintf(`%d`, tile.T.X))
os.MkdirAll(dir, os.ModePerm)
fileName := filepath.Join(dir, fmt.Sprintf(`%d.png`, tile.T.Y))
err := ioutil.WriteFile(fileName, tile.C, os.ModePerm)
if err != nil {
return err
}
log.Println(fileName)
return nil
}
func optimizeConnection(db *sql.DB) error {
// _, err := db.Exec("PRAGMA synchronous=0")
// if err != nil {
// return err
// }
_, err := db.Exec("PRAGMA locking_mode=EXCLUSIVE")
if err != nil {
return err
}
_, err = db.Exec("PRAGMA journal_mode=DELETE")
if err != nil {
return err
}
return nil
}
func optimizeDatabase(db *sql.DB) error {
_, err := db.Exec("ANALYZE;")
if err != nil {
return err
}
_, err = db.Exec("VACUUM;")
if err != nil {
return err
}
return nil
}
func loadFeature(path string) *geojson.Feature {
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalf("unable to read file: %v", err)
}
f, err := geojson.UnmarshalFeature(data)
if err == nil {
return f
}
fc, err := geojson.UnmarshalFeatureCollection(data)
if err == nil {
if len(fc.Features) != 1 {
log.Fatalf("must have 1 feature: %v", len(fc.Features))
}
return fc.Features[0]
}
g, err := geojson.UnmarshalGeometry(data)
if err != nil {
log.Fatalf("unable to unmarshal feature: %v", err)
}
return geojson.NewFeature(g.Geometry())
}
func loadFeatureCollection(path string) *geojson.FeatureCollection {
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalf("unable to read file: %v", err)
}
fc, err := geojson.UnmarshalFeatureCollection(data)
if err != nil {
log.Fatalf("unable to unmarshal feature: %v", err)
}
count := 0
for i := range fc.Features {
if fc.Features[i].Properties["name"] != "original" {
fc.Features[count] = fc.Features[i]
count++
}
}
fc.Features = fc.Features[:count]
return fc
}
func loadCollection(path string) orb.Collection {
data, err := ioutil.ReadFile(path)
if err != nil {
log.Fatalf("unable to read file: %v", err)
}
fc, err := geojson.UnmarshalFeatureCollection(data)
if err != nil {
log.Fatalf("unable to unmarshal feature: %v", err)
}
var collection orb.Collection
for _, f := range fc.Features {
collection = append(collection, f.Geometry)
}
return collection
}
// output gets called if there is a test failure for debugging.
func output(name string, r *geojson.FeatureCollection) {
f := loadFeature("./data/" + name + ".geojson")
if f.Properties == nil {
f.Properties = make(geojson.Properties)
}
f.Properties["fill"] = "#FF0000"
f.Properties["fill-opacity"] = "0.5"
f.Properties["stroke"] = "#FF0000"
f.Properties["name"] = "original"
r.Append(f)
data, err := json.MarshalIndent(r, "", " ")
if err != nil {
log.Fatalf("error marshalling json: %v", err)
}
err = ioutil.WriteFile("failure_"+name+".geojson", data, 0644)
if err != nil {
log.Fatalf("write file failure: %v", err)
}
}
// output gets called if there is a test failure for debugging.
func output2(name string, r *geojson.FeatureCollection, wg *sync.WaitGroup) {
defer wg.Done()
data, err := json.MarshalIndent(r, "", " ")
if err != nil {
log.Fatalf("error marshalling json: %v", err)
}
err = ioutil.WriteFile(name+".geojson", data, 0644)
if err != nil {
log.Fatalf("write file failure: %v", err)
}
}
func getZoomCount(g orb.Geometry, minz int, maxz int) map[int]int64 {
info := make(map[int]int64)
for z := minz; z <= maxz; z++ {
info[z] = tilecover.GeometryCount(g, maptile.Zoom(z))
}
return info
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。