mirror of
https://github.com/mapbox/tippecanoe.git
synced 2025-02-01 16:58:05 +00:00
More reorganization to reuse JSON parsing
This commit is contained in:
parent
112f451c66
commit
4256473283
2
Makefile
2
Makefile
@ -43,7 +43,7 @@ C = $(wildcard *.c) $(wildcard *.cpp)
|
|||||||
INCLUDES = -I/usr/local/include -I.
|
INCLUDES = -I/usr/local/include -I.
|
||||||
LIBS = -L/usr/local/lib
|
LIBS = -L/usr/local/lib
|
||||||
|
|
||||||
tippecanoe: geojson.o jsonpull/jsonpull.o tile.o pool.o mbtiles.o geometry.o projection.o memfile.o clipper/clipper.o mvt.o serial.o main.o text.o plugin.o write_json.o
|
tippecanoe: geojson.o jsonpull/jsonpull.o tile.o pool.o mbtiles.o geometry.o projection.o memfile.o clipper/clipper.o mvt.o serial.o main.o text.o plugin.o write_json.o read_json.o
|
||||||
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
$(CXX) $(PG) $(LIBS) $(FINAL_FLAGS) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) -lm -lz -lsqlite3 -lpthread
|
||||||
|
|
||||||
tippecanoe-enumerate: enumerate.o
|
tippecanoe-enumerate: enumerate.o
|
||||||
|
37
geojson.cpp
37
geojson.cpp
@ -38,42 +38,7 @@ extern "C" {
|
|||||||
#include "options.hpp"
|
#include "options.hpp"
|
||||||
#include "serial.hpp"
|
#include "serial.hpp"
|
||||||
#include "text.hpp"
|
#include "text.hpp"
|
||||||
|
#include "read_json.hpp"
|
||||||
#define GEOM_POINT 0 /* array of positions */
|
|
||||||
#define GEOM_MULTIPOINT 1 /* array of arrays of positions */
|
|
||||||
#define GEOM_LINESTRING 2 /* array of arrays of positions */
|
|
||||||
#define GEOM_MULTILINESTRING 3 /* array of arrays of arrays of positions */
|
|
||||||
#define GEOM_POLYGON 4 /* array of arrays of arrays of positions */
|
|
||||||
#define GEOM_MULTIPOLYGON 5 /* array of arrays of arrays of arrays of positions */
|
|
||||||
#define GEOM_TYPES 6
|
|
||||||
|
|
||||||
static const char *geometry_names[GEOM_TYPES] = {
|
|
||||||
"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon",
|
|
||||||
};
|
|
||||||
|
|
||||||
static int geometry_within[GEOM_TYPES] = {
|
|
||||||
-1, /* point */
|
|
||||||
GEOM_POINT, /* multipoint */
|
|
||||||
GEOM_POINT, /* linestring */
|
|
||||||
GEOM_LINESTRING, /* multilinestring */
|
|
||||||
GEOM_LINESTRING, /* polygon */
|
|
||||||
GEOM_POLYGON, /* multipolygon */
|
|
||||||
};
|
|
||||||
|
|
||||||
static int mb_geometry[GEOM_TYPES] = {
|
|
||||||
VT_POINT, VT_POINT, VT_LINE, VT_LINE, VT_POLYGON, VT_POLYGON,
|
|
||||||
};
|
|
||||||
|
|
||||||
void json_context(json_object *j) {
|
|
||||||
char *s = json_stringify(j);
|
|
||||||
|
|
||||||
if (strlen(s) >= 500) {
|
|
||||||
sprintf(s + 497, "...");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "In JSON object %s\n", s);
|
|
||||||
free(s); // stringify
|
|
||||||
}
|
|
||||||
|
|
||||||
long long parse_geometry(int t, json_object *j, long long *bbox, drawvec &out, int op, const char *fname, int line, int *initialized, unsigned *initial_x, unsigned *initial_y, json_object *feature) {
|
long long parse_geometry(int t, json_object *j, long long *bbox, drawvec &out, int op, const char *fname, int line, int *initialized, unsigned *initial_x, unsigned *initial_y, json_object *feature) {
|
||||||
long long g = 0;
|
long long g = 0;
|
||||||
|
17
plugin.cpp
17
plugin.cpp
@ -7,7 +7,6 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "mvt.hpp"
|
#include "mvt.hpp"
|
||||||
#include "plugin.hpp"
|
#include "plugin.hpp"
|
||||||
#include "write_json.hpp"
|
|
||||||
#include "projection.hpp"
|
#include "projection.hpp"
|
||||||
#include "geometry.hpp"
|
#include "geometry.hpp"
|
||||||
|
|
||||||
@ -15,6 +14,9 @@ extern "C" {
|
|||||||
#include "jsonpull/jsonpull.h"
|
#include "jsonpull/jsonpull.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include "write_json.hpp"
|
||||||
|
#include "read_json.hpp"
|
||||||
|
|
||||||
struct writer_arg {
|
struct writer_arg {
|
||||||
int *pipe_orig;
|
int *pipe_orig;
|
||||||
mvt_layer *layer;
|
mvt_layer *layer;
|
||||||
@ -44,17 +46,6 @@ void *run_writer(void *a) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void json_context(json_object *j) { // XXX share with geojson.cpp
|
|
||||||
char *s = json_stringify(j);
|
|
||||||
|
|
||||||
if (strlen(s) >= 500) {
|
|
||||||
sprintf(s + 497, "...");
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "In JSON object %s\n", s);
|
|
||||||
free(s); // stringify
|
|
||||||
}
|
|
||||||
|
|
||||||
mvt_layer parse_layer(int fd, unsigned z, unsigned x, unsigned y) {
|
mvt_layer parse_layer(int fd, unsigned z, unsigned x, unsigned y) {
|
||||||
mvt_layer ret;
|
mvt_layer ret;
|
||||||
|
|
||||||
@ -124,7 +115,6 @@ mvt_layer parse_layer(int fd, unsigned z, unsigned x, unsigned y) {
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
int t;
|
int t;
|
||||||
for (t = 0; t < GEOM_TYPES; t++) {
|
for (t = 0; t < GEOM_TYPES; t++) {
|
||||||
if (strcmp(geometry_type->string, geometry_names[t]) == 0) {
|
if (strcmp(geometry_type->string, geometry_names[t]) == 0) {
|
||||||
@ -136,7 +126,6 @@ mvt_layer parse_layer(int fd, unsigned z, unsigned x, unsigned y) {
|
|||||||
json_context(j);
|
json_context(j);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
json_free(j);
|
json_free(j);
|
||||||
}
|
}
|
||||||
|
39
read_json.cpp
Normal file
39
read_json.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "jsonpull/jsonpull.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "read_json.hpp"
|
||||||
|
#include "geometry.hpp"
|
||||||
|
|
||||||
|
const char *geometry_names[GEOM_TYPES] = {
|
||||||
|
"Point", "MultiPoint", "LineString", "MultiLineString", "Polygon", "MultiPolygon",
|
||||||
|
};
|
||||||
|
|
||||||
|
int geometry_within[GEOM_TYPES] = {
|
||||||
|
-1, /* point */
|
||||||
|
GEOM_POINT, /* multipoint */
|
||||||
|
GEOM_POINT, /* linestring */
|
||||||
|
GEOM_LINESTRING, /* multilinestring */
|
||||||
|
GEOM_LINESTRING, /* polygon */
|
||||||
|
GEOM_POLYGON, /* multipolygon */
|
||||||
|
};
|
||||||
|
|
||||||
|
int mb_geometry[GEOM_TYPES] = {
|
||||||
|
VT_POINT, VT_POINT, VT_LINE, VT_LINE, VT_POLYGON, VT_POLYGON,
|
||||||
|
};
|
||||||
|
|
||||||
|
void json_context(json_object *j) {
|
||||||
|
char *s = json_stringify(j);
|
||||||
|
|
||||||
|
if (strlen(s) >= 500) {
|
||||||
|
sprintf(s + 497, "...");
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "In JSON object %s\n", s);
|
||||||
|
free(s); // stringify
|
||||||
|
}
|
13
read_json.hpp
Normal file
13
read_json.hpp
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#define GEOM_POINT 0 /* array of positions */
|
||||||
|
#define GEOM_MULTIPOINT 1 /* array of arrays of positions */
|
||||||
|
#define GEOM_LINESTRING 2 /* array of arrays of positions */
|
||||||
|
#define GEOM_MULTILINESTRING 3 /* array of arrays of arrays of positions */
|
||||||
|
#define GEOM_POLYGON 4 /* array of arrays of arrays of positions */
|
||||||
|
#define GEOM_MULTIPOLYGON 5 /* array of arrays of arrays of arrays of positions */
|
||||||
|
#define GEOM_TYPES 6
|
||||||
|
|
||||||
|
extern const char *geometry_names[GEOM_TYPES];
|
||||||
|
extern int geometry_within[GEOM_TYPES];
|
||||||
|
extern int mb_geometry[GEOM_TYPES];
|
||||||
|
|
||||||
|
void json_context(json_object *j);
|
Loading…
x
Reference in New Issue
Block a user