From a647dda378eb57cec630ad9c8931fefc41440e81 Mon Sep 17 00:00:00 2001 From: tianpf Date: Wed, 25 May 2022 17:19:55 +0800 Subject: [PATCH 1/2] add example encoding. --- algorithm/graph/clipping/link.go | 3 +- algorithm/subdivision/voronoi_test.go | 2 +- clusters/dbscan/kdtree_test.go | 6 +- example/data/geobuf.proto | Bin 0 -> 43 bytes example/data/geocsv.csv | 2 + example/data/geojson.json | 1 + example/data/geowkb.wkb | 1 + example/data/geowkt.wkt | 1 + example/encoding/example_encoding.go | 162 ++++++++++++++++++ example/example.go | 4 +- {encoding => geoencoding}/encoding.go | 14 +- {encoding => geoencoding}/encoding_test.go | 3 +- .../geobuf/decode/decode.go | 4 +- .../geobuf/decode/feature.go | 4 +- .../geobuf/decode/geometry.go | 4 +- .../geobuf/encode/encode.go | 4 +- .../geobuf/encode/feature_encode.go | 4 +- .../geobuf/encode/feature_encode_test.go | 4 +- .../geobuf/encode/featurecollection_encode.go | 4 +- .../geobuf/encode/geometry_encode.go | 4 +- .../geobuf/encode/options.go | 4 +- .../geobuf/geobuf_encoder.go | 8 +- .../geobuf/protogeo/geobuf.pb.go | 0 .../geobuf/protogeo/geobuf.proto | 0 .../geobuf/protogeo/id_encode.go | 0 .../geobuf/protogeo/key_store.go | 0 .../geobuf/protogeo/math.go | 0 .../geobuf/protogeo/value_encode.go | 0 {encoding => geoencoding}/geocsv/geocsv.go | 4 +- .../geocsv/geocsv_encoder.go | 10 +- .../geocsv/geocsv_test.go | 0 {encoding => geoencoding}/geocsv/test1.csv | 0 {encoding => geoencoding}/geocsv/test2.csv | 0 .../geojson/base_encoder.go | 4 +- {encoding => geoencoding}/geojson/bbox.go | 0 .../geojson/bbox_test.go | 0 {encoding => geoencoding}/geojson/feature.go | 0 .../geojson/feature_collection.go | 0 .../geojson/feature_collection_test.go | 0 .../geojson/feature_test.go | 0 .../geojson/geojson_encoder.go | 22 +++ {encoding => geoencoding}/geojson/geometry.go | 0 .../geojson/geometry_test.go | 0 .../geojson/properties.go | 0 .../geojson/properties_test.go | 0 {encoding => geoencoding}/wkb/collection.go | 0 .../wkb/collection_test.go | 0 {encoding => geoencoding}/wkb/line_string.go | 0 .../wkb/line_string_test.go | 0 {encoding => geoencoding}/wkb/point.go | 0 {encoding => geoencoding}/wkb/point_test.go | 0 {encoding => geoencoding}/wkb/polygon.go | 0 {encoding => geoencoding}/wkb/polygon_test.go | 0 {encoding => geoencoding}/wkb/scanner.go | 0 {encoding => geoencoding}/wkb/scanner_test.go | 0 {encoding => geoencoding}/wkb/wkb.go | 0 {encoding => geoencoding}/wkb/wkb_encoder.go | 2 +- .../wkb/wkb_hex_reader.go | 0 .../wkb/wkb_hex_writer.go | 0 {encoding => geoencoding}/wkb/wkb_test.go | 0 {encoding => geoencoding}/wkt/wkt.go | 0 {encoding => geoencoding}/wkt/wkt_encoder.go | 2 +- {encoding => geoencoding}/wkt/wkt_lexer.go | 0 {encoding => geoencoding}/wkt/wkt_parser.go | 0 {encoding => geoencoding}/wkt/wkt_test.go | 0 planar/megrez_measure_test.go | 2 +- planar/megrez_overlay.go | 2 +- planar/megrez_overlay_test.go | 2 +- planar/megrez_produce_test.go | 2 +- planar/megrez_relate_test.go | 2 +- planar/megrez_test.go | 2 +- 71 files changed, 241 insertions(+), 58 deletions(-) create mode 100644 example/data/geobuf.proto create mode 100644 example/data/geocsv.csv create mode 100644 example/data/geojson.json create mode 100644 example/data/geowkb.wkb create mode 100644 example/data/geowkt.wkt create mode 100644 example/encoding/example_encoding.go rename {encoding => geoencoding}/encoding.go (86%) rename {encoding => geoencoding}/encoding_test.go (98%) rename {encoding => geoencoding}/geobuf/decode/decode.go (82%) rename {encoding => geoencoding}/geobuf/decode/feature.go (94%) rename {encoding => geoencoding}/geobuf/decode/geometry.go (97%) rename {encoding => geoencoding}/geobuf/encode/encode.go (91%) rename {encoding => geoencoding}/geobuf/encode/feature_encode.go (90%) rename {encoding => geoencoding}/geobuf/encode/feature_encode_test.go (91%) rename {encoding => geoencoding}/geobuf/encode/featurecollection_encode.go (80%) rename {encoding => geoencoding}/geobuf/encode/geometry_encode.go (96%) rename {encoding => geoencoding}/geobuf/encode/options.go (95%) rename {encoding => geoencoding}/geobuf/geobuf_encoder.go (91%) rename {encoding => geoencoding}/geobuf/protogeo/geobuf.pb.go (100%) rename {encoding => geoencoding}/geobuf/protogeo/geobuf.proto (100%) rename {encoding => geoencoding}/geobuf/protogeo/id_encode.go (100%) rename {encoding => geoencoding}/geobuf/protogeo/key_store.go (100%) rename {encoding => geoencoding}/geobuf/protogeo/math.go (100%) rename {encoding => geoencoding}/geobuf/protogeo/value_encode.go (100%) rename {encoding => geoencoding}/geocsv/geocsv.go (97%) rename {encoding => geoencoding}/geocsv/geocsv_encoder.go (91%) rename {encoding => geoencoding}/geocsv/geocsv_test.go (100%) rename {encoding => geoencoding}/geocsv/test1.csv (100%) rename {encoding => geoencoding}/geocsv/test2.csv (100%) rename {encoding => geoencoding}/geojson/base_encoder.go (96%) rename {encoding => geoencoding}/geojson/bbox.go (100%) rename {encoding => geoencoding}/geojson/bbox_test.go (100%) rename {encoding => geoencoding}/geojson/feature.go (100%) rename {encoding => geoencoding}/geojson/feature_collection.go (100%) rename {encoding => geoencoding}/geojson/feature_collection_test.go (100%) rename {encoding => geoencoding}/geojson/feature_test.go (100%) rename {encoding => geoencoding}/geojson/geojson_encoder.go (71%) rename {encoding => geoencoding}/geojson/geometry.go (100%) rename {encoding => geoencoding}/geojson/geometry_test.go (100%) rename {encoding => geoencoding}/geojson/properties.go (100%) rename {encoding => geoencoding}/geojson/properties_test.go (100%) rename {encoding => geoencoding}/wkb/collection.go (100%) rename {encoding => geoencoding}/wkb/collection_test.go (100%) rename {encoding => geoencoding}/wkb/line_string.go (100%) rename {encoding => geoencoding}/wkb/line_string_test.go (100%) rename {encoding => geoencoding}/wkb/point.go (100%) rename {encoding => geoencoding}/wkb/point_test.go (100%) rename {encoding => geoencoding}/wkb/polygon.go (100%) rename {encoding => geoencoding}/wkb/polygon_test.go (100%) rename {encoding => geoencoding}/wkb/scanner.go (100%) rename {encoding => geoencoding}/wkb/scanner_test.go (100%) rename {encoding => geoencoding}/wkb/wkb.go (100%) rename {encoding => geoencoding}/wkb/wkb_encoder.go (96%) rename {encoding => geoencoding}/wkb/wkb_hex_reader.go (100%) rename {encoding => geoencoding}/wkb/wkb_hex_writer.go (100%) rename {encoding => geoencoding}/wkb/wkb_test.go (100%) rename {encoding => geoencoding}/wkt/wkt.go (100%) rename {encoding => geoencoding}/wkt/wkt_encoder.go (96%) rename {encoding => geoencoding}/wkt/wkt_lexer.go (100%) rename {encoding => geoencoding}/wkt/wkt_parser.go (100%) rename {encoding => geoencoding}/wkt/wkt_test.go (100%) diff --git a/algorithm/graph/clipping/link.go b/algorithm/graph/clipping/link.go index 1db9505..082cdd8 100644 --- a/algorithm/graph/clipping/link.go +++ b/algorithm/graph/clipping/link.go @@ -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" ) diff --git a/algorithm/subdivision/voronoi_test.go b/algorithm/subdivision/voronoi_test.go index 3c99edb..74696ce 100644 --- a/algorithm/subdivision/voronoi_test.go +++ b/algorithm/subdivision/voronoi_test.go @@ -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" ) diff --git a/clusters/dbscan/kdtree_test.go b/clusters/dbscan/kdtree_test.go index f5bc664..2faf5d2 100644 --- a/clusters/dbscan/kdtree_test.go +++ b/clusters/dbscan/kdtree_test.go @@ -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 } diff --git a/example/data/geobuf.proto b/example/data/geobuf.proto new file mode 100644 index 0000000000000000000000000000000000000000..ee74d733257cab64dd780a5ffec99334bb2c5262 GIT binary patch literal 43 ycmd;LEhx$_Fc4spU{aFflHp>LV%adCF(r$Gi>)j%r!>`|h>3wAiY2c!CkFt*stM5m literal 0 HcmV?d00001 diff --git a/example/data/geocsv.csv b/example/data/geocsv.csv new file mode 100644 index 0000000..d852560 --- /dev/null +++ b/example/data/geocsv.csv @@ -0,0 +1,2 @@ +way_id,pt_id,x,y +0,0,102,0.5 diff --git a/example/data/geojson.json b/example/data/geojson.json new file mode 100644 index 0000000..2499b70 --- /dev/null +++ b/example/data/geojson.json @@ -0,0 +1 @@ +{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Point","coordinates":[102,0.5]},"properties":{"prop0":"value0"}}]} \ No newline at end of file diff --git a/example/data/geowkb.wkb b/example/data/geowkb.wkb new file mode 100644 index 0000000..18bdfa9 --- /dev/null +++ b/example/data/geowkb.wkb @@ -0,0 +1 @@ +01070000000100000001010000000000000000805940000000000000e03f \ No newline at end of file diff --git a/example/data/geowkt.wkt b/example/data/geowkt.wkt new file mode 100644 index 0000000..5e49e70 --- /dev/null +++ b/example/data/geowkt.wkt @@ -0,0 +1 @@ +GEOMETRYCOLLECTION(POINT(102 0.5)) \ No newline at end of file diff --git a/example/encoding/example_encoding.go b/example/encoding/example_encoding.go new file mode 100644 index 0000000..e28be91 --- /dev/null +++ b/example/encoding/example_encoding.go @@ -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) + } + } + } +} diff --git a/example/example.go b/example/example.go index fd032ed..3605169 100644 --- a/example/example.go +++ b/example/example.go @@ -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" ) diff --git a/encoding/encoding.go b/geoencoding/encoding.go similarity index 86% rename from encoding/encoding.go rename to geoencoding/encoding.go index eecdf0b..df48c0d 100644 --- a/encoding/encoding.go +++ b/geoencoding/encoding.go @@ -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" ) diff --git a/encoding/encoding_test.go b/geoencoding/encoding_test.go similarity index 98% rename from encoding/encoding_test.go rename to geoencoding/encoding_test.go index 22281ff..f9a39a4 100644 --- a/encoding/encoding_test.go +++ b/geoencoding/encoding_test.go @@ -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" diff --git a/encoding/geobuf/decode/decode.go b/geoencoding/geobuf/decode/decode.go similarity index 82% rename from encoding/geobuf/decode/decode.go rename to geoencoding/geobuf/decode/decode.go index cd67767..907123c 100644 --- a/encoding/geobuf/decode/decode.go +++ b/geoencoding/geobuf/decode/decode.go @@ -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 ... diff --git a/encoding/geobuf/decode/feature.go b/geoencoding/geobuf/decode/feature.go similarity index 94% rename from encoding/geobuf/decode/feature.go rename to geoencoding/geobuf/decode/feature.go index 0eb877a..3237b6b 100644 --- a/encoding/geobuf/decode/feature.go +++ b/geoencoding/geobuf/decode/feature.go @@ -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" ) diff --git a/encoding/geobuf/decode/geometry.go b/geoencoding/geobuf/decode/geometry.go similarity index 97% rename from encoding/geobuf/decode/geometry.go rename to geoencoding/geobuf/decode/geometry.go index 8ce89c2..bddf97f 100644 --- a/encoding/geobuf/decode/geometry.go +++ b/geoencoding/geobuf/decode/geometry.go @@ -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" ) diff --git a/encoding/geobuf/encode/encode.go b/geoencoding/geobuf/encode/encode.go similarity index 91% rename from encoding/geobuf/encode/encode.go rename to geoencoding/geobuf/encode/encode.go index 51c2c71..7f83010 100644 --- a/encoding/geobuf/encode/encode.go +++ b/geoencoding/geobuf/encode/encode.go @@ -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 ... diff --git a/encoding/geobuf/encode/feature_encode.go b/geoencoding/geobuf/encode/feature_encode.go similarity index 90% rename from encoding/geobuf/encode/feature_encode.go rename to geoencoding/geobuf/encode/feature_encode.go index 0c71c0d..16f8b6d 100644 --- a/encoding/geobuf/encode/feature_encode.go +++ b/geoencoding/geobuf/encode/feature_encode.go @@ -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 ... diff --git a/encoding/geobuf/encode/feature_encode_test.go b/geoencoding/geobuf/encode/feature_encode_test.go similarity index 91% rename from encoding/geobuf/encode/feature_encode_test.go rename to geoencoding/geobuf/encode/feature_encode_test.go index fafbe2b..c7dc727 100644 --- a/encoding/geobuf/encode/feature_encode_test.go +++ b/geoencoding/geobuf/encode/feature_encode_test.go @@ -4,8 +4,8 @@ import ( "fmt" "testing" - "github.com/spatial-go/geoos/encoding/geobuf/decode" - "github.com/spatial-go/geoos/encoding/geojson" + "github.com/spatial-go/geoos/geoencoding/geobuf/decode" + "github.com/spatial-go/geoos/geoencoding/geojson" ) func TestEncodeFeature(t *testing.T) { diff --git a/encoding/geobuf/encode/featurecollection_encode.go b/geoencoding/geobuf/encode/featurecollection_encode.go similarity index 80% rename from encoding/geobuf/encode/featurecollection_encode.go rename to geoencoding/geobuf/encode/featurecollection_encode.go index 65e6348..493754c 100644 --- a/encoding/geobuf/encode/featurecollection_encode.go +++ b/geoencoding/geobuf/encode/featurecollection_encode.go @@ -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" ) // FeatureCollection ... diff --git a/encoding/geobuf/encode/geometry_encode.go b/geoencoding/geobuf/encode/geometry_encode.go similarity index 96% rename from encoding/geobuf/encode/geometry_encode.go rename to geoencoding/geobuf/encode/geometry_encode.go index a84a090..9926d71 100644 --- a/encoding/geobuf/encode/geometry_encode.go +++ b/geoencoding/geobuf/encode/geometry_encode.go @@ -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" "github.com/spatial-go/geoos/space" ) diff --git a/encoding/geobuf/encode/options.go b/geoencoding/geobuf/encode/options.go similarity index 95% rename from encoding/geobuf/encode/options.go rename to geoencoding/geobuf/encode/options.go index b784b69..faceb39 100644 --- a/encoding/geobuf/encode/options.go +++ b/geoencoding/geobuf/encode/options.go @@ -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" "github.com/spatial-go/geoos/space" ) diff --git a/encoding/geobuf/geobuf_encoder.go b/geoencoding/geobuf/geobuf_encoder.go similarity index 91% rename from encoding/geobuf/geobuf_encoder.go rename to geoencoding/geobuf/geobuf_encoder.go index 33e1c58..395e7e6 100644 --- a/encoding/geobuf/geobuf_encoder.go +++ b/geoencoding/geobuf/geobuf_encoder.go @@ -3,10 +3,10 @@ package geobuf import ( "io" - "github.com/spatial-go/geoos/encoding/geobuf/decode" - "github.com/spatial-go/geoos/encoding/geobuf/encode" - "github.com/spatial-go/geoos/encoding/geobuf/protogeo" - "github.com/spatial-go/geoos/encoding/geojson" + "github.com/spatial-go/geoos/geoencoding/geobuf/decode" + "github.com/spatial-go/geoos/geoencoding/geobuf/encode" + "github.com/spatial-go/geoos/geoencoding/geobuf/protogeo" + "github.com/spatial-go/geoos/geoencoding/geojson" "github.com/spatial-go/geoos/space" "google.golang.org/protobuf/proto" ) diff --git a/encoding/geobuf/protogeo/geobuf.pb.go b/geoencoding/geobuf/protogeo/geobuf.pb.go similarity index 100% rename from encoding/geobuf/protogeo/geobuf.pb.go rename to geoencoding/geobuf/protogeo/geobuf.pb.go diff --git a/encoding/geobuf/protogeo/geobuf.proto b/geoencoding/geobuf/protogeo/geobuf.proto similarity index 100% rename from encoding/geobuf/protogeo/geobuf.proto rename to geoencoding/geobuf/protogeo/geobuf.proto diff --git a/encoding/geobuf/protogeo/id_encode.go b/geoencoding/geobuf/protogeo/id_encode.go similarity index 100% rename from encoding/geobuf/protogeo/id_encode.go rename to geoencoding/geobuf/protogeo/id_encode.go diff --git a/encoding/geobuf/protogeo/key_store.go b/geoencoding/geobuf/protogeo/key_store.go similarity index 100% rename from encoding/geobuf/protogeo/key_store.go rename to geoencoding/geobuf/protogeo/key_store.go diff --git a/encoding/geobuf/protogeo/math.go b/geoencoding/geobuf/protogeo/math.go similarity index 100% rename from encoding/geobuf/protogeo/math.go rename to geoencoding/geobuf/protogeo/math.go diff --git a/encoding/geobuf/protogeo/value_encode.go b/geoencoding/geobuf/protogeo/value_encode.go similarity index 100% rename from encoding/geobuf/protogeo/value_encode.go rename to geoencoding/geobuf/protogeo/value_encode.go diff --git a/encoding/geocsv/geocsv.go b/geoencoding/geocsv/geocsv.go similarity index 97% rename from encoding/geocsv/geocsv.go rename to geoencoding/geocsv/geocsv.go index c43d23b..92bb6a3 100644 --- a/encoding/geocsv/geocsv.go +++ b/geoencoding/geocsv/geocsv.go @@ -9,8 +9,8 @@ import ( "strconv" "strings" - "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/space" "github.com/spatial-go/geoos/utils" "golang.org/x/text/encoding/simplifiedchinese" diff --git a/encoding/geocsv/geocsv_encoder.go b/geoencoding/geocsv/geocsv_encoder.go similarity index 91% rename from encoding/geocsv/geocsv_encoder.go rename to geoencoding/geocsv/geocsv_encoder.go index 7deb78a..2530bee 100644 --- a/encoding/geocsv/geocsv_encoder.go +++ b/geoencoding/geocsv/geocsv_encoder.go @@ -6,7 +6,7 @@ import ( "io" "log" - "github.com/spatial-go/geoos/encoding/geojson" + "github.com/spatial-go/geoos/geoencoding/geojson" "github.com/spatial-go/geoos/space" ) @@ -45,13 +45,9 @@ func (e *GeocsvEncoder) Decode(s []byte) (space.Geometry, error) { if len(gc.headers) != 4 { log.Printf("length of headers is wrong") } - if len(gc.rows) != 4 { - log.Printf("length of rows is wrong") - } + features := gc.ToGeoJSON() - if len(features.Features) != 4 { - log.Printf("length of features is wrong") - } + coll := make(space.Collection, len(features.Features)) for i, f := range features.Features { coll[i] = f.Geometry.Coordinates.(space.Point) diff --git a/encoding/geocsv/geocsv_test.go b/geoencoding/geocsv/geocsv_test.go similarity index 100% rename from encoding/geocsv/geocsv_test.go rename to geoencoding/geocsv/geocsv_test.go diff --git a/encoding/geocsv/test1.csv b/geoencoding/geocsv/test1.csv similarity index 100% rename from encoding/geocsv/test1.csv rename to geoencoding/geocsv/test1.csv diff --git a/encoding/geocsv/test2.csv b/geoencoding/geocsv/test2.csv similarity index 100% rename from encoding/geocsv/test2.csv rename to geoencoding/geocsv/test2.csv diff --git a/encoding/geojson/base_encoder.go b/geoencoding/geojson/base_encoder.go similarity index 96% rename from encoding/geojson/base_encoder.go rename to geoencoding/geojson/base_encoder.go index ce22890..e3722a9 100644 --- a/encoding/geojson/base_encoder.go +++ b/geoencoding/geojson/base_encoder.go @@ -85,7 +85,7 @@ func GeometryToFeatureCollection(geom space.Geometry) *FeatureCollection { switch geom.GeoJSONType() { case space.TypeCollection: features := []*Feature{} - for _, v := range geom.(space.Collection) { + for _, v := range geom.Geom().(space.Collection) { geometry := NewGeometry(v) feature := NewFeature(*geometry) features = append(features, feature) @@ -94,7 +94,7 @@ func GeometryToFeatureCollection(geom space.Geometry) *FeatureCollection { default: features := []*Feature{} - geometry := NewGeometry(geom) + geometry := NewGeometry(geom.Geom()) feature := NewFeature(*geometry) features = append(features, feature) fc.Features = features diff --git a/encoding/geojson/bbox.go b/geoencoding/geojson/bbox.go similarity index 100% rename from encoding/geojson/bbox.go rename to geoencoding/geojson/bbox.go diff --git a/encoding/geojson/bbox_test.go b/geoencoding/geojson/bbox_test.go similarity index 100% rename from encoding/geojson/bbox_test.go rename to geoencoding/geojson/bbox_test.go diff --git a/encoding/geojson/feature.go b/geoencoding/geojson/feature.go similarity index 100% rename from encoding/geojson/feature.go rename to geoencoding/geojson/feature.go diff --git a/encoding/geojson/feature_collection.go b/geoencoding/geojson/feature_collection.go similarity index 100% rename from encoding/geojson/feature_collection.go rename to geoencoding/geojson/feature_collection.go diff --git a/encoding/geojson/feature_collection_test.go b/geoencoding/geojson/feature_collection_test.go similarity index 100% rename from encoding/geojson/feature_collection_test.go rename to geoencoding/geojson/feature_collection_test.go diff --git a/encoding/geojson/feature_test.go b/geoencoding/geojson/feature_test.go similarity index 100% rename from encoding/geojson/feature_test.go rename to geoencoding/geojson/feature_test.go diff --git a/encoding/geojson/geojson_encoder.go b/geoencoding/geojson/geojson_encoder.go similarity index 71% rename from encoding/geojson/geojson_encoder.go rename to geoencoding/geojson/geojson_encoder.go index 13111d1..2ad5c86 100644 --- a/encoding/geojson/geojson_encoder.go +++ b/geoencoding/geojson/geojson_encoder.go @@ -2,6 +2,8 @@ package geojson import ( "io" + "log" + "strings" "github.com/spatial-go/geoos/space" ) @@ -19,6 +21,26 @@ func (e *GeojsonEncoder) Encode(g space.Geometry) []byte { // Decode Returns geometry of that decode string by codeType. func (e *GeojsonEncoder) Decode(s []byte) (space.Geometry, error) { + if strings.Contains(string(s[9:20]), "FeatureCollection") { + if colls, err := UnmarshalFeatureCollection(s); err != nil { + log.Println(err) + return nil, err + } else { + geom := space.Collection{} + for _, v := range colls.Features { + geom = append(geom, v.Geometry.Geometry()) + } + return geom, nil + } + } else if strings.Contains(string(s[9:20]), "Feature") { + if feat, err := UnmarshalFeature(s); err != nil { + log.Println(err) + return nil, err + } else { + geom := feat.Geometry.Geometry() + return geom, nil + } + } geom, err := UnmarshalGeometry(s) return geom.Geometry(), err } diff --git a/encoding/geojson/geometry.go b/geoencoding/geojson/geometry.go similarity index 100% rename from encoding/geojson/geometry.go rename to geoencoding/geojson/geometry.go diff --git a/encoding/geojson/geometry_test.go b/geoencoding/geojson/geometry_test.go similarity index 100% rename from encoding/geojson/geometry_test.go rename to geoencoding/geojson/geometry_test.go diff --git a/encoding/geojson/properties.go b/geoencoding/geojson/properties.go similarity index 100% rename from encoding/geojson/properties.go rename to geoencoding/geojson/properties.go diff --git a/encoding/geojson/properties_test.go b/geoencoding/geojson/properties_test.go similarity index 100% rename from encoding/geojson/properties_test.go rename to geoencoding/geojson/properties_test.go diff --git a/encoding/wkb/collection.go b/geoencoding/wkb/collection.go similarity index 100% rename from encoding/wkb/collection.go rename to geoencoding/wkb/collection.go diff --git a/encoding/wkb/collection_test.go b/geoencoding/wkb/collection_test.go similarity index 100% rename from encoding/wkb/collection_test.go rename to geoencoding/wkb/collection_test.go diff --git a/encoding/wkb/line_string.go b/geoencoding/wkb/line_string.go similarity index 100% rename from encoding/wkb/line_string.go rename to geoencoding/wkb/line_string.go diff --git a/encoding/wkb/line_string_test.go b/geoencoding/wkb/line_string_test.go similarity index 100% rename from encoding/wkb/line_string_test.go rename to geoencoding/wkb/line_string_test.go diff --git a/encoding/wkb/point.go b/geoencoding/wkb/point.go similarity index 100% rename from encoding/wkb/point.go rename to geoencoding/wkb/point.go diff --git a/encoding/wkb/point_test.go b/geoencoding/wkb/point_test.go similarity index 100% rename from encoding/wkb/point_test.go rename to geoencoding/wkb/point_test.go diff --git a/encoding/wkb/polygon.go b/geoencoding/wkb/polygon.go similarity index 100% rename from encoding/wkb/polygon.go rename to geoencoding/wkb/polygon.go diff --git a/encoding/wkb/polygon_test.go b/geoencoding/wkb/polygon_test.go similarity index 100% rename from encoding/wkb/polygon_test.go rename to geoencoding/wkb/polygon_test.go diff --git a/encoding/wkb/scanner.go b/geoencoding/wkb/scanner.go similarity index 100% rename from encoding/wkb/scanner.go rename to geoencoding/wkb/scanner.go diff --git a/encoding/wkb/scanner_test.go b/geoencoding/wkb/scanner_test.go similarity index 100% rename from encoding/wkb/scanner_test.go rename to geoencoding/wkb/scanner_test.go diff --git a/encoding/wkb/wkb.go b/geoencoding/wkb/wkb.go similarity index 100% rename from encoding/wkb/wkb.go rename to geoencoding/wkb/wkb.go diff --git a/encoding/wkb/wkb_encoder.go b/geoencoding/wkb/wkb_encoder.go similarity index 96% rename from encoding/wkb/wkb_encoder.go rename to geoencoding/wkb/wkb_encoder.go index 1da1179..4637a4f 100644 --- a/encoding/wkb/wkb_encoder.go +++ b/geoencoding/wkb/wkb_encoder.go @@ -3,7 +3,7 @@ package wkb import ( "io" - "github.com/spatial-go/geoos/encoding/geojson" + "github.com/spatial-go/geoos/geoencoding/geojson" "github.com/spatial-go/geoos/space" ) diff --git a/encoding/wkb/wkb_hex_reader.go b/geoencoding/wkb/wkb_hex_reader.go similarity index 100% rename from encoding/wkb/wkb_hex_reader.go rename to geoencoding/wkb/wkb_hex_reader.go diff --git a/encoding/wkb/wkb_hex_writer.go b/geoencoding/wkb/wkb_hex_writer.go similarity index 100% rename from encoding/wkb/wkb_hex_writer.go rename to geoencoding/wkb/wkb_hex_writer.go diff --git a/encoding/wkb/wkb_test.go b/geoencoding/wkb/wkb_test.go similarity index 100% rename from encoding/wkb/wkb_test.go rename to geoencoding/wkb/wkb_test.go diff --git a/encoding/wkt/wkt.go b/geoencoding/wkt/wkt.go similarity index 100% rename from encoding/wkt/wkt.go rename to geoencoding/wkt/wkt.go diff --git a/encoding/wkt/wkt_encoder.go b/geoencoding/wkt/wkt_encoder.go similarity index 96% rename from encoding/wkt/wkt_encoder.go rename to geoencoding/wkt/wkt_encoder.go index 9cc1db9..d7ae20f 100644 --- a/encoding/wkt/wkt_encoder.go +++ b/geoencoding/wkt/wkt_encoder.go @@ -3,7 +3,7 @@ package wkt import ( "io" - "github.com/spatial-go/geoos/encoding/geojson" + "github.com/spatial-go/geoos/geoencoding/geojson" "github.com/spatial-go/geoos/space" ) diff --git a/encoding/wkt/wkt_lexer.go b/geoencoding/wkt/wkt_lexer.go similarity index 100% rename from encoding/wkt/wkt_lexer.go rename to geoencoding/wkt/wkt_lexer.go diff --git a/encoding/wkt/wkt_parser.go b/geoencoding/wkt/wkt_parser.go similarity index 100% rename from encoding/wkt/wkt_parser.go rename to geoencoding/wkt/wkt_parser.go diff --git a/encoding/wkt/wkt_test.go b/geoencoding/wkt/wkt_test.go similarity index 100% rename from encoding/wkt/wkt_test.go rename to geoencoding/wkt/wkt_test.go diff --git a/planar/megrez_measure_test.go b/planar/megrez_measure_test.go index ab5e5fd..390e8f2 100644 --- a/planar/megrez_measure_test.go +++ b/planar/megrez_measure_test.go @@ -3,7 +3,7 @@ package planar import ( "testing" - "github.com/spatial-go/geoos/encoding/wkt" + "github.com/spatial-go/geoos/geoencoding/wkt" "github.com/spatial-go/geoos/space" ) diff --git a/planar/megrez_overlay.go b/planar/megrez_overlay.go index 8ebc77b..8957780 100644 --- a/planar/megrez_overlay.go +++ b/planar/megrez_overlay.go @@ -6,7 +6,7 @@ import ( "github.com/spatial-go/geoos/algorithm/matrix" "github.com/spatial-go/geoos/algorithm/overlay" "github.com/spatial-go/geoos/algorithm/sharedpaths" - "github.com/spatial-go/geoos/encoding/wkt" + "github.com/spatial-go/geoos/geoencoding/wkt" "github.com/spatial-go/geoos/space" "github.com/spatial-go/geoos/space/spaceerr" ) diff --git a/planar/megrez_overlay_test.go b/planar/megrez_overlay_test.go index 9f60fa6..9ef40fb 100644 --- a/planar/megrez_overlay_test.go +++ b/planar/megrez_overlay_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/spatial-go/geoos" - "github.com/spatial-go/geoos/encoding/wkt" + "github.com/spatial-go/geoos/geoencoding/wkt" "github.com/spatial-go/geoos/space" ) diff --git a/planar/megrez_produce_test.go b/planar/megrez_produce_test.go index d58d76a..3cdacb4 100644 --- a/planar/megrez_produce_test.go +++ b/planar/megrez_produce_test.go @@ -4,7 +4,7 @@ import ( "reflect" "testing" - "github.com/spatial-go/geoos/encoding/wkt" + "github.com/spatial-go/geoos/geoencoding/wkt" "github.com/spatial-go/geoos/space" ) diff --git a/planar/megrez_relate_test.go b/planar/megrez_relate_test.go index b6fe277..d641f1b 100644 --- a/planar/megrez_relate_test.go +++ b/planar/megrez_relate_test.go @@ -5,7 +5,7 @@ import ( "testing" "github.com/spatial-go/geoos" - "github.com/spatial-go/geoos/encoding/wkt" + "github.com/spatial-go/geoos/geoencoding/wkt" "github.com/spatial-go/geoos/space" ) diff --git a/planar/megrez_test.go b/planar/megrez_test.go index 0b2e9a5..af33d6e 100644 --- a/planar/megrez_test.go +++ b/planar/megrez_test.go @@ -3,7 +3,7 @@ package planar import ( "testing" - "github.com/spatial-go/geoos/encoding/wkt" + "github.com/spatial-go/geoos/geoencoding/wkt" "github.com/spatial-go/geoos/space" ) From 0a4caad11ac77731a07fa1520358181ec83c41d3 Mon Sep 17 00:00:00 2001 From: tianpf Date: Thu, 26 May 2022 11:24:09 +0800 Subject: [PATCH 2/2] Update Change log. --- CHANGELOG.md | 7 ++++++- CHANGELOG.zh-CN.md | 6 +++++- README.md | 22 ++-------------------- README.zh-CN.md | 22 ++-------------------- 4 files changed, 15 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4d270f..98dcf07 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/CHANGELOG.zh-CN.md b/CHANGELOG.zh-CN.md index 8611c5c..e6365df 100644 --- a/CHANGELOG.zh-CN.md +++ b/CHANGELOG.zh-CN.md @@ -1,5 +1,9 @@ # 更新日志 - +## [1.1.0] - 2022-05-26 +### 新增 +- 优化几何体的拓扑关系算法以及几何运算算法,提升了计算的性能 +- 规范了geoencoding的编码和解码方法,实现了encoder接口 +- 增加了对坐标系的支持 ## [1.0.4] - 2021-12-31 ### 新增 - 德劳内三角形方法与沃罗诺伊图 diff --git a/README.md b/README.md index 9100a95..24ce20e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/README.zh-CN.md b/README.zh-CN.md index ee630d2..7924173 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -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) ## 维护者