Seperated out to method and added test for --raw-tiles

This commit is contained in:
Shan-Chun Kuo 2017-04-05 15:59:37 +01:00
parent aee12ac1fe
commit f03b89656c
27 changed files with 99 additions and 15 deletions

3
.gitignore vendored
View File

@ -27,3 +27,6 @@
*.exe
*.out
*.app
# Mac
.DS_Store

View File

@ -46,7 +46,7 @@ C = $(wildcard *.c) $(wildcard *.cpp)
INCLUDES = -I/usr/local/include -I.
LIBS = -L/usr/local/lib
tippecanoe: geojson.o jsonpull/jsonpull.o tile.o pool.o mbtiles.o geometry.o projection.o memfile.o mvt.o serial.o main.o text.o
tippecanoe: geojson.o jsonpull/jsonpull.o tile.o pool.o mbtiles.o geometry.o projection.o memfile.o mvt.o serial.o main.o text.o rawtiles.o
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
tippecanoe-enumerate: enumerate.o
@ -78,7 +78,7 @@ indent:
TESTS = $(wildcard tests/*/out/*.json)
SPACE = $(NULL) $(NULL)
test: tippecanoe tippecanoe-decode $(addsuffix .check,$(TESTS)) parallel-test pbf-test join-test enumerate-test decode-test unit
test: tippecanoe tippecanoe-decode $(addsuffix .check,$(TESTS)) raw-tiles-test parallel-test pbf-test join-test enumerate-test decode-test unit
./unit
# Work around Makefile and filename punctuation limits: _ for space, @ for :, % for /
@ -111,6 +111,11 @@ parallel-test:
cmp tests/parallel/linear-file.json tests/parallel/parallel-pipes.json
rm tests/parallel/*.mbtiles tests/parallel/*.json
raw-tiles-test:
./tippecanoe -o tests/raw-tiles/raw-tiles tests/raw-tiles/hackspots.geojson --raw-tiles
diff -x '.*' -rq tests/raw-tiles/raw-tiles tests/raw-tiles/compare
rm -rf tests/raw-tiles/raw-tiles
decode-test:
mkdir -p tests/muni/decode
./tippecanoe -z11 -Z11 -f -o tests/muni/decode/multi.mbtiles tests/muni/*.json

View File

@ -2255,7 +2255,7 @@ int main(int argc, char **argv) {
if(!prevent[P_PBF_COMPRESSION]){
outdb = mbtiles_open(outdir, argv, forcetable);
}else{
}else{
outpbfdir = outdir;
}

20
rawtiles.cpp Normal file
View File

@ -0,0 +1,20 @@
#include <iostream>
#include <fstream>
#include <string>
#include <sys/stat.h>
#include "rawtiles.hpp"
void write_raw_tile(char *outdir, int z, int tx, int ty, std::string pbf) {
mkdir(outdir, S_IRWXU | S_IRWXG | S_IRWXO);
std::string curdir(outdir);
std::string slash( "/" );
std::string newdir = curdir + slash + std::to_string(z);
mkdir(newdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
newdir = newdir + "/" + std::to_string(tx);
mkdir(newdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
newdir = newdir + "/" + std::to_string(ty) + ".pbf";
std::ofstream pbfFile (newdir, std::ios::out | std::ios::binary);
pbfFile.write (pbf.data(), pbf.size());
pbfFile.close();
}

1
rawtiles.hpp Normal file
View File

@ -0,0 +1 @@
void write_raw_tile(char *outdir, int z, int tx, int ty, std::string pbf);

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,65 @@
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"Name": "Albina Press",
"Address": "4637 N Albina Ave Portland, OR 97217",
"Notes": "usually busy, outlets on side wall only"
},
"geometry": {
"type": "Point",
"coordinates": [
-122.67516911029816,
45.55673233031101
]
}
},
{
"type": "Feature",
"properties": {
"Name": "Arbor Lodge",
"Address": "1507 N Rosa Parks Way Portland, OR 97217",
"Notes": ""
},
"geometry": {
"type": "Point",
"coordinates": [
-122.68242716789246,
45.56997505986905
]
}
},
{
"type": "Feature",
"properties": {
"Name": "Three Friends Coffeehouse",
"Address": "201 SE 12th Ave, Portland, OR 97214",
"Notes": ""
},
"geometry": {
"type": "Point",
"coordinates": [
-122.65496134757996,
45.5212590460849
]
}
},
{
"type": "Feature",
"properties": {
"Name": "Lucky Labrador Brew Pub",
"Address": "915 SE Hawthorne Blvd. Portland, OR 97214",
"Notes": "Dog friendly"
},
"geometry": {
"type": "Point",
"coordinates": [
-122.65625953674315,
45.512331780814186
]
}
}
]
}

View File

@ -22,6 +22,7 @@
#include <time.h>
#include "mvt.hpp"
#include "mbtiles.hpp"
#include "rawtiles.hpp"
#include "geometry.hpp"
#include "tile.hpp"
#include "pool.hpp"
@ -1919,18 +1920,7 @@ long long write_tile(FILE *geoms, long long *geompos_in, char *metabase, char *s
if(!prevent[P_PBF_COMPRESSION]){
mbtiles_write_tile(outdb, z, tx, ty, compressed.data(), compressed.size());
}else{
mkdir(outpbfdir, S_IRWXU | S_IRWXG | S_IRWXO);
std::string curdir(outpbfdir);
std::string slash( "/" );
std::string newdir = curdir + slash + std::to_string(z);
mkdir(newdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
newdir = newdir + "/" + std::to_string(tx);
mkdir(newdir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
newdir = newdir + "/" + std::to_string(ty) + ".pbf";
std::ofstream pbfFile (newdir, std::ios::out | std::ios::app | std::ios::binary);
pbfFile.write (pbf.data(), pbf.size());
pbfFile.close();
write_raw_tile(outpbfdir, z, tx, ty, pbf);
}
if (pthread_mutex_unlock(&db_lock) != 0) {