Skip to content

Commit

Permalink
more new format updates
Browse files Browse the repository at this point in the history
  • Loading branch information
mourner committed Aug 3, 2015
1 parent b96542f commit 955e76b
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 32 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ it may still change as we get community feedback and discover new ways to improv
| normal | gzipped
------------------- | --------- | --------
us-zips.json | 101.85 MB | 26.67 MB
us-zips.pbf | 12.24 MB | 10.48 MB
us-zips.pbf | 12.2 MB | 10.31 MB
idaho.json | 10.92 MB | 2.57 MB
idaho.pbf | 1.37 MB | 1.17 MB
idaho.pbf | 1.38 MB | 1.18 MB

## API

Expand Down
6 changes: 3 additions & 3 deletions decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ function decode(pbf) {

function readObjectField(tag, obj, pbf) {
if (tag === 1) obj.type = objTypes[pbf.readVarint()];
else if (tag === 2) dim = pbf.readVarint();
else if (tag === 3) e = Math.pow(10, pbf.readVarint());
else if (tag === 4) keys.push(pbf.readString());
else if (tag === 3) dim = pbf.readVarint();
else if (tag === 4) e = Math.pow(10, pbf.readVarint());
else if (tag === 5) keys.push(pbf.readString());

else if (tag === 6) lengths = pbf.readPackedVarint();
else if (tag === 7) readCoords(obj, pbf, obj.type);
Expand Down
7 changes: 4 additions & 3 deletions encode.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,10 @@ function writeObject(obj, pbf) {
if (!paramsWritten) {
var precision = Math.ceil(Math.log(e) / Math.LN10);

pbf.writeVarintField(2, dim);
pbf.writeVarintField(3, precision);
for (var id in keys) pbf.writeStringField(4, id);
pbf.writeBooleanField(2, true);
if (dim !== 2) pbf.writeVarintField(3, dim);
if (precision !== 6) pbf.writeVarintField(4, precision);
for (var id in keys) pbf.writeStringField(5, id);

paramsWritten = true;
}
Expand Down
51 changes: 27 additions & 24 deletions geobuf.proto
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
message Object {
required ObjectType type = 1;

optional uint32 dimensions = 2; // max coordinate dimensions
optional uint32 precision = 3; // number of digits after decimal point for coordinates
repeated string keys = 4; // global array of unique keys
optional bool is_top_level = 2;

// global parameters; encoded in the top level object, with subsequent objects inheriting them
optional uint32 dimensions = 3 [default = 2]; // max coordinate dimensions
optional uint32 precision = 4 [default = 6]; // number of digits after decimal point for coordinates
repeated string keys = 5; // global array of unique keys

// geometry coordinates (where the bulk of the size goes)
repeated uint32 lengths = 6 [packed = true]; // coordinate structure in lengths
Expand All @@ -18,28 +21,28 @@ message Object {

repeated uint32 properties = 14 [packed = true]; // pairs of key/value indexes for feature properties
repeated uint32 custom_properties = 15 [packed = true]; // arbitrary properties
}

message Value {
oneof value_type {
string string_value = 1;
double double_value = 2;
uint64 pos_int_value = 3;
uint64 neg_int_value = 4;
bool bool_value = 5;
string json_value = 6;
enum ObjectType {
POINT = 0;
MULTIPOINT = 1;
LINESTRING = 2;
MULTILINESTRING = 3;
POLYGON = 4;
MULTIPOLYGON = 5;
GEOMETRYCOLLECTION = 6;

FEATURE = 7;
FEATURECOLLECTION = 8;
}
}

enum ObjectType {
POINT = 0;
MULTIPOINT = 1;
LINESTRING = 2;
MULTILINESTRING = 3;
POLYGON = 4;
MULTIPOLYGON = 5;
GEOMETRYCOLLECTION = 6;

FEATURE = 7;
FEATURECOLLECTION = 8;
message Value {
oneof value_type {
string string_value = 1;
double double_value = 2;
uint64 pos_int_value = 3;
uint64 neg_int_value = 4;
bool bool_value = 5;
string json_value = 6;
}
}
}

0 comments on commit 955e76b

Please sign in to comment.