Skip to content

Commit

Permalink
Remove orb as a top level dependency
Browse files Browse the repository at this point in the history
TODO:

* Add Orb extension
* Add Custom Properties
* Add Schema for properties
  • Loading branch information
JackWink committed May 22, 2018
1 parent fcfe64e commit 3e07642
Show file tree
Hide file tree
Showing 17 changed files with 378 additions and 175 deletions.
11 changes: 1 addition & 10 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
name = "github.com/golang/protobuf"
version = "1.0.0"

[[constraint]]
branch = "master"
name = "github.com/paulmach/orb"

[prune]
go-tests = true
unused-packages = true
11 changes: 4 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ A compact Protobuf representation of GeoJSON. Based on Mapbox's [geobuf](https:/

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
Some properties may lose their types through encoding/decoding. For instance, `int8`s may become `uint`s
or just `int`s.

## Encoding/Decoding
Expand All @@ -19,11 +16,11 @@ A basic example shows how this library will infer the proper precision for encod
```go
import (
"github.com/cairnapp/go-geobuf"
"github.com/paulmach/orb"
"github.com/paulmach/orb/geojson"
"github.com/cairnapp/go-geobuf/pkg/geometry"
"github.com/cairnapp/go-geobuf/pkg/geojson"
)

point := geojson.NewGeometry(orb.Point([2]float64{
point := geojson.NewGeometry(geometry.Point([]float64{
124.123,
234.456
}))
Expand Down
3 changes: 1 addition & 2 deletions decode.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package geobuf

import (
"github.com/paulmach/orb/geojson"

"github.com/cairnapp/go-geobuf/pkg/decode"
"github.com/cairnapp/go-geobuf/pkg/geojson"
"github.com/cairnapp/go-geobuf/proto"
)

Expand Down
181 changes: 91 additions & 90 deletions decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"testing"

"github.com/davecgh/go-spew/spew"
"github.com/paulmach/orb"
"github.com/paulmach/orb/geojson"

. "github.com/cairnapp/go-geobuf"
"github.com/cairnapp/go-geobuf/pkg/geojson"
"github.com/cairnapp/go-geobuf/pkg/geometry"
)

func TestDecodePoint(t *testing.T) {
p := geojson.NewGeometry(orb.Point([2]float64{124.123, 234.456}))
p := geojson.NewGeometry(geometry.Point([]float64{124.123, 234.456}))
encoded := Encode(p)
decoded := Decode(encoded)

Expand All @@ -22,9 +22,9 @@ func TestDecodePoint(t *testing.T) {
}

func TestDecodeMultiPoint(t *testing.T) {
p := geojson.NewGeometry(orb.MultiPoint([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
p := geojson.NewGeometry(geometry.MultiPoint([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
}))
encoded := Encode(p)
decoded := Decode(encoded)
Expand All @@ -35,9 +35,9 @@ func TestDecodeMultiPoint(t *testing.T) {
}

func TestDecodeLineString(t *testing.T) {
p := geojson.NewGeometry(orb.LineString([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
p := geojson.NewGeometry(geometry.LineString([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
}))
encoded := Encode(p)
decoded := Decode(encoded)
Expand All @@ -48,14 +48,14 @@ func TestDecodeLineString(t *testing.T) {
}

func TestDecodeMultiLineString(t *testing.T) {
p := geojson.NewGeometry(orb.MultiLineString([]orb.LineString{
orb.LineString([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
p := geojson.NewGeometry(geometry.MultiLineString([]geometry.LineString{
geometry.LineString([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
}),
orb.LineString([]orb.Point{
orb.Point([2]float64{224.123, 334.456}),
orb.Point([2]float64{445.567, 556.678}),
geometry.LineString([]geometry.Point{
geometry.Point([]float64{224.123, 334.456}),
geometry.Point([]float64{445.567, 556.678}),
}),
}))
encoded := Encode(p)
Expand All @@ -67,16 +67,16 @@ func TestDecodeMultiLineString(t *testing.T) {
}

func TestDecodePolygon(t *testing.T) {
p := geojson.NewGeometry(orb.Polygon([]orb.Ring{
orb.Ring([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
orb.Point([2]float64{124.123, 234.456}),
p := geojson.NewGeometry(geometry.Polygon([]geometry.Ring{
geometry.Ring([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
geometry.Point([]float64{124.123, 234.456}),
}),
orb.Ring([]orb.Point{
orb.Point([2]float64{224.123, 334.456}),
orb.Point([2]float64{445.567, 556.678}),
orb.Point([2]float64{224.123, 334.456}),
geometry.Ring([]geometry.Point{
geometry.Point([]float64{224.123, 334.456}),
geometry.Point([]float64{445.567, 556.678}),
geometry.Point([]float64{224.123, 334.456}),
}),
}))
encoded := Encode(p)
Expand All @@ -89,33 +89,34 @@ func TestDecodePolygon(t *testing.T) {

func TestDecodeMultiPolygon(t *testing.T) {
p := geojson.NewGeometry(
orb.MultiPolygon([]orb.Polygon{
orb.Polygon([]orb.Ring{
orb.Ring([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
orb.Point([2]float64{124.123, 234.456}),
geometry.MultiPolygon([]geometry.Polygon{
geometry.Polygon([]geometry.Ring{
geometry.Ring([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
geometry.Point([]float64{124.123, 234.456}),
}),
orb.Ring([]orb.Point{
orb.Point([2]float64{224.123, 334.456}),
orb.Point([2]float64{445.567, 556.678}),
orb.Point([2]float64{224.123, 334.456}),
geometry.Ring([]geometry.Point{
geometry.Point([]float64{224.123, 334.456}),
geometry.Point([]float64{445.567, 556.678}),
geometry.Point([]float64{224.123, 334.456}),
}),
}),
orb.Polygon([]orb.Ring{
orb.Ring([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
orb.Point([2]float64{124.123, 234.456}),
geometry.Polygon([]geometry.Ring{
geometry.Ring([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
geometry.Point([]float64{124.123, 234.456}),
}),
orb.Ring([]orb.Point{
orb.Point([2]float64{224.123, 334.456}),
orb.Point([2]float64{445.567, 556.678}),
orb.Point([2]float64{224.123, 334.456}),
geometry.Ring([]geometry.Point{
geometry.Point([]float64{224.123, 334.456}),
geometry.Point([]float64{445.567, 556.678}),
geometry.Point([]float64{224.123, 334.456}),
}),
}),
}))
encoded := Encode(p)
spew.Dump(encoded)
decoded := Decode(encoded)

if !reflect.DeepEqual(p, decoded) {
Expand All @@ -125,17 +126,17 @@ func TestDecodeMultiPolygon(t *testing.T) {

func TestDecodeMultiPolygonEfficient(t *testing.T) {
p := geojson.NewGeometry(
orb.MultiPolygon([]orb.Polygon{
orb.Polygon([]orb.Ring{
orb.Ring([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
orb.Point([2]float64{124.123, 234.456}),
geometry.MultiPolygon([]geometry.Polygon{
geometry.Polygon([]geometry.Ring{
geometry.Ring([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
geometry.Point([]float64{124.123, 234.456}),
}),
orb.Ring([]orb.Point{
orb.Point([2]float64{224.123, 334.456}),
orb.Point([2]float64{445.567, 556.678}),
orb.Point([2]float64{224.123, 334.456}),
geometry.Ring([]geometry.Point{
geometry.Point([]float64{224.123, 334.456}),
geometry.Point([]float64{445.567, 556.678}),
geometry.Point([]float64{224.123, 334.456}),
}),
}),
}))
Expand All @@ -148,16 +149,16 @@ func TestDecodeMultiPolygonEfficient(t *testing.T) {
}

func TestDecodeFeatureIntId(t *testing.T) {
p := geojson.NewFeature(orb.Polygon([]orb.Ring{
orb.Ring([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
orb.Point([2]float64{124.123, 234.456}),
p := geojson.NewFeature(geometry.Polygon([]geometry.Ring{
geometry.Ring([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
geometry.Point([]float64{124.123, 234.456}),
}),
orb.Ring([]orb.Point{
orb.Point([2]float64{224.123, 334.456}),
orb.Point([2]float64{445.567, 556.678}),
orb.Point([2]float64{224.123, 334.456}),
geometry.Ring([]geometry.Point{
geometry.Point([]float64{224.123, 334.456}),
geometry.Point([]float64{445.567, 556.678}),
geometry.Point([]float64{224.123, 334.456}),
}),
}))
p.ID = int64(1)
Expand All @@ -176,16 +177,16 @@ func TestDecodeFeatureIntId(t *testing.T) {
}

func TestDecodeFeatureStringId(t *testing.T) {
p := geojson.NewFeature(orb.Polygon([]orb.Ring{
orb.Ring([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
orb.Point([2]float64{124.123, 234.456}),
p := geojson.NewFeature(geometry.Polygon([]geometry.Ring{
geometry.Ring([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
geometry.Point([]float64{124.123, 234.456}),
}),
orb.Ring([]orb.Point{
orb.Point([2]float64{224.123, 334.456}),
orb.Point([2]float64{445.567, 556.678}),
orb.Point([2]float64{224.123, 334.456}),
geometry.Ring([]geometry.Point{
geometry.Point([]float64{224.123, 334.456}),
geometry.Point([]float64{445.567, 556.678}),
geometry.Point([]float64{224.123, 334.456}),
}),
}))
p.ID = "1234"
Expand All @@ -205,16 +206,16 @@ func TestDecodeFeatureStringId(t *testing.T) {
}

func TestDecodeFeatureCollection(t *testing.T) {
p := geojson.NewFeature(orb.Polygon([]orb.Ring{
orb.Ring([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
orb.Point([2]float64{124.123, 234.456}),
p := geojson.NewFeature(geometry.Polygon([]geometry.Ring{
geometry.Ring([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
geometry.Point([]float64{124.123, 234.456}),
}),
orb.Ring([]orb.Point{
orb.Point([2]float64{224.123, 334.456}),
orb.Point([2]float64{445.567, 556.678}),
orb.Point([2]float64{224.123, 334.456}),
geometry.Ring([]geometry.Point{
geometry.Point([]float64{224.123, 334.456}),
geometry.Point([]float64{445.567, 556.678}),
geometry.Point([]float64{224.123, 334.456}),
}),
}))
p.ID = "1234"
Expand All @@ -224,16 +225,16 @@ func TestDecodeFeatureCollection(t *testing.T) {
p.Properties["string"] = "string"
p.Properties["bool"] = true

p2 := geojson.NewFeature(orb.Polygon([]orb.Ring{
orb.Ring([]orb.Point{
orb.Point([2]float64{224.123, 334.456}),
orb.Point([2]float64{445.567, 556.678}),
orb.Point([2]float64{224.123, 334.456}),
p2 := geojson.NewFeature(geometry.Polygon([]geometry.Ring{
geometry.Ring([]geometry.Point{
geometry.Point([]float64{224.123, 334.456}),
geometry.Point([]float64{445.567, 556.678}),
geometry.Point([]float64{224.123, 334.456}),
}),
orb.Ring([]orb.Point{
orb.Point([2]float64{124.123, 234.456}),
orb.Point([2]float64{345.567, 456.678}),
orb.Point([2]float64{124.123, 234.456}),
geometry.Ring([]geometry.Point{
geometry.Point([]float64{124.123, 234.456}),
geometry.Point([]float64{345.567, 456.678}),
geometry.Point([]float64{124.123, 234.456}),
}),
}))
p2.ID = "5679"
Expand Down
3 changes: 1 addition & 2 deletions encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ package geobuf

import (
"github.com/cairnapp/go-geobuf/pkg/encode"
"github.com/cairnapp/go-geobuf/pkg/geojson"
"github.com/cairnapp/go-geobuf/pkg/math"
"github.com/cairnapp/go-geobuf/proto"

"github.com/paulmach/orb/geojson"
)

func Encode(obj interface{}) *proto.Data {
Expand Down
16 changes: 14 additions & 2 deletions pkg/decode/feature.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
package decode

import (
"github.com/cairnapp/go-geobuf/pkg/geojson"
"github.com/cairnapp/go-geobuf/pkg/geometry"
"github.com/cairnapp/go-geobuf/proto"
"github.com/paulmach/orb/geojson"
)

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())
var geoFeature *geojson.Feature
switch decodedGeo.Type {
case geojson.GeometryCollectionType:
collection := make(geometry.Collection, len(decodedGeo.Geometries))
for i, child := range decodedGeo.Geometries {
collection[i] = child.Coordinates
}
geoFeature = geojson.NewFeature(collection)
default:
geoFeature = geojson.NewFeature(decodedGeo.Coordinates)
}

for i := 0; i < len(feature.Properties); i = i + 2 {
keyIdx := feature.Properties[i]
valIdx := feature.Properties[i+1]
Expand Down
Loading

0 comments on commit 3e07642

Please sign in to comment.