mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 10:25:41 +02:00
Clean up ancient weirdness in JSON attribute stringification
This commit is contained in:
+10
-33
@@ -10,7 +10,6 @@
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <string.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@@ -41,7 +40,7 @@
|
|||||||
#include "milo/dtoa_milo.h"
|
#include "milo/dtoa_milo.h"
|
||||||
#include "errors.hpp"
|
#include "errors.hpp"
|
||||||
|
|
||||||
int serialize_geojson_feature(struct serialization_state *sst, json_object *geometry, json_object *properties, json_object *id, int layer, json_object *tippecanoe, json_object *feature, std::string layername) {
|
int serialize_geojson_feature(struct serialization_state *sst, json_object *geometry, json_object *properties, json_object *id, int layer, json_object *tippecanoe, json_object *feature, std::string const &layername) {
|
||||||
json_object *geometry_type = json_hash_get(geometry, "type");
|
json_object *geometry_type = json_hash_get(geometry, "type");
|
||||||
if (geometry_type == NULL) {
|
if (geometry_type == NULL) {
|
||||||
static int warned = 0;
|
static int warned = 0;
|
||||||
@@ -182,36 +181,21 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
|||||||
nprop = properties->value.object.length;
|
nprop = properties->value.object.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<char *> metakey;
|
std::vector<std::string> keys;
|
||||||
metakey.resize(nprop);
|
std::vector<serial_val> values;
|
||||||
|
|
||||||
std::vector<std::string> metaval;
|
keys.reserve(nprop);
|
||||||
metaval.resize(nprop);
|
values.reserve(nprop);
|
||||||
|
|
||||||
std::vector<int> metatype;
|
|
||||||
metatype.resize(nprop);
|
|
||||||
|
|
||||||
size_t m = 0;
|
|
||||||
|
|
||||||
for (size_t i = 0; i < nprop; i++) {
|
for (size_t i = 0; i < nprop; i++) {
|
||||||
if (properties->value.object.keys[i]->type == JSON_STRING) {
|
if (properties->value.object.keys[i]->type == JSON_STRING) {
|
||||||
std::string s(properties->value.object.keys[i]->value.string.string);
|
|
||||||
|
|
||||||
int type = -1;
|
int type = -1;
|
||||||
|
|
||||||
std::string val;
|
std::string val;
|
||||||
stringify_value(properties->value.object.values[i], type, val, sst->fname, sst->line, feature);
|
stringify_value(properties->value.object.values[i], type, val, sst->fname, sst->line, feature);
|
||||||
|
|
||||||
if (type >= 0) {
|
keys.emplace_back(properties->value.object.keys[i]->value.string.string);
|
||||||
metakey[m] = properties->value.object.keys[i]->value.string.string;
|
values.emplace_back(serial_val(type, val));
|
||||||
metatype[m] = type;
|
|
||||||
metaval[m] = val;
|
|
||||||
m++;
|
|
||||||
} else {
|
|
||||||
metakey[m] = properties->value.object.keys[i]->value.string.string;
|
|
||||||
metatype[m] = mvt_null;
|
|
||||||
metaval[m] = "null";
|
|
||||||
m++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,15 +222,8 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
|||||||
sf.layername = layername;
|
sf.layername = layername;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (size_t i = 0; i < m; i++) {
|
sf.full_keys = std::move(keys);
|
||||||
sf.full_keys.push_back(metakey[i]);
|
sf.full_values = std::move(values);
|
||||||
|
|
||||||
serial_val sv;
|
|
||||||
sv.type = metatype[i];
|
|
||||||
sv.s = metaval[i];
|
|
||||||
|
|
||||||
sf.full_values.push_back(sv);
|
|
||||||
}
|
|
||||||
|
|
||||||
return serialize_feature(sst, sf);
|
return serialize_feature(sst, sf);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -730,7 +730,7 @@ int serialize_feature(struct serialization_state *sst, serial_feature &sf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sst->layermap->count(sf.layername) == 0) {
|
if (sst->layermap->count(sf.layername) == 0) {
|
||||||
sst->layermap->insert(std::pair<std::string, layermap_entry>(sf.layername, layermap_entry(sst->layermap->size())));
|
sst->layermap->emplace(sf.layername, layermap_entry(sst->layermap->size()));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ai = sst->layermap->find(sf.layername);
|
auto ai = sst->layermap->find(sf.layername);
|
||||||
|
|||||||
+10
-2
@@ -36,11 +36,19 @@ void deserialize_byte(char **f, signed char *n);
|
|||||||
// mvt_double, mvt_bool, or mvt_null). Note that all numeric values,
|
// mvt_double, mvt_bool, or mvt_null). Note that all numeric values,
|
||||||
// whether integer or floating point, use mvt_double here.
|
// whether integer or floating point, use mvt_double here.
|
||||||
struct serial_val {
|
struct serial_val {
|
||||||
int type = 0;
|
int type;
|
||||||
std::string s = "";
|
std::string s;
|
||||||
|
|
||||||
bool operator<(const serial_val &o) const;
|
bool operator<(const serial_val &o) const;
|
||||||
bool operator!=(const serial_val &o) const;
|
bool operator!=(const serial_val &o) const;
|
||||||
|
|
||||||
|
serial_val() {
|
||||||
|
type = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
serial_val(int t, const std::string &val)
|
||||||
|
: type(t), s(val) {
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
struct serial_feature {
|
struct serial_feature {
|
||||||
|
|||||||
Reference in New Issue
Block a user