Skip to content

Give out points of geometries #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Aug 16, 2020

Conversation

Sov-trotter
Copy link
Contributor

@Sov-trotter Sov-trotter commented Jul 26, 2020

PR for #69
So this overloads the convert_simplex() method to break down a linestring.

ls1=LineString([Point(1, 2), Point(4,5), Point(10, 8), Point(1, 2)])
decompose(Point{2, Int}, ls1)
6-element Array{Point{2,Int64},1}:
 [1, 2]
 [4, 5]
 [4, 5]
 [10, 8]
 [10, 8]
 [1, 2]

The repetition of Points is the only visible issue currently. Expected is:

ls1.points.parent.data
4-element Array{Point{2,Int64},1}:
 [1, 2]
 [4, 5]
 [10, 8]
 [1, 2]

@Sov-trotter
Copy link
Contributor Author

Sov-trotter commented Jul 26, 2020

Now the thing is convert_simplex receives only Line so it's pretty hard to avoid the repetitions in there. We can either introduce a new check_repeat() method in the collect_with_eltype() or maybe overload it for LineString/polygon/other higher geometries specifically?

using Makie
a = lines(decompose(Point{2, Int}, ls1))

b = lines(ls1.points.parent.data)

a==b
false

The only thing is that will it be fast enough when we have a very large linestring and that would also result in a quite large array?

@Sov-trotter Sov-trotter marked this pull request as draft July 26, 2020 11:33
@Sov-trotter Sov-trotter changed the title Geom points Give out points of geometries Jul 26, 2020
@SimonDanisch
Copy link
Member

How about overloading decompose?

@Sov-trotter
Copy link
Contributor Author

Sov-trotter commented Jul 26, 2020

Ah. That's doable. BTW can we use the points.parent.data to return our points? Or use the method in the latest commit and iterate over it to remove the duplicates?

Since currently,

using BenchmarkTools

pts = collect(Point{2, Float64}(x/2, (x+1)/3) for x in 1:10000)
ls = LineString(pts)

@btime decompose(Point{2, Float64}, ls)
  925.390 μs (30012 allocations: 2.98 MiB)

@btime ls.points.parent.data
  123.831 ns (6 allocations: 192 bytes)

Clean up stuff
@Sov-trotter Sov-trotter marked this pull request as ready for review July 27, 2020 14:55
Add decompose for polygon
@Sov-trotter
Copy link
Contributor Author

Sov-trotter commented Jul 31, 2020

So the new overload is for giving out points of a polygon.
A polygon has two parts, and exterior and interiors. In the latest commit, if there are no interiors, an array of points of exterior is given out, but it interiors are present, the data is given out as:

pol = Polygon(LineString(Point{2, Int}[(5, 1), (3, 3), (4, 8), (1, 2), (5, 1)]), [LineString(Point{2, Int}[(2, 2), (3, 8),(5, 6) , (3, 4), (2, 2)]), LineString(Point{2, Int}[(3, 2), (4, 5),(6, 1) , (1, 4), (3, 2)])])

decompose(Point{2, Int}, pol)
2-element Array{Array{Union{Array, Point},N} where N,1}:
 [[5, 1], [3, 3], [4, 8], [1, 2], [5, 1]]
 [Point{2,Int64}[[2, 2], [3, 8], [5, 6], [3, 4], [2, 2]], Point{2,Int64}[[2, 2], [3, 8], [5, 6], [3, 4], [2, 2]]]

Here the first element contains Array of exterior points and second contains arrays of interior linestrings' points.
Is this nested Array approach better? Or what might be a better way to have interiors spread out?

@Sov-trotter
Copy link
Contributor Author

@visr @SimonDanisch can you take a look?

@Sov-trotter
Copy link
Contributor Author

Sov-trotter commented Aug 14, 2020

@SimonDanisch Really sorry for pestering you this way, but I'd be nice if you can take a look at this PR and #79 too?

@SimonDanisch SimonDanisch merged commit 8e72103 into JuliaGeometry:master Aug 16, 2020
@knuesel knuesel mentioned this pull request Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants