From fcfe64e00798ecf60ae5f0f2712108b20732e588 Mon Sep 17 00:00:00 2001 From: Jack Wink Date: Sun, 13 May 2018 22:46:40 -0700 Subject: [PATCH] Add README --- README.md | 34 ++++++++++++++++++++++++++++++++++ decode.go | 2 +- decode_test.go | 20 ++++++++++---------- pkg/decode/feature.go | 2 +- 4 files changed, 46 insertions(+), 12 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..2ea29c0 --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# Go Geobuf + +A compact Protobuf representation of GeoJSON. Based on Mapbox's [geobuf](https://github.com/mapbox). + +## Limitations + +Due to the nature of Go being a statically typed language, custom properties are not currently supported. + +Currently, [orb](https://github.com/paulmach/orb) is the underlying library supporting GeoJSON. +Long term plans are to offer our own representation with orb as a supported extension. + +Some orb properties may lose their types through encoding/decoding. For instance, `int8`s may become `uint`s +or just `int`s. + +## Encoding/Decoding + +A basic example shows how this library will infer the proper precision for encoding/decoding + +```go +import ( + "github.com/cairnapp/go-geobuf" + "github.com/paulmach/orb" + "github.com/paulmach/orb/geojson" +) + +point := geojson.NewGeometry(orb.Point([2]float64{ + 124.123, + 234.456 +})) +data := geobuf.Encode(point) +decoded_point := geobuf.Decode(point) +``` + +## diff --git a/decode.go b/decode.go index 4f0ba7e..71b8f25 100644 --- a/decode.go +++ b/decode.go @@ -7,7 +7,7 @@ import ( "github.com/cairnapp/go-geobuf/proto" ) -func Decode(msg proto.Data) interface{} { +func Decode(msg *proto.Data) interface{} { switch v := msg.DataType.(type) { case *proto.Data_Geometry_: geo := v.Geometry diff --git a/decode_test.go b/decode_test.go index b0fcdfc..6e31d0a 100644 --- a/decode_test.go +++ b/decode_test.go @@ -14,7 +14,7 @@ import ( func TestDecodePoint(t *testing.T) { p := geojson.NewGeometry(orb.Point([2]float64{124.123, 234.456})) encoded := Encode(p) - decoded := Decode(*encoded) + decoded := Decode(encoded) if !reflect.DeepEqual(p, decoded) { t.Errorf("Expected %+v, got %+v", p, decoded) @@ -27,7 +27,7 @@ func TestDecodeMultiPoint(t *testing.T) { orb.Point([2]float64{345.567, 456.678}), })) encoded := Encode(p) - decoded := Decode(*encoded) + decoded := Decode(encoded) if !reflect.DeepEqual(p, decoded) { t.Errorf("Expected %+v, got %+v", p, decoded) @@ -40,7 +40,7 @@ func TestDecodeLineString(t *testing.T) { orb.Point([2]float64{345.567, 456.678}), })) encoded := Encode(p) - decoded := Decode(*encoded) + decoded := Decode(encoded) if !reflect.DeepEqual(p, decoded) { t.Errorf("Expected %+v, got %+v", p, decoded) @@ -59,7 +59,7 @@ func TestDecodeMultiLineString(t *testing.T) { }), })) encoded := Encode(p) - decoded := Decode(*encoded) + decoded := Decode(encoded) if !reflect.DeepEqual(p, decoded) { t.Errorf("Expected %+v, got %+v", p, decoded) @@ -80,7 +80,7 @@ func TestDecodePolygon(t *testing.T) { }), })) encoded := Encode(p) - decoded := Decode(*encoded) + decoded := Decode(encoded) if !reflect.DeepEqual(p, decoded) { t.Errorf("Expected %+v, got %+v", p, decoded) @@ -116,7 +116,7 @@ func TestDecodeMultiPolygon(t *testing.T) { }), })) encoded := Encode(p) - decoded := Decode(*encoded) + decoded := Decode(encoded) if !reflect.DeepEqual(p, decoded) { t.Errorf("Expected %+v, got %+v", p, decoded) @@ -140,7 +140,7 @@ func TestDecodeMultiPolygonEfficient(t *testing.T) { }), })) encoded := Encode(p) - decoded := Decode(*encoded) + decoded := Decode(encoded) if !reflect.DeepEqual(p, decoded) { t.Errorf("Expected %+v, got %+v", p, decoded) @@ -168,7 +168,7 @@ func TestDecodeFeatureIntId(t *testing.T) { p.Properties["bool"] = true encoded := Encode(p) spew.Dump(encoded) - decoded := Decode(*encoded) + decoded := Decode(encoded) if !reflect.DeepEqual(p, decoded) { t.Errorf("Expected %+v, got %+v", p, decoded) @@ -197,7 +197,7 @@ func TestDecodeFeatureStringId(t *testing.T) { encoded := Encode(p) spew.Dump(encoded) - decoded := Decode(*encoded) + decoded := Decode(encoded) if !reflect.DeepEqual(p, decoded) { t.Errorf("Expected %+v, got %+v", p, decoded) @@ -248,7 +248,7 @@ func TestDecodeFeatureCollection(t *testing.T) { collection.Append(p2) encoded := Encode(collection) - decoded := Decode(*encoded) + decoded := Decode(encoded) if !reflect.DeepEqual(collection, decoded) { t.Errorf("Expected %+v, got %+v", p, decoded) diff --git a/pkg/decode/feature.go b/pkg/decode/feature.go index ade1c27..1615ab6 100644 --- a/pkg/decode/feature.go +++ b/pkg/decode/feature.go @@ -5,7 +5,7 @@ import ( "github.com/paulmach/orb/geojson" ) -func DecodeFeature(msg proto.Data, feature *proto.Data_Feature, precision, dimension uint32) *geojson.Feature { +func DecodeFeature(msg *proto.Data, feature *proto.Data_Feature, precision, dimension uint32) *geojson.Feature { geo := feature.Geometry decodedGeo := DecodeGeometry(geo, msg.Precision, msg.Dimensions) geoFeature := geojson.NewFeature(decodedGeo.Geometry())