Skip to content

Commit

Permalink
Merge pull request #67 from tianpf/main
Browse files Browse the repository at this point in the history
add example encoding.
  • Loading branch information
tianpf authored May 26, 2022
2 parents 65c5933 + 0a4caad commit 1a2fd88
Show file tree
Hide file tree
Showing 75 changed files with 256 additions and 100 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [1.1.0] - 2022-05-26
### 新增
- Optimize the topological relation algorithm and geometric operation algorithm of geometry,
and improve the performance of calculation
- The encoding and decoding methods of geoencoding are standardized, and the encoder interface is realized
- Added support for coordinate system
## [1.0.4] - 2021-12-31
### Added
- Delaunay triangle method and Voronoi diagram
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.zh-CN.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 更新日志

## [1.1.0] - 2022-05-26
### 新增
- 优化几何体的拓扑关系算法以及几何运算算法,提升了计算的性能
- 规范了geoencoding的编码和解码方法,实现了encoder接口
- 增加了对坐标系的支持
## [1.0.4] - 2021-12-31
### 新增
- 德劳内三角形方法与沃罗诺伊图
Expand Down
22 changes: 2 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,11 @@ func main() {
fmt.Printf(e.Error())
}
fmt.Printf("%f", area)
// get result 4.0
rawJSON := []byte(`
{ "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
"properties": {"prop0": "value0"}
}
]
}`)
fc := geojson.NewFeatureCollection()
_ = json.Unmarshal(rawJSON, &fc)
println("%p", fc)
// Geometry will be unmarshalled into the correct geo.Geometry type.
point := fc.Features[0].Geometry.(geoos.Point)
println("%p", &point)
}
```
Example: geoencoding
[example_encoding.go](https://github.com/spatial-go/geoos/example/example_encoding.go)

## Maintainer

Expand Down
22 changes: 2 additions & 20 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,11 @@ func main() {
fmt.Printf(e.Error())
}
fmt.Printf("%f", area)
// get result 4.0
rawJSON := []byte(`
{ "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
"properties": {"prop0": "value0"}
}
]
}`)
fc := geojson.NewFeatureCollection()
_ = json.Unmarshal(rawJSON, &fc)
println("%p", fc)
// Geometry will be unmarshalled into the correct geo.Geometry type.
point := fc.Features[0].Geometry.(geoos.Point)
println("%p", &point)
}
```
Example: geoencoding
[example_encoding.go](https://github.com/spatial-go/geoos/example/example_encoding.go)

## 维护者

Expand Down
3 changes: 1 addition & 2 deletions algorithm/graph/clipping/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
"github.com/spatial-go/geoos/algorithm/calc"
"github.com/spatial-go/geoos/algorithm/graph"
"github.com/spatial-go/geoos/algorithm/matrix"
"github.com/spatial-go/geoos/encoding/geojson"

"github.com/spatial-go/geoos/geoencoding/geojson"
"github.com/spatial-go/geoos/space"
)

Expand Down
2 changes: 1 addition & 1 deletion algorithm/subdivision/voronoi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/spatial-go/geoos/algorithm/matrix"
"github.com/spatial-go/geoos/algorithm/matrix/envelope"
"github.com/spatial-go/geoos/encoding/wkt"
"github.com/spatial-go/geoos/geoencoding/wkt"
"github.com/spatial-go/geoos/space"
)

Expand Down
6 changes: 3 additions & 3 deletions clusters/dbscan/kdtree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,11 @@ func isSortedOnDim(dim int, nodes []int, pts pointSlice) bool {
return true
}
prev := pts[nodes[0]][dim]
for _, n := range nodes {
if pts[n][dim] < prev {
for i := 0; i < len(nodes); i++ {
if pts[nodes[i]][dim] < prev {
return false
}
prev = pts[n][dim]
prev = pts[nodes[i]][dim]
}
return true
}
Binary file added example/data/geobuf.proto
Binary file not shown.
2 changes: 2 additions & 0 deletions example/data/geocsv.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
way_id,pt_id,x,y
0,0,102,0.5
1 change: 1 addition & 0 deletions example/data/geojson.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[102,0.5]},"properties":{"prop0":"value0"}}]}
1 change: 1 addition & 0 deletions example/data/geowkb.wkb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
01070000000100000001010000000000000000805940000000000000e03f
1 change: 1 addition & 0 deletions example/data/geowkt.wkt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
GEOMETRYCOLLECTION(POINT(102 0.5))
162 changes: 162 additions & 0 deletions example/encoding/example_encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
// Example This is an example .
package main

import (
"bytes"
"fmt"
"os"

"github.com/spatial-go/geoos/geoencoding"
)

func main() {
rawJSON := []byte(`
{ "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [102.0, 0.5]},
"properties": {"prop0": "value0"}
}
]
}`)

buf := new(bytes.Buffer)
buf.Write(rawJSON)

if geomFeatureCollection, err := geoencoding.ReadGeoJSON(buf, geoencoding.GeoJSON); err != nil {
fmt.Printf("ReadGeoJSON error:%v", err)
} else {
fmt.Println(geomFeatureCollection)

filename := "../data/geojson.json"
if file, err := os.Create(filename); err != nil {
fmt.Println(err)
} else {
defer file.Close()

if err := geoencoding.WriteGeoJSON(file, geomFeatureCollection, geoencoding.GeoJSON); err != nil {
fmt.Printf("WriteGeoJSON error:%v", err)
}
}

filename = "../data/geojson.json"
if file, err := os.Open(filename); err != nil {
fmt.Println(err)
} else {
defer file.Close()

if geomFeatureCollection, err := geoencoding.ReadGeoJSON(file, geoencoding.GeoJSON); err != nil {
fmt.Printf("ReadGeoJSON error:%v", err)
} else {
buf := new(bytes.Buffer)
_ = geoencoding.WriteGeoJSON(buf, geomFeatureCollection, geoencoding.GeoJSON)
bufStr := buf.String()
fmt.Println(bufStr)
}
}

filename = "../data/geobuf.proto"
if file, err := os.Create(filename); err != nil {
fmt.Println(err)
} else {
defer file.Close()
if err := geoencoding.WriteGeoJSON(file, geomFeatureCollection, geoencoding.Geobuf); err != nil {
fmt.Printf("WriteGeoJSON error:%v", err)
}
}

filename = "../data/geobuf.proto"
if file, err := os.Open(filename); err != nil {
fmt.Println(err)
} else {
defer file.Close()

if geomFeatureCollection, err := geoencoding.ReadGeoJSON(file, geoencoding.Geobuf); err != nil {
fmt.Printf("ReadGeoJSON error:%v", err)
} else {
buf := new(bytes.Buffer)
_ = geoencoding.WriteGeoJSON(buf, geomFeatureCollection, geoencoding.GeoJSON)
bufStr := buf.String()
fmt.Println(bufStr)
}
}

filename = "../data/geocsv.csv"
if file, err := os.Create(filename); err != nil {
fmt.Println(err)
} else {
defer file.Close()
if err := geoencoding.WriteGeoJSON(file, geomFeatureCollection, geoencoding.GeoCSV); err != nil {
fmt.Printf("WriteGeoJSON error:%v", err)
}
}

filename = "../data/geocsv.csv"
if file, err := os.Open(filename); err != nil {
fmt.Println(err)
} else {
defer file.Close()

if geomFeatureCollection, err := geoencoding.ReadGeoJSON(file, geoencoding.GeoCSV); err != nil {
fmt.Printf("ReadGeoJSON error:%v", err)
} else {
buf := new(bytes.Buffer)
_ = geoencoding.WriteGeoJSON(buf, geomFeatureCollection, geoencoding.GeoJSON)
bufStr := buf.String()
fmt.Println(bufStr)
}
}

filename = "../data/geowkb.wkb"
if file, err := os.Create(filename); err != nil {
fmt.Println(err)
} else {
defer file.Close()
if err := geoencoding.WriteGeoJSON(file, geomFeatureCollection, geoencoding.WKB); err != nil {
fmt.Printf("WriteGeoJSON error:%v", err)
}
}

filename = "../data/geowkb.wkb"
if file, err := os.Open(filename); err != nil {
fmt.Println(err)
} else {
defer file.Close()

if geomFeatureCollection, err := geoencoding.ReadGeoJSON(file, geoencoding.WKB); err != nil {
fmt.Printf("ReadGeoJSON error:%v", err)
} else {
buf := new(bytes.Buffer)
_ = geoencoding.WriteGeoJSON(buf, geomFeatureCollection, geoencoding.GeoJSON)
bufStr := buf.String()
fmt.Println(bufStr)
}
}

filename = "../data/geowkt.wkt"
if file, err := os.Create(filename); err != nil {
fmt.Println(err)
} else {
defer file.Close()
if err := geoencoding.WriteGeoJSON(file, geomFeatureCollection, geoencoding.WKT); err != nil {
fmt.Printf("WriteGeoJSON error:%v", err)
}
}

filename = "../data/geowkt.wkt"
if file, err := os.Open(filename); err != nil {
fmt.Println(err)
} else {
defer file.Close()

if geomFeatureCollection, err := geoencoding.ReadGeoJSON(file, geoencoding.WKT); err != nil {
fmt.Printf("ReadGeoJSON error:%v", err)
} else {
buf := new(bytes.Buffer)
_ = geoencoding.WriteGeoJSON(buf, geomFeatureCollection, geoencoding.GeoJSON)
bufStr := buf.String()
fmt.Println(bufStr)
}
}
}
}
4 changes: 2 additions & 2 deletions example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"encoding/json"
"fmt"

"github.com/spatial-go/geoos/encoding/geojson"
"github.com/spatial-go/geoos/encoding/wkt"
"github.com/spatial-go/geoos/geoencoding/geojson"
"github.com/spatial-go/geoos/geoencoding/wkt"
"github.com/spatial-go/geoos/planar"
"github.com/spatial-go/geoos/space"
)
Expand Down
14 changes: 7 additions & 7 deletions encoding/encoding.go → geoencoding/encoding.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Package encoding is a library for encoding and decoding into Go structs using the geometries.
package encoding
// Package geoencoding is a library for encoding and decoding into Go structs using the geometries.
package geoencoding

import (
"io"

"github.com/spatial-go/geoos/encoding/geobuf"
"github.com/spatial-go/geoos/encoding/geocsv"
"github.com/spatial-go/geoos/encoding/geojson"
"github.com/spatial-go/geoos/encoding/wkb"
"github.com/spatial-go/geoos/encoding/wkt"
"github.com/spatial-go/geoos/geoencoding/geobuf"
"github.com/spatial-go/geoos/geoencoding/geocsv"
"github.com/spatial-go/geoos/geoencoding/geojson"
"github.com/spatial-go/geoos/geoencoding/wkb"
"github.com/spatial-go/geoos/geoencoding/wkt"
"github.com/spatial-go/geoos/space"
)

Expand Down
3 changes: 1 addition & 2 deletions encoding/encoding_test.go → geoencoding/encoding_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// Package encoding is a library for encoding and decoding into Go structs using the geometries.
package encoding
package geoencoding

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package decode

import (
"github.com/spatial-go/geoos/encoding/geobuf/protogeo"
"github.com/spatial-go/geoos/encoding/geojson"
"github.com/spatial-go/geoos/geoencoding/geobuf/protogeo"
"github.com/spatial-go/geoos/geoencoding/geojson"
)

// Decode ...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package decode

import (
"github.com/spatial-go/geoos/encoding/geobuf/protogeo"
"github.com/spatial-go/geoos/encoding/geojson"
"github.com/spatial-go/geoos/geoencoding/geobuf/protogeo"
"github.com/spatial-go/geoos/geoencoding/geojson"
"github.com/spatial-go/geoos/space"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package decode

import (
"github.com/spatial-go/geoos/algorithm/matrix"
"github.com/spatial-go/geoos/encoding/geobuf/protogeo"
"github.com/spatial-go/geoos/encoding/geojson"
"github.com/spatial-go/geoos/geoencoding/geobuf/protogeo"
"github.com/spatial-go/geoos/geoencoding/geojson"
"github.com/spatial-go/geoos/space"
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package encode

import (
"github.com/spatial-go/geoos/encoding/geobuf/protogeo"
"github.com/spatial-go/geoos/encoding/geojson"
"github.com/spatial-go/geoos/geoencoding/geobuf/protogeo"
"github.com/spatial-go/geoos/geoencoding/geojson"
)

// Encode ...
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package encode

import (
"github.com/spatial-go/geoos/encoding/geobuf/protogeo"
"github.com/spatial-go/geoos/encoding/geojson"
"github.com/spatial-go/geoos/geoencoding/geobuf/protogeo"
"github.com/spatial-go/geoos/geoencoding/geojson"
)

// FeatureEncode ...
Expand Down
Loading

0 comments on commit 1a2fd88

Please sign in to comment.