Skip to content

Commit

Permalink
Add README
Browse files Browse the repository at this point in the history
  • Loading branch information
JackWink committed May 14, 2018
1 parent ad72c31 commit fcfe64e
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 12 deletions.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
```

##
2 changes: 1 addition & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 10 additions & 10 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/decode/feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit fcfe64e

Please sign in to comment.