Skip to content

Commit

Permalink
Merge branch 'master' into ignore-error
Browse files Browse the repository at this point in the history
Conflicts:
	mbtiles.c
  • Loading branch information
e-n-f committed Feb 1, 2016
2 parents a84061c + f9a0a55 commit 2015ba2
Show file tree
Hide file tree
Showing 27 changed files with 32,258 additions and 12 deletions.
27 changes: 25 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,37 @@ sudo: false
matrix:
include:
- os: linux
compiler: gcc
env: COVERAGE=gcov-4.9
addons:
apt:
sources: ['ubuntu-toolchain-r-test']
packages: [ 'g++-4.9', 'protobuf-compiler', 'libprotobuf-dev' ]
- os: linux
compiler: clang
addons:
apt:
packages: [ 'protobuf-compiler', 'libprotobuf-dev' ]
- os: osx
compiler: clang


install:
- if [[ $(uname -s) == 'Darwin' ]]; then brew install protobuf; fi;
- if [ -n "${COVERAGE}" ]; then
export CXX=g++-4.9;
export CC=gcc-4.9;
export CXXFLAGS="--coverage -g";
export CFLAGS="--coverage -g";
export LDFLAGS="--coverage";
fi;
- make

script:
- echo '{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[0,0]}}' > test.json
- ./tippecanoe -o test.mbtiles test.json
- make test
- if [ -n "${COVERAGE}" ]; then
rm vector_tile.pb.o;
${COVERAGE} -lp *.o;
pip install --user cpp-coveralls;
~/.local/bin/coveralls --no-gcov -i ./ --exclude clipper --exclude vector_tile.pb.cc --exclude vector_tile.pb.h;
fi
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.8.0

* There are tests that can be run with "make test".

## 1.7.2

* Feature properties that are arrays or hashes get stringified
Expand Down
24 changes: 23 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ libjsonpull.a: jsonpull.o
ranlib $@

%.o: %.c $(H)
cc $(PG) $(INCLUDES) -O3 -g -Wall $(CFLAGS) -c $<
$(CC) $(PG) $(INCLUDES) -O3 -g -Wall $(CFLAGS) -c $<

%.o: %.cc $(H)
$(CXX) $(PG) $(INCLUDES) -O3 -g -Wall $(CXXFLAGS) -c $<
Expand All @@ -62,3 +62,25 @@ clean:

indent:
clang-format -i -style="{BasedOnStyle: Google, IndentWidth: 8, UseTab: Always, AllowShortIfStatementsOnASingleLine: false, ColumnLimit: 0, ContinuationIndentWidth: 8, SpaceAfterCStyleCast: true, IndentCaseLabels: false, AllowShortBlocksOnASingleLine: false, AllowShortFunctionsOnASingleLine: false}" $(C) $(H)

TESTS = $(wildcard tests/*/out/*.json)
SPACE = $(NULL) $(NULL)

test: tippecanoe tippecanoe-decode $(addsuffix .check,$(TESTS))

%.json.check:
./tippecanoe -f -o $@.mbtiles $(subst _, ,$(patsubst %.json.check,%,$(word 4,$(subst /, ,$@)))) $(wildcard $(subst $(SPACE),/,$(wordlist 1,2,$(subst /, ,$@)))/*.json)
./tippecanoe-decode $@.mbtiles > $@.out
cmp $(patsubst %.check,%,$@) $@.out
rm $@.out $@.mbtiles

# Use this target to regenerate the standards that the tests are compared against
# after making a change that legitimately changes their output

prep-test: $(TESTS)

tests/%.json: Makefile tippecanoe tippecanoe-decode
./tippecanoe -f -o $@.check.mbtiles $(subst _, ,$(patsubst %.json,%,$(word 4,$(subst /, ,$@)))) $(wildcard $(subst $(SPACE),/,$(wordlist 1,2,$(subst /, ,$@)))/*.json)
./tippecanoe-decode $@.check.mbtiles > $@
cmp $(patsubst %.check,%,$@) $@
rm $@.check.mbtiles
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Builds [vector tilesets](https://www.mapbox.com/developers/vector-tiles/) from l
features. This is a tool for [making maps from huge datasets](MADE_WITH.md).

[![Build Status](https://travis-ci.org/mapbox/tippecanoe.svg)](https://travis-ci.org/mapbox/tippecanoe)
[![Coverage Status](https://coveralls.io/repos/mapbox/tippecanoe/badge.svg?branch=master&service=github)](https://coveralls.io/github/mapbox/tippecanoe?branch=master)

Intent
------
Expand Down
30 changes: 28 additions & 2 deletions decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -360,16 +360,42 @@ void decode(char *fname, int z, unsigned x, unsigned y) {
}

if (z < 0) {
printf("{ \"type\": \"FeatureCollection\", \"properties\": {\n");

const char *sql2 = "SELECT name, value from metadata order by name;";
sqlite3_stmt *stmt2;
if (sqlite3_prepare_v2(db, sql2, -1, &stmt2, NULL) != SQLITE_OK) {
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE);
}

int within = 0;
while (sqlite3_step(stmt2) == SQLITE_ROW) {
if (within) {
printf(",\n");
}
within = 1;

const unsigned char *name = sqlite3_column_text(stmt2, 0);
const unsigned char *value = sqlite3_column_text(stmt2, 1);

printq((char *) name);
printf(": ");
printq((char *) value);
}

sqlite3_finalize(stmt2);

const char *sql = "SELECT tile_data, zoom_level, tile_column, tile_row from tiles order by zoom_level, tile_column, tile_row;";
sqlite3_stmt *stmt;
if (sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {
fprintf(stderr, "%s: select failed: %s\n", fname, sqlite3_errmsg(db));
exit(EXIT_FAILURE);
}

printf("{ \"type\": \"FeatureCollection\", \"features\": [\n");
printf("\n}, \"features\": [\n");

int within = 0;
within = 0;
while (sqlite3_step(stmt) == SQLITE_ROW) {
if (within) {
printf(",\n");
Expand Down
2 changes: 1 addition & 1 deletion geojson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
*out = '\0';

if (!quiet) {
printf("using layer %d name %s\n", i, trunc);
fprintf(stderr, "For layer %d, using name \"%s\"\n", i, trunc);
}
}
}
Expand Down
1 change: 1 addition & 0 deletions jsonpull.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define _GNU_SOURCE // for asprintf()
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
Expand Down
29 changes: 28 additions & 1 deletion mbtiles.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ static void aprintf(char **buf, const char *format, ...) {
free(tmp);
}

static int pvcmp(const void *v1, const void *v2) {
const struct pool_val *const *pv1 = v1;
const struct pool_val *const *pv2 = v2;

int n = strcmp((*pv1)->s, (*pv2)->s);
if (n != 0) {
return n;
}

return (*pv1)->type - (*pv2)->type;
}

void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, char **layername, int minzoom, int maxzoom, double minlat, double minlon, double maxlat, double maxlon, double midlat, double midlon, struct pool **file_keys, int nlayers, int forcetable) {
char *sql, *err;

Expand Down Expand Up @@ -219,8 +231,23 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, char **layername,
quote(&buf, layername[i]);
aprintf(&buf, "\", \"description\": \"\", \"minzoom\": %d, \"maxzoom\": %d, \"fields\": {", minzoom, maxzoom);

int n = 0;
struct pool_val *pv;
for (pv = file_keys[i]->head; pv != NULL; pv = pv->next) {
n++;
}

struct pool_val *vals[n];
n = 0;
for (pv = file_keys[i]->head; pv != NULL; pv = pv->next) {
vals[n++] = pv;
}

qsort(vals, n, sizeof(struct pool_val *), pvcmp);

int j;
for (j = 0; j < n; j++) {
pv = vals[j];
aprintf(&buf, "\"");
quote(&buf, pv->s);

Expand All @@ -232,7 +259,7 @@ void mbtiles_write_metadata(sqlite3 *outdb, const char *fname, char **layername,
aprintf(&buf, "\": \"String\"");
}

if (pv->next != NULL) {
if (j + 1 < n) {
aprintf(&buf, ", ");
}
}
Expand Down

0 comments on commit 2015ba2

Please sign in to comment.