Git Product home page Git Product logo

geoos's Introduction

Geoos

Our organization spatial-go is officially established! The first open source project Geoos(Using Golang) provides spatial data and geometric algorithms. All comments and suggestions are welcome!

Guides

http://www.spatial-go.com

Contents

Structure

1.algorithm Package algorithm defines Specifies Computational Geometric and algorithm err. 2.clusters Package clusters is a spatial clustering algorithm. 3.coordtransform Package coordtransform is for transform coord. 4.example Example This is an example . 5.geoencoding Package geoencoding is a library for encoding and decoding into Go structs using the geometries. 6.grid Package grid is used to generate grid data. 7.index Package index define spatial index interface. 8.planar Package planar provides support for the implementation of spatial operations and geometric algorithms. 9.space Package space A representation of a linear vector geometry. 10.utils Package utils A functions of utils.

Documentation

How to use Geoos: Example: Calculating area via Geoos

package main

import (
	"bytes"
	"fmt"

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

func main() {
	// First, choose the default algorithm.
	strategy := planar.NormalStrategy()
	// Secondly, manufacturing test data and convert it to geometry
	const polygon = `POLYGON((-1 -1, 1 -1, 1 1, -1 1, -1 -1))`
	// geometry, _ := wkt.UnmarshalString(polygon)

	buf0 := new(bytes.Buffer)
	buf0.Write([]byte(polygon))
	geometry, _ := geoencoding.Read(buf0, geoencoding.WKT)

	// Last, call the Area () method and get result.
	area, e := strategy.Area(geometry)
	if e != nil {
		fmt.Printf(e.Error())
	}
	fmt.Printf("%f", area)
	// get result 4.0
}

Example: geoencoding example_encoding.go

Maintainer

@spatial-go

Contributing

We will also uphold the concept of "openness, co-creation, and win-win" to contribute in the field of space computing.

Welcome to join us !please report an issue

Email Address: [email protected]

License

Geoos is licensed under the: LGPL-2.1

geoos's People

Contributors

7499060 avatar abirdcfly avatar aichibazhang avatar asturm-fe avatar bean0303 avatar ch0pp3rvirus avatar coolwxb avatar dituwuyou avatar djm93dev avatar publicpwd avatar tianpf avatar xiaogu-space avatar zhaoxinqing avatar zhyt1985 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

geoos's Issues

A problem of the method space.Contains()

While using the method space.Contains() to determine whether Geometry A contains Geometry B,I found that in some cases the result returned is not as expected. The code is as follows:

type TestStruct struct {
	name    string
	args    args
	want    bool
	wantErr bool
}
func TestAlgorithm_Contains(t *testing.T) {
	const polygon1 = `POLYGON((1 1,5 1,5 5,1 5,1 1))`
	const polygon2 = `POLYGON((2 2,3 2,3 3,2 3,2 2))`

	p1, _ := wkt.UnmarshalString(polygon1)
	p2, _ := wkt.UnmarshalString(polygon2)

	tests := []TestStruct{
		{name: "contain", args: args{
			g1: p1,
			g2: p2,
		}, want: true, wantErr: false},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			G := NormalStrategy()
			got, err := G.Contains(tt.args.g1, tt.args.g2) // got = true
			if (err != nil) != tt.wantErr {
				t.Errorf("Contains() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			if got != tt.want {
				t.Errorf("Contains() got = %v, want %v", got, tt.want)
			}
		})
	}
}

and the corresponding image is

image-20220118212319961

obviously it is correct.

But when I change the parameters, where polygon1 = POLYGON((113.48581807062143 23.33621329259057,113.48785155569199 23.336383160940287,113.48792833916376 23.335028970144833,113.48582512451681 23.33493907732756,113.48581807062143 23.33621329259057)) and polygon2 = POLYGON((113.48668269733025 23.335774475286513,113.48720314737876 23.3358047169134,113.4873120145494 23.335572135724533,113.48676140749377 23.33538486387792,113.48668269733025 23.335774475286513)),the result returned is false,but it should actually be true, as the image shows:

image-20220118213111364

I want to judge whether a POLYGON A contains another POLYGON B, but the result returned by this method does not match the actual one, or is there another more suitable way to judge? Hope someone can answer my doubts,thank you very much.

I cannot install

go version
go version go1.20.2 darwin/amd64

When I try to install:
go get github.com/spatial-go/geoos
go: go.mod file not found in current directory or any parent directory. 'go get' is no longer supported outside a module. To build and install a command, use 'go install' with a version, like 'go install example.com/cmd@latest' For more information, see https://golang.org/doc/go-get-install-deprecation or run 'go help get' or 'go help install'. zsh: exit 1 go get github.com/spatial-go/geoos

With go install
go install github.com/spatial-go/geoos@latest
package github.com/spatial-go/geoos is not a main package zsh: exit 1 go install github.com/spatial-go/geoos@latest

I try to clone repo in go/src/ but when run file:
go run conv.go
conv.go:7:2: no required module provides package github.com/spatial-go/geoos/geoencoding: go.mod file not found in current directory or any parent directory; see 'go help modules' zsh: exit 1 go run conv.go

geojson Decode()

fc := `{"type":"FeatureCollection","features":[{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[122.993197,41.117725],[122.999399,41.115696],[122.99573,41.109516],[122.987146,41.106994],[122.984775,41.107699],[122.990687,41.117878],[122.993197,41.117725]]]},"properties":{}}]}`
_, err := geoencoding.Decode([]byte(fc), geoencoding.GeoJSON)
fmt.Println(err)

report error: geojson: not a feature: type=FeatureCollection

I thought the correct should be
if strings.Contains(string(s[9:26]), "FeatureCollection") {
rather than
if strings.Contains(string(s[9:20]), "FeatureCollection") {

Convex Hull

Is there any initiative to implement a function to calculate the ConvexHull for a list of Points (and specifically: for clusters) ?

The function Buffer return a wrong geometry

I pass a linestring to function buffer and get a polygon, but the polygon is wrong.look at the image below.
wrong geometry
image
correct geometry
image

sLineString, _ := wkt.UnmarshalString("LINESTRING (12925610.710013045 4856270.465739663, 12925562.342807498 4856370.568506251, 12925554.8522816 4856387.370610655)")
G := NormalStrategy()
got := G.Buffer(sLineString, 10, 8)
// got is 'POLYGON ((12925553.33876128 4856366.217971605, 12925553.209322736 4856366.496718426, 12925545.718796838 4856383.29882283, 12925545.099927789 4856385.158915575, 12925544.855836228 4856387.104002521, 12925544.995902454 4856389.059335069, 12925545.514743807 4856390.949770884, 12925546.392421499 4856392.702661579, 12925547.59520687 4856394.250644547, 12925549.076877553 4856395.534231671, 12925550.780493775 4856396.504095417, 12925552.64058652 4856397.122964467, 12925554.585673466 4856397.367056029, 12925556.541006014 4856397.2269898, 12925558.431441829 4856396.70814845, 12925560.184332523 4856395.830470758, 12925561.732315492 4856394.627685386, 12925563.015902616 4856393.1460147025, 12925563.985766362 4856391.44239848, 12925571.47629226 4856374.640294076, 12925566.909549879 4856372.6044001635, 12925566.844830606 4856372.743773574, 12925571.346853716 4856374.919040897, 12925619.714059263 4856274.816274309, 12925620.389796244 4856272.976077729, 12925620.693544587 4856271.039410265, 12925620.61363141 4856269.080696963, 12925620.153127734 4856267.175210074, 12925619.329730455 4856265.396176391, 12925618.175082272 4856263.811963183, 12925616.733555663 4856262.483450873, 12925615.06054769 4856261.461693445, 12925613.220351111 4856260.785956463, 12925611.283683648 4856260.482208122, 12925609.324970344 4856260.562121298, 12925607.419483457 4856261.022624974, 12925605.640449774 4856261.846022252, 12925604.056236565 4856263.000670436, 12925602.727724256 4856264.442197044, 12925601.705966827 4856266.115205017, 12925553.33876128 4856366.217971605))'
// the correct polygon maybe like this 'POLYGON ((12925553.33876128 4856366.217971605, 12925553.209322736 4856366.496718426, 12925545.718796838 4856383.29882283, 12925545.099927789 4856385.158915575, 12925544.855836228 4856387.104002521, 12925544.995902454 4856389.059335069, 12925545.514743807 4856390.949770884, 12925546.392421499 4856392.702661579, 12925547.59520687 4856394.250644547, 12925549.076877553 4856395.534231671, 12925550.780493775 4856396.504095417, 12925552.64058652 4856397.122964467, 12925554.585673466 4856397.367056029, 12925556.541006014 4856397.2269898, 12925558.431441829 4856396.70814845, 12925560.184332523 4856395.830470758, 12925561.732315492 4856394.627685386, 12925563.015902616 4856393.1460147025, 12925563.985766362 4856391.44239848, 12925571.413714938 4856374.780662151, 12925619.714059263 4856274.816274309, 12925620.389796244 4856272.976077729, 12925620.693544587 4856271.039410265, 12925620.61363141 4856269.080696963, 12925620.153127734 4856267.175210074, 12925619.329730455 4856265.396176391, 12925618.175082272 4856263.811963183, 12925616.733555663 4856262.483450873, 12925615.06054769 4856261.461693445, 12925613.220351111 4856260.785956463, 12925611.283683648 4856260.482208122, 12925609.324970344 4856260.562121298, 12925607.419483457 4856261.022624974, 12925605.640449774 4856261.846022252, 12925604.056236565 4856263.000670436, 12925602.727724256 4856264.442197044, 12925601.705966827 4856266.115205017, 12925553.33876128 4856366.217971605))'

a problem of distanceLineAndLine

	line0 := space.LineString{{116.40495300292967, 39.926785883895654}, {116.3975715637207, 39.9295502919}}
	line1 := space.LineString{{116.37310981750488, 39.92099342895789}, {116.39928817749023, 39.9174387253541}}
	fmt.Println(line1.Distance(line0))

0 <nil>

dist is initialized with 0, this for impossible in
if distP, _ := elem.Distance(); dist > distP {
dist = distP
}

var dist float64
modified with
var dist float64 = math.MaxFloat64


修改问题源码
func (el *ElementDistance) distanceLineAndLine() (float64, error) {
	var dist float64 
	if mark := relate.IsIntersectionEdge(el.From.(matrix.LineMatrix), el.To.(matrix.LineMatrix)); mark {
		return 0, nil
	}
	for _, v := range el.From.(matrix.LineMatrix) {
		elem := &ElementDistance{matrix.Matrix(v), el.To, el.F}
		if distP, _ := elem.Distance(); dist > distP {
			dist = distP
		}
	}
	return dist, nil
}

Find intersection of two geometries?

Hello, and thank you for this project!

Is it possible to calculate the spatial intersection of two geometries? Say, the point where two lines intersect? I wasn't able to find it in the docs.

发现一个缓冲区分析bug


const d = `{"type":"LineString","coordinates":[[148.3,23.9],[149.3,25],[149.5,25.3],[149.5,25.3],[149.5,25.3],[149.9,26.1],[150.2,26.4],[150.5,27.1],[150.5,27.1],[150.8,28.8],[150.8,28.8],[150.9,29.2],[150.7,29.7],[150.8,30.1],[150.6,30.4],[150.4,30.6],[150.1,31.6],[149.8,32.5]]}`
g, _ := geoencoding.Decode([]byte(d), geoencoding.GeoJSON)
b := g.BufferInMeter(100, calc.QuadrantSegments)
fmt.Println(string(geoencoding.Encode(b, geoencoding.WKT)))

返回结果中存在很多NaN,返回结果如下:

POLYGON((149.29921586139045 25.000588113059923,NaN NaN,149.4990720118337 25.30037798677464,149.89907201183368 26.100375455240716,149.89914706649813 26.100498760295352,149.899242
28147618 26.100610276338013,150.19924228147616 26.40060870255267,NaN NaN,150.4989943229493 27.100139551904082,NaN NaN,150.79900567017944 28.800190521518022,150.8990056701794 29.
20018978565512,150.69903881583426 29.699709188528097,150.69899396085847 29.699865864360323,150.69898265359106 29.70002701287475,150.69900527108788 29.700187260352127,150.7990052
7108794 30.10018651010826,150.59911798315972 30.399561890373853,150.3992289238104 30.59942813752714,150.39909781968294 30.59959441563601,150.3990141831927 30.599782033025665,150
.09901418319268 31.599784315923866,149.79902051880478 32.4997666111684,149.79898535265346 32.49993225733657,149.79898917883068 32.500100506508375,149.79903185029852 32.500264892
96596,149.79911172721646 32.500419099468,149.79922573995933 32.500557200011805,149.79936950708134 32.500673887556204,149.79953750369262 32.50076467795526,149.79972327377766 32.5
0082608226746,149.79991967829622 32.50085574082134,149.8001191695328 32.500852513886876,149.80031408115107 32.50081652546986,149.80049692280687 32.50074915854693,149.80066066799
785 32.50065300192449,149.80079902408818 32.50053175076223,149.8009066741309 32.500390064583456,149.8009794811952 32.50023338822593,150.10097948119522 31.600235694878712,150.100
9858168073 31.60021568357662,150.40098581680732 30.60021796648385,150.6007710761896 30.40057303614954,150.60088201684027 30.40043810766075,150.80088201684026 30.100439447496502,
150.8009600570297 30.100292430107576,150.8010056916988 30.100135541888058,150.80101738050664 30.099974078368952,150.80099472891214 30.099813489539766,150.70099472891212 29.69981
2739298796,150.9009611841657 29.200292247081364,150.90100613383842 29.200134258372675,150.90101730742316 29.199971762339494,150.90099432982058 29.199810213993548,NaN NaN,150.801
00567705074 28.799862627877324,NaN NaN,150.50095058750804 27.099676147743672,150.20095058750803 26.399674147279168,150.20086862381865 26.399524804326035,150.2007577185238 26.399
39129423718,149.9007577185238 26.09938972047752,NaN NaN,149.5008714400348 25.299524557295143,149.3008714400348 24.999523387088384,149.30078413860957 24.999411884125102,148.30078
413860957 23.89940672780346,148.30064247505413 23.899278266075022,148.30047612154266 23.899177540150923,148.30029147094731 23.899108420940394,148.30009561928694 23.8990735647080
93,148.29989609303098 23.899074310987338,148.29970055986155 23.899110631098452,148.29951653400875 23.89918112925092,148.29935108748282 23.89928309618727,148.29921057830106 23.89
9412613306403,148.29910040615243 23.8995647032637,148.2990248048909 23.899733521258984,148.2989866798305 23.899912579659166,148.29898749609595 23.900094997322515,148.29902722231
86 23.900273764041103,148.29910433184202 23.900442009939216,148.29921586139045 23.900593269474307,149.29921586139045 25.000588113059923))

The result of function "Intersection" is wrong.

I call function "Intersection" for compute intersection of two geometries, but the result maybe wrong.
case 1

20210927102727

polygon01, _ := wkt.UnmarshalString("POLYGON ((111.30523681640625 38.11727165830543, 112.34344482421875 38.11727165830543, 112.34344482421875 38.89103282648846, 111.30523681640625 38.89103282648846, 111.30523681640625 38.11727165830543))")
polygon02, _ := wkt.UnmarshalString("POLYGON ((111.50848388671875 37.6359849542696, 112.64007568359375 37.6359849542696, 112.64007568359375 38.35027253825765, 111.50848388671875 38.35027253825765, 111.50848388671875 37.6359849542696))")
G := NormalStrategy()
got, err := G.Intersection(polygon01, polygon02)
// got is nil

case 2

tapd_54316281_base64_1632645422_42

linestring, _ := wkt.UnmarshalString("LINESTRING (111.98638916015625 38.50357937743225, 111.96372985839844 38.42723559654225, 111.91085815429688 38.344887442462806, 111.87309265136717 38.24680876017446, 111.84906005859375 38.15075747130226)")
polygon, _ := wkt.UnmarshalString("POLYGON ((112.01248168945312 38.4519755295767, 111.7096710205078 38.39441521865825, 111.90948486328125 38.176671418717746, 112.01248168945312 38.4519755295767))")
G := NormalStrategy()
got, err := G.Intersection(linestring, polygon)
// got is 'MULTIPOINT((111.96859688870947 38.44363360825604),(111.86710034242763 38.22285924285058))'
// but correct result maybe like this 'LINESTRING(111.968596888709 38.443633608256,111.963729858398 38.4272355965423,111.910858154297 38.3448874424628,111.873092651367 38.2468087601745,111.867100342428 38.2228592428506)'

Buffer distance unit

What is the distance unit used in Buffer function?

I did some tests like:

	ls := space.LineString{
		{2.073333263397217, 48.81027603149414},  // LFPZ
		{1.5225944519042969, 48.45795440673828}, // LFON
		{1.361388921737671, 48.705833435058594}, //LFOP
	}

	data, _ := geojson.NewGeometry(ls).MarshalJSON()
	v := "trip"
	fmt.Printf("var %s = %s;\nL.geoJSON(%s, {}).addTo(map);\n", v, data, v)

	bls := ls.Buffer(0.01, 4)

	bdata, _ := geojson.NewGeometry(bls).MarshalJSON()
	v = "btrip"
	fmt.Printf("var %s = %s;\nL.geoJSON(%s, {}).addTo(map);\n", v, bdata, v)

It looks like 0.01 creates a 1km buffer around the trip line.

When I compute a distance between 2 points like that:

	d := measure.SpheroidDistance(
		space.Point{2.073333263397217, 48.81027603149414}.ToMatrix(),
		space.Point{1.5225944519042969, 48.45795440673828}.ToMatrix(),
	)
	fmt.Printf("d = %f\n", d/1000)

It looks like distance is in meters.

Can you please clarify?

Thanks in advance.

New in GeoOS version 1.0.2: Methods related to constructing Tyson polygon geometry

We will add a new vector geometry method: The Tyson polygon

Method introduction:
A Tyson polygon is a partition of a spatial plane. It is characterized by the fact that any position in a polygon is closest to the sample point of the polygon (such as a residential point) and far from the sample point in an adjacent polygon, and that each polygon contains only one sample point. Tyson polygon can be used to solve many spatial analysis problems, such as adjacency, proximity and reachability, because of its bisect property in spatial partition.

Thanks for your support 🙏

Added polygon dissovle method

This algorithm takes a vector layer and combines their features into new features. One or more attributes can be specified to dissolve features belonging to the same class (having the same value for the specified attributes), alternatively all features can be dissolved in a single one.
All output geometries will be converted to multi geometries. In case the input is a polygon layer, common boundaries of adjacent polygons being dissolved will get erased.

New filter method in GeoOS version 1.0.2

We will add a filter method to the spatial validity check method. Can help you correct some of the invalid positions of the filter geometry.

Thanks for your support 🙏

The result of function "Union" is wrong.

I call function "Union" for compute intersection of two geometries, but the result maybe wrong.

20210927145739

poly01, _ := wkt.UnmarshalString(`POLYGON((112.48928294957003 39.183075132525914,112.43133544921875 39.25990481501755,111.6046142578125 39.223742741391305,111.2200927734375 38.649053322140226,111.533203125 38.10214399750345,112.43408203124999 38.26621945628273,112.58254734220755 38.75548434361472,113.36517333984375 38.61901643727865,112.6593017578125 39.3746488816007,112.48928294957003 39.183075132525914))`)
poly02, _ := wkt.UnmarshalString(`POLYGON ((112.00561523437499 38.363195134453846, 113.31298828125 37.751172385606196, 113.43658447265625 38.955137225429574, 112.00561523437499 38.363195134453846))`)
G := NormalStrategy()
got, err := G.Union(poly01, poly02)
// got is 'POLYGON((112.52923636879997 38.57979894458389,112.58254734220755 38.75548434361472,112.84381070229523 38.70992738044051,112.52923636879997 38.57979894458389))'
// but correct result maybe like this 'POLYGON((112.27475618753795 38.23720172624033,111.533203125 38.10214399750345,111.2200927734375 38.649053322140226,111.6046142578125 39.223742741391305,112.43133544921875 39.25990481501755,112.48928294957003 39.183075132525914,112.6593017578125 39.3746488816007,113.15860509074275 38.840146845359875,113.43658447265625 38.955137225429574,113.31298828125 37.751172385606196,112.27475618753795 38.23720172624033),(112.84381070229523 38.70992738044051,112.58254734220755 38.75548434361472,112.52923636879997 38.57979894458389,112.84381070229523 38.70992738044051))'

发现一个几何图形相交判断bug

const a1 = "LINESTRING (119.3039141328787309 26.0688567207556332, 119.3036083610503510 26.0681869226817753, 119.3033186824765153 26.0679845368985639)"
const a2 = "POLYGON ((119.3172630350001100 26.0702955380000390, 119.3172497400000793 26.0703321550000737, 119.3172290960000055 26.0703549800000474, 119.3171979140000758 26.0703685560000622, 119.3171192560000691 26.0703590920000465, 119.3150906640000812 26.0699619740000230, 119.3149878960000478 26.0699494980000281, 119.3143222760000981 26.0698098000000300, 119.3139883680000821 26.0697879690000605, 119.3132765640000343 26.0697358590000476, 119.3132011550001153 26.0697304560000589, 119.3129190370000288 26.0697096750000696, 119.3111563600000409 26.0695852310000760, 119.3109965890000694 26.0695196390000774, 119.3107551660000354 26.0694689840000251, 119.3106054270000413 26.0694540860000643, 119.3105945770000744 26.0694530400000417, 119.3105856270000231 26.0694516730000601, 119.3105761370001119 26.0694508760000758, 119.3105671780000421 26.0694500390000599, 119.3105579580001177 26.0694489820000399, 119.3105487380000795 26.0694481760000372, 119.3105397880000282 26.0694470890000503, 119.3105305480000879 26.0694462820000581, 119.3105216080000446 26.0694454650000580, 119.3105123880000065 26.0694443880000790, 119.3105031680000820 26.0694435710000789, 119.3104942080000228 26.0694427650000762, 119.3104849880000984 26.0694416580000734, 119.3104681690000461 26.0694400640000481, 119.3104369790000874 26.0694370640000557, 119.3103078550000191 26.0693934490000743, 119.3102112770000076 26.0693755690000444, 119.3099221230000921 26.0693252120000238, 119.3088639410000269 26.0691093130000695, 119.3086276680000992 26.0690527240000733, 119.3084014460000617 26.0689920200000529, 119.3078483490000963 26.0688210030000391, 119.3075865890000387 26.0687429470000325, 119.3073801560000220 26.0686865570000350, 119.3070351180000443 26.0685920170000713, 119.3069911800000682 26.0685800900000686, 119.3069032920000154 26.0685624780000467, 119.3066070560000753 26.0685197070000640, 119.3064738660000330 26.0685132670000712, 119.3055648530000781 26.0684864910000442, 119.3053117620000876 26.0684792470000275, 119.3007346390000976 26.0683380540000371, 119.3006188190000785 26.0683266760000265, 119.3005433790000325 26.0683196640000574, 119.3005168190001086 26.0683183240000744, 119.3001297180001075 26.0682964810000612, 119.2996200020000970 26.0682958950000625, 119.2993834490000609 26.0683003320000353, 119.2991243780001014 26.0682819690000542, 119.2983976580001126 26.0682839130000730, 119.2981323310000334 26.0683084390000772, 119.2977460480000218 26.0683579540000778, 119.2974045160000287 26.0684075110000322, 119.2965745140000990 26.0685377980000226, 119.2957896610000716 26.0685491330000332, 119.2954264850000072 26.0685515730000361, 119.2948474920000308 26.0685097760000417, 119.2948101140000290 26.0686241440000686, 119.2953998390000834 26.0686505420000572, 119.2958137050001142 26.0686534930000562, 119.2965880250000055 26.0686596380000424, 119.2974137140000721 26.0685480800000278, 119.2977308180001046 26.0684904100000381, 119.2981231100000059 26.0684443940000392, 119.2983781080000654 26.0684130890000461, 119.2990806990001147 26.0684019210000315, 119.2993546810000680 26.0684102540000708, 119.2995790230000921 26.0684185770000454, 119.3000887390001026 26.0684145510000462, 119.3005572210000764 26.0684423330000641, 119.3005629010000348 26.0684431410000457, 119.3006383100000676 26.0684536950000734, 119.3006567700000460 26.0684561280000366, 119.3006977290000350 26.0684620840000321, 119.3007180780000454 26.0684740200000533, 119.3007218740000326 26.0684981680000760, 119.3053149980000853 26.0686393630000453, 119.3055637490000436 26.0686441480000326, 119.3064667840000084 26.0686581810000462, 119.3065940230001161 26.0686689850000448, 119.3067073910000317 26.0686865780000403, 119.3068311080000967 26.0687150200000701, 119.3069512740000846 26.0687434730000405, 119.3069881630000282 26.0687543130000563, 119.3073364600001014 26.0688575640000408, 119.3074984030000678 26.0689052580000293, 119.3077775230000270 26.0689833080000426, 119.3085641160000705 26.0691944590000730, 119.3088245570000936 26.0692634930000509, 119.3104337000000896 26.0695586580000622, 119.3104681500000197 26.0695621660000256, 119.3105988980000802 26.0695759610000550, 119.3107415770000443 26.0695908320000740, 119.3109618480000336 26.0696518090000495, 119.3111069680001037 26.0697228380000752, 119.3128978550000738 26.0698554030000764, 119.3131954130000167 26.0698761580000564, 119.3132700220000970 26.0698810410000306, 119.3139812860000575 26.0699304300000563, 119.3143030130000852 26.0699590790000570, 119.3149478770000087 26.0700692340000728, 119.3150706170000603 26.0700736100000654, 119.3170849910001152 26.0704565680000542, 119.3172141570000804 26.0705490010000744, 119.3172494210000423 26.0705875310000579, 119.3172630350001100 26.0702955380000390))"

g1, _ := wkt.UnmarshalString(a1)
g2, _ := wkt.UnmarshalString(a2)
f, _ := strategy.Intersects(g1, g2)
fmt.Println(f)

返回结果为false,实际情况是有相交
1660797569318

Add multiple single parts to make it a multi-part method

This algorithm takes a vector layer with single-part geometries and generates a new one in which all geometries are multipart. Input features which are already multipart features will remain unchanged.
This algorithm can be used to force geometries to multipart types in order to be compatible with data providers with strict single-part/multi-part compatibility checks.
I really need this feature, thanks a million.

The result of function Union is not expected

I want call function Union to merge two linestrings, the result is a collection of points and linestrings, whereas in PostGIS the result is a multilinestring. I think the result of PostGIS is better.
image

Use geoos

line01, _ := wkt.UnmarshalString(`LINESTRING (108.775634765625 35.074964853989556, 108.06976318359375 34.59251960889388, 108.41583251953125 34.091335914867344, 107.66876220703125 33.79056118537381)`)
line02, _ := wkt.UnmarshalString(`LINESTRING (108.270263671875 34.99625375979014, 108.10546875 33.578014746143985)`)
G := NormalStrategy()
got, err := G.Union(line01, line02)
// got is 'GEOMETRYCOLLECTION(POINT(108.23660087925735 34.70654892389195),POINT(108.2012282997209 34.40212951738887),POINT(108.15281049013673 33.98544175950031),LINESTRING(108.775634765625 35.074964853989556,108.23660087925735 34.70654892389195),LINESTRING(108.23660087925735 34.70654892389195,108.06976318359375 34.59251960889388,108.2012282997209 34.40212951738887),LINESTRING(108.2012282997209 34.40212951738887,108.41583251953125 34.091335914867344,108.15281049013673 33.98544175950031),LINESTRING(108.15281049013673 33.98544175950031,107.66876220703125 33.79056118537381),LINESTRING(108.270263671875 34.99625375979014,108.23660087925735 34.70654892389195),LINESTRING(108.23660087925735 34.70654892389195,108.2012282997209 34.40212951738887),LINESTRING(108.2012282997209 34.40212951738887,108.15281049013673 33.98544175950031),LINESTRING(108.15281049013673 33.98544175950031,108.10546875 33.578014746143985))'

Use PostGIS

Select ST_Union(
	ST_Geomfromtext('LINESTRING (108.775634765625 35.074964853989556, 108.06976318359375 34.59251960889388, 108.41583251953125 34.091335914867344, 107.66876220703125 33.79056118537381)'),
	ST_Geomfromtext('LINESTRING (108.270263671875 34.99625375979014, 108.10546875 33.578014746143985)')
);
# MULTILINESTRING ((108.775634765625 35.074964853989556, 108.23660087925734 34.70654892389193), (108.23660087925734 34.70654892389193, 108.06976318359375 34.59251960889388, 108.20122829972088 34.402129517388865), (108.20122829972088 34.402129517388865, 108.41583251953125 34.091335914867344, 108.15281049013674 33.98544175950031), (108.15281049013674 33.98544175950031, 107.66876220703125 33.79056118537381), (108.270263671875 34.99625375979014, 108.23660087925734 34.70654892389193), (108.23660087925734 34.70654892389193, 108.20122829972088 34.402129517388865), (108.20122829972088 34.402129517388865, 108.15281049013674 33.98544175950031), (108.15281049013674 33.98544175950031, 108.10546875 33.578014746143985))

DBScan PointList and Center not filled

I am currently looking into this library for its geospatial clustering capabilities.
I tried out the DBScan but noticed, that the clusters.Cluster properties PointList and Center are not filled.
It seems to me that the calls to cluster.Append(Point) and cluster.Recenter() are missing from the implementation of DBScan.
While I can do this manually after the clustering, I had expected this to be done inside the clustering function.

If this is unintentional, I suppose the changes would be easy enough to make so I could provide a MR - I look forward to your answer.

Is there a bug on BufferInMeter?

  1. When I used the method on polygon, the result is not what I want.
  2. Remove the following code maybe more suitable or accurate? (reference postgis st_buffer and turf.js)
centroid := geom.Centroid()
width = measure.MercatorDistance(width, centroid.Lat())

An issue of PolygonOverlay.Union()

When I used PolygonOverlay.Union() to find the union of two POLYGON, the result returned was as follows, which is different from the result I expected.

image-20220310114034258

The union I understand should be the result of the following.

image-20220310114121711

func TestPolygonOverlay_Union(t *testing.T) {
	type fields struct {
		PointOverlay  *PointOverlay
		subjectPlane  *Plane
		clippingPlane *Plane
	}
	tests := []struct {
		name    string
		fields  fields
		want    []matrix.Steric
		wantErr bool
	}{
		{"poly poly", fields{PointOverlay: &PointOverlay{matrix.PolygonMatrix{{{0, 0}, {10, 0}, {10, 10}, {0, 10}, {0, 0}}},
			matrix.PolygonMatrix{{{5, 5}, {15, 5}, {15, 15}, {5, 15}, {5, 5}}},
		}},
			[]matrix.Steric{matrix.PolygonMatrix{{{5, 10}, {0, 10}, {0, 0}, {10, 0}, {10, 5}, {15, 5}, {15, 15}, {5, 15}, {5, 10}}}}, false},
	}
	for _, tt := range tests {
		if !geoos.GeoosTestTag && tt.name != "poly poly03" {
			continue
		}
		t.Run(tt.name, func(t *testing.T) {
			p := &PolygonOverlay{
				PointOverlay:  tt.fields.PointOverlay,
				subjectPlane:  tt.fields.subjectPlane,
				clippingPlane: tt.fields.clippingPlane,
			}
			got, err := p.Union()
                         // result:
                         // POLYGON((0 0,15 0,15 15,0 15,0 0))
      
                         // want: 
                         // POLYGON ((10 0, 0 0, 0 10, 5 10, 5 15, 15 15, 15 5, 10 5, 10 0))     
			if (err != nil) != tt.wantErr {
				t.Errorf("PolygonOverlay.Union() error = %v, wantErr %v", err, tt.wantErr)
				return
			}
			// ...
		})
	}
}

The shadow method Transformer.transformCollection prevents space.Geometry.Simplify() to work correctly

Using DP geometry simplification I noted that the shadow method tranformCollection() in Tranformer obscure the call at a missing method in DPTransformer and the call at space.Geometry.Simplify() doesn't work in case of geometry collection.
I suppose the following method has to be added for DPTransformer.

func (d *DPTransformer) transformCollection(geom matrix.Collection, parent matrix.Steric) matrix.Steric {
	transGeoms := matrix.Collection{}
	for _, v := range geom {
		transformGeom, _ := d.Transform(v)
		if transformGeom == nil {
			continue
		}
		if d.pruneEmptyGeometry && transformGeom.IsEmpty() {
			continue
		}
		transGeoms = append(transGeoms, transformGeom)
	}
	return transGeoms
}

ReadBytes buffer is 1 byte, Ultra slow

In the GeoJson package, under the base encoder file your ReadBytes buffer is 1 byte.
For any decently sized file this makes it take FOREVER.

Any reason this isn't bumped up to like 4096?

// ReadBytes Returns geometry from reader.
func (e *BaseEncoder) ReadBytes(r io.Reader) ([]byte, error) {
	buf := []byte{}
	b := make([]byte, 1)
	for {
		if _, err := r.Read(b); err == io.EOF {
			//buf = append(buf, b[0:n]...)
			break
		} else if err != nil {
			return nil, err
		} else {
			buf = append(buf, b...)
		}
	}
	return buf, nil
}

Intersects bug

polygon, _ := geoencoding.Decode([]byte(`MULTIPOLYGON(((121.308225482526 31.3977223795235,121.320481 31.399024,121.322129 31.386769,121.304536 31.385516,121.300412 31.393475,121.308225482526 31.3977223795235)),((121.308225482526 31.3977223795235,121.308156 31.397715,121.308337 31.397783,121.308225482526 31.3977223795235)))`), geoencoding.WKT)  
line, _ := geoencoding.Decode([]byte(`linestring(121.318481 31.40068, 121.317523 31.393429, 121.324714 31.392735, 121.325045 31.390363)`), geoencoding.WKT)  

a := planar.NewMegrezAlgorithm()  
i, e := a.Intersects(polygon, line)  
fmt.Println(i, e)  

LGPL license is difficult to use with Go

I see that you have chosen to release your library using the LGPL license.

I am not a lawyer and nothing in this text is legal advice, but my understanding is that Go libraries using the LGPL license are quite difficult to use. I don't know your motives when choosing this license, but often the intention is to allow others to use the library in their own projects (open source or not), but to require modifications to the library itself to be released using the same LGPL license. This is however very difficult to satisfy with Go, as Go uses static linking, while the LGPL unfortunately has very specific language mentioning dynamically linking the library and distribution of programs using the library as object code to allow relinking with a modified version of the library. In practice this means that users can only use the library in GPL programs.

If this is the intention, then my opinion is that it would be clearer to use the GPL license for the library.

On the other hand, if your intention is to allow users to use the library also in projects that are not GPL, then as a user I would prefer another open source license like MPL that allows using in closed source or open source MIT licensed projects, but that still requires publishing changes to the library as open source like the LGPL does.

I understand that this is your project and I have no say in which license you use, but just wanted to raise this in case you were not aware of this issue with Go and the LGPL. Thank you so much for your generous contributions to open source!

发现一个图形计算的bug,对两个multiloygon进行union操作时,得到错误的计算结果

第一个multipolyon:[[[[116.458553 39.88791] [116.45857094384326 39.88790553563427] [116.45856 39.88788] [116.4585554 39.887848] [116.45856448239947 39.88781221907734] [116.4587112 39.8878347] [116.4591606 39.8878296] [116.45952 39.8878296] [116.45987912842851 39.887820731401185] [116.4598813171811 39.88786572522166] [116.46016837242065 39.88786341614056] [116.4601663 39.8877617] [116.4602998 39.8877604] [116.46066780447438 39.887752718692184] [116.4606703 39.8878119] [116.4606736 39.8878444] [116.46067457705385 39.88785934421506] [116.460966 39.887857] [116.4610304829428 39.88785653927355] [116.4610285 39.8877514] [116.46124888556602 39.88774876594252] [116.46143624152896 39.8877471103319] [116.46144 39.88792] [116.46144 39.88813] [116.46162616602014 39.88812731264462] [116.46162644189089 39.88813614050829] [116.461844 39.888133] [116.462701 39.888107] [116.46288437670745 39.88810507620295] [116.46289951156183 39.88810521663731] [116.46289532422891 39.88857001059088] [116.4629 39.88877] [116.46290002476694 39.88885143029087] [116.46290295416163 39.88902060283474] [116.4629017869734 39.889185567331936] [116.46290084263367 39.889185576001445] [116.46289971814569 39.889344502074465] [116.46273834940025 39.88934400268843] [116.462497 39.889345] [116.46248448325267 39.889345124362634] [116.46248426575583 39.88936692289501] [116.46248073326008 39.88936695799271] [116.461774 39.88936] [116.46176887366315 39.88925767831632] [116.46165 39.88926071363079] [116.46147137010163 39.88926000543263] [116.46147137010163 39.889328505081636] [116.46128 39.88933] [116.46128 39.88938087151887] [116.46106 39.88938000041751] [116.46106 39.889386707395175] [116.46104787153232 39.88938665937188] [116.46104741421834 39.88938050047763] [116.4609066 39.8893861] [116.46081 39.88939] [116.46075 39.88939] [116.46051 39.8894] [116.4604 39.8894] [116.46001 39.88941] [116.45977 39.88942] [116.45964 39.88943] [116.4593013 39.8894392] [116.45863305962509 39.889449950776175] [116.45863182188327 39.889413562334404] [116.45864 39.88925] [116.45864 39.88919] [116.45867 39.88908] [116.45870000018292 39.88904999987805] [116.45873 39.88903] [116.45879557236869 39.88896442771095] [116.458585 39.888791] [116.45861712636355 39.88853572565184] [116.45862172063282 39.88849707042791] [116.45859959426923 39.88849534476924] [116.45861503309332 39.88836544569761] [116.4586208207688 39.88828984423715] [116.45862073675784 39.88828973863373] [116.4586294031725 39.88817653337766] [116.458631 39.888143] [116.458617 39.888064] [116.458553 39.88791]]]]
第二个multipolygon:[[[[116.46277925748878 39.88599] [116.46327 39.88599] [116.46327121548828 39.886109220211566] [116.46431140000675 39.88610711457489] [116.46437815770724 39.88610553470714] [116.46437821516655 39.88610675825216] [116.46437798719191 39.886019937380794] [116.46449012423405 39.88601728357566] [116.465193 39.886019] [116.46520508527627 39.886019012615826] [116.465205 39.886002] [116.46584660810673 39.886000300375876] [116.46595733806026 39.88599648210394] [116.46595682983767 39.88595148862629] [116.466 39.88595] [116.46663 39.88595] [116.4671 39.88594] [116.46709942832697 39.88589866765154] [116.467261 39.885898] [116.46726128624843 39.88594] [116.4679 39.88594] [116.46805881008105 39.88595684350834] [116.468043 39.886048] [116.46815974241039 39.886054984588654] [116.46815777083641 39.88607577565319] [116.46815788779723 39.886075783508765] [116.46815384274812 39.88611558570732] [116.468129 39.886114] [116.46792 39.886295] [116.467879 39.88629483526067] [116.467879 39.886422] [116.467864 39.886578] [116.46784403501898 39.88657731712968] [116.467839 39.886627] [116.4678267404138 39.886723675594055] [116.46778 39.88672] [116.4677801555936 39.886717277112126] [116.46764 39.886712] [116.467014 39.886706] [116.46692 39.886765] [116.466925 39.887255] [116.467228 39.887255] [116.467557 39.887252] [116.46770983916338 39.88726160836621] [116.46769 39.88746] [116.46768690541188 39.88767971575692] [116.46771 39.88768] [116.467711 39.887696] [116.46770801472468 39.88823533974078] [116.46767156440872 39.88823507456137] [116.46761 39.88871] [116.46761 39.88878] [116.46761473983558 39.88888860676638] [116.46760846016662 39.88888874291529] [116.46749545690462 39.88887846989132] [116.46749783782663 39.88886234889874] [116.467406 39.888854] [116.46562163217507 39.888857145646234] [116.46513720883907 39.888850509710124] [116.46513646130968 39.88889586425838] [116.465099 39.891529] [116.46509902876262 39.89152985233281] [116.46509382233967 39.89164750296356] [116.46505847429681 39.89164644112512] [116.46505 39.89166] [116.46504218543848 39.89218357562194] [116.46439781209806 39.892186892859215] [116.46437700037785 39.8921867880231] [116.46437799934012 39.891626370191105] [116.46433003220054 39.89162612856142] [116.46432913903807 39.89154727507503] [116.46418 39.89154] [116.46402 39.89153] [116.46402131828314 39.891488080779375] [116.463751 39.891482] [116.46374671152233 39.891513895753334] [116.4635903 39.8915009] [116.46338 39.89145] [116.4632133 39.8913735] [116.4630362 39.8912531] [116.46301444387001 39.89121807797685] [116.46296532973061 39.891141337364424] [116.4629665 39.8911409] [116.4629477 39.8910689] [116.462941 39.8909845] [116.4629343 39.8908868] [116.4629263 39.8907324] [116.4629142 39.8903707] [116.4629082 39.8900314] [116.4629076 39.8899751] [116.4629047 39.8897277] [116.4629065 39.8896535] [116.4629060377541 39.889344521631685] [116.46289971817896 39.88934449737274] [116.46290084273836 39.889185559645384] [116.4629017869734 39.889185567331936] [116.46290295416163 39.88902060283474] [116.4629 39.88885] [116.4629 39.88877] [116.46289532422891 39.88857001059088] [116.462902 39.887829] [116.46290193254518 39.88782389379261] [116.4628762206468 39.887823976702784] [116.46287400232684 39.88782366764997] [116.46287476934253 39.8877141122413] [116.46287 39.88752] [116.46287 39.88711] [116.4628600101224 39.88647064783323] [116.46278 39.88647] [116.46278 39.8861] [116.46277925748878 39.88599]]]]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.