mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-02 08:25:40 +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/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
@@ -41,7 +40,7 @@
|
||||
#include "milo/dtoa_milo.h"
|
||||
#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");
|
||||
if (geometry_type == NULL) {
|
||||
static int warned = 0;
|
||||
@@ -182,36 +181,21 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
||||
nprop = properties->value.object.length;
|
||||
}
|
||||
|
||||
std::vector<char *> metakey;
|
||||
metakey.resize(nprop);
|
||||
std::vector<std::string> keys;
|
||||
std::vector<serial_val> values;
|
||||
|
||||
std::vector<std::string> metaval;
|
||||
metaval.resize(nprop);
|
||||
|
||||
std::vector<int> metatype;
|
||||
metatype.resize(nprop);
|
||||
|
||||
size_t m = 0;
|
||||
keys.reserve(nprop);
|
||||
values.reserve(nprop);
|
||||
|
||||
for (size_t i = 0; i < nprop; i++) {
|
||||
if (properties->value.object.keys[i]->type == JSON_STRING) {
|
||||
std::string s(properties->value.object.keys[i]->value.string.string);
|
||||
|
||||
int type = -1;
|
||||
|
||||
std::string val;
|
||||
stringify_value(properties->value.object.values[i], type, val, sst->fname, sst->line, feature);
|
||||
|
||||
if (type >= 0) {
|
||||
metakey[m] = properties->value.object.keys[i]->value.string.string;
|
||||
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++;
|
||||
}
|
||||
keys.emplace_back(properties->value.object.keys[i]->value.string.string);
|
||||
values.emplace_back(serial_val(type, val));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,15 +222,8 @@ int serialize_geojson_feature(struct serialization_state *sst, json_object *geom
|
||||
sf.layername = layername;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m; i++) {
|
||||
sf.full_keys.push_back(metakey[i]);
|
||||
|
||||
serial_val sv;
|
||||
sv.type = metatype[i];
|
||||
sv.s = metaval[i];
|
||||
|
||||
sf.full_values.push_back(sv);
|
||||
}
|
||||
sf.full_keys = std::move(keys);
|
||||
sf.full_values = std::move(values);
|
||||
|
||||
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) {
|
||||
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);
|
||||
|
||||
+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,
|
||||
// whether integer or floating point, use mvt_double here.
|
||||
struct serial_val {
|
||||
int type = 0;
|
||||
std::string s = "";
|
||||
int type;
|
||||
std::string s;
|
||||
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user