Skip to content
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

ConcaveHull for Points #823

Merged
merged 21 commits into from
Jan 4, 2022
Merged

ConcaveHull for Points #823

merged 21 commits into from
Jan 4, 2022

Conversation

dr-jts
Copy link
Contributor

@dr-jts dr-jts commented Dec 20, 2021

Adds a ConcaveHull class to compute concave hulls of point sets.
The shape of the computed hull can be specified by one of the following criteria:

  • Maximum Edge Length in the concave hull
  • Maximum Edge Length Factor - a scale-free value which determines the Maximum Edge Length as a percentage of the length difference between longest and shortest edges in the triangulation. This is the recommended criteria.

Concave hulls are single connected polygons . Optionally they may be allowed to contain holes.

Examples

Concave Hull

  • Length = 40 / Length factor = 0.2
MULTIPOINT ((70 80), (80 90), (90 70), (50 80), (30 70), (20 40), (30 20), (50 10), (90 20), (40 50), (40 30), (41 67))

image

Reconstruction of a "C" glyph from random points

  • Max Length = 20; Length factor = 0.3
MULTIPOINT ((7 23), (6 30), (5 35), (7 33), (7 37), (8 25), (21 5), (13 11), (15 10), (21 8), (25 6), (24 9), (19 13), (24 13), (25 11), (27 8), (27 2), (30 0), (35 -1), (36 1), (32 1), (29 4), (20 15), (10 22), (10 16), (10 26), (8 42), (9 39), (9 45), (10 31), (9 51), (11 55), (11 19), (14 22), (15 18), (15 15), (17 19), (16 23), (11 24), (11 28), (12 30), (12 35), (11 43), (11 40), (11 60), (13 50), (14 54), (14 25), (13 57), (16 38), (16 48), (16 29), (17 51), (18 49), (17 54), (20 55), (17 58), (16 63), (17 61), (21 61), (19 66), (22 65), (22 59), (26 64), (29 66), (31 67), (27 67), (37 5), (43 1), (39 4), (41 2), (48 4), (49 1), (54 0), (51 3), (52 6), (54 7), (55 3), (57 2), (59 5), (62 6), (56 8), (58 9), (62 10), (54 65), (38 67), (41 67), (45 66), (61 65), (59 67), (35 68), (21 68), (24 69), (28 71), (30 73), (33 72), (37 70), (47 68), (40 70), (53 69), (63 68), (45 71), (42 71), (38 73), (48 71), (49 73), (41 74), (53 72), (58 72))

image

Reconstruction of an "A" glyph from random points

  • Holes allowed; Length = 80 / Length Factor = 0.19
MULTIPOINT ((296 698), (301 243), (149 225), (294 206), (225 558), (95 75), (446 388), (97 58), (440 308), (167 267), (458 409), (542 307), (200 410), (569 37), (427 582), (553 163), (454 389), (454 216), (472 250), (313 612), (246 604), (650 37), (451 267), (568 121), (345 721), (94 148), (395 532), (450 354), (268 557), (502 287), (89 117), (95 147), (226 495), (121 79), (106 31), (501 226), (150 235), (239 245), (251 242), (249 507), (198 280), (251 206), (580 225), (392 581), (99 199), (574 49), (406 492), (412 454), (511 361), (342 271), (376 492), (451 246), (552 67), (459 235), (35 13), (250 273), (40 74), (402 458), (264 624), (270 526), (424 472), (571 245), (331 581), (408 628), (540 215), (588 134), (579 137), (514 322), (359 626), (314 239), (403 453), (235 431), (121 94), (452 452), (201 451), (144 128), (536 163), (352 547), (575 107), (420 559), (476 368), (591 68), (54 37), (162 180), (245 552), (199 454), (355 276), (516 329), (431 454), (490 451), (423 567), (137 141), (537 276), (334 688), (260 559), (61 94), (79 60), (458 472), (183 373), (404 580), (559 111), (435 327), (336 645), (476 229), (108 271), (276 560), (270 618), (355 591), (544 84), (202 381), (598 33), (273 518), (429 432), (494 312), (145 140), (387 532), (481 483), (529 195), (471 262), (148 173), (340 634), (415 235), (378 629), (224 521), (268 214), (210 433), (447 373), (235 263), (396 506), (258 545), (267 532), (244 420), (540 82), (503 182), (463 295), (544 176), (130 224), (163 398), (550 252), (356 565), (150 193), (79 81), (609 82), (461 207), (498 344), (198 276), (50 26), (129 123), (24 15), (548 198), (60 96), (392 223), (112 146), (435 497), (531 311), (395 426), (276 605), (621 73), (403 512), (69 66), (472 322), (427 216), (117 235), (304 712), (403 217), (557 83), (205 325), (269 487), (166 353), (411 631), (466 447), (434 495), (617 81), (434 591), (58 102), (192 430), (201 234), (342 650), (166 401), (524 230), (2 3), (444 334), (485 418), (274 548), (544 84), (452 236), (233 513), (258 219), (474 457), (422 618), (488 291), (204 410), (301 539), (525 231), (627 12), (604 102), (283 700), (92 55), (452 519), (125 209), (165 245), (492 276), (250 241), (407 566), (518 301), (202 415), (547 135), (404 450), (55 40), (440 543), (330 241), (616 32), (529 148), (261 463), (153 386), (459 292), (525 312), (503 180), (338 671), (590 141), (237 248), (199 366), (500 211), (457 266), (239 236), (195 224), (288 648), (368 225), (593 97), (459 204), (566 82), (339 601), (314 237), (214 216), (86 142), (281 602), (245 404), (395 515), (617 121), (212 524), (662 3), (331 662), (71 50), (625 47), (36 30), (156 188), (580 129), (434 471), (527 217), (393 634), (552 264), (400 543), (219 459), (306 687), (209 356), (163 325), (570 193), (186 268), (426 262), (447 294), (198 461), (273 655), (291 596), (292 652), (347 233), (228 387), (464 352), (297 216), (284 629), (250 507), (259 504), (440 317), (180 334), (399 461), (199 330), (544 83), (342 217), (304 212), (556 216), (423 456), (269 273), (232 585), (203 276), (390 688), (206 242), (508 258), (230 402), (402 439), (414 419), (46 99), (489 398), (192 458), (337 695), (378 682), (197 256), (434 242), (491 301), (458 483), (158 159), (493 200), (140 330), (230 359), (560 0), (610 150), (600 180), (388 722), (287 722), (70 170), (60 140), (90 220), (95 0), (360 200), (390 200), (518 390), (533 350), (403 400), (315 560), (343 555), (299 519), (280 470), (510 130), (520 110), (20 50), (40 0), (640 70), (540 50), (500 160), (409 275), (210 300), (435 274), (359 515), (220 200), (460 540))

image

The famous Flickr example:

image

The almost-famous S example

  • Length = 20 / Length Factor = 0.12
MULTIPOINT ((0 81), (65 86), (70 71), (80 59), (92 49), (107 44), (122 41), (137 40), (152 41), (167 42), (182 47), (195 55), (203 68), (201 83), (188 92), (173 97), (158 100), (143 103), (128 106), (113 109), (98 112), (83 115), (68 120), (53 125), (40 133), (28 143), (18 155), (13 170), (12 185), (16 200), (26 213), (38 223), (51 231), (66 236), (81 240), (96 243), (111 245), (126 245), (141 245), (156 245), (171 244), (186 241), (201 238), (216 233), (229 225), (242 216), (252 204), (259 190), (262 175), (194 171), (189 186), (178 197), (164 203), (149 205), (134 206), (119 205), (104 203), (89 198), (77 188), (80 173), (93 165), (108 160), (123 157), (138 154), (153 151), (168 149), (183 146), (198 142), (213 138), (227 132), (241 126), (253 116), (263 104), (269 90), (271 75), (270 60), (264 46), (254 34), (243 23), (229 16), (215 10), (200 6), (185 3), (170 1), (155 0), (139 0), (123 0), (108 1), (93 3), (78 5), (63 10), (49 16), (35 23), (23 33), (13 45), (6 59), (16 82), (32 83), (48 84), (245 174), (228 173), (211 172), (131 128), (63 148), (222 207), (127 230), (154 131), (240 82), (72 220), (210 32), (90 22), (206 208), (57 202), (195 117), (55 166), (246 55), (201 101), (224 73), (211 192), (42 176), (152 228), (172 113), (24 61), (76 33), (92 216), (46 69), (118 138), (169 23), (213 118), (221 56), (44 192), (118 22), (224 40), (56 57), (192 32), (179 220), (34 44), (145 18), (239 194), (40 155), (92 136), (231 106), (40 207), (108 228), (256 81), (28 185), (54 33), (74 205), (172 132), (221 93), (249 96), (69 47), (78 146), (155 115), (202 223))

image

Concaveman test fixture

  • Length factor: 0.2

image

Signed-off-by: Martin Davis mtnclimb@gmail.com

Signed-off-by: Martin Davis <mtnclimb@gmail.com>
@dr-jts dr-jts self-assigned this Dec 20, 2021
@dr-jts dr-jts mentioned this pull request Dec 20, 2021
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
@dr-jts dr-jts changed the title WIP: ConcaveHull of points with Length and Area criteria WIP: ConcaveHull for points with Length and Area criteria Dec 20, 2021
@dr-jts dr-jts marked this pull request as draft December 20, 2021 21:57
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Handle degenerate cases

Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
*/
public Geometry getHull() {
if (inputGeometry.isEmpty()) {
return geomFactory.createPolygon();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the input geometry is a POLYGON Z, the output should respect the dimensionality. (Yeah.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I realize this is something that needs work. Will do that soon.

Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
add function for length factor with holes

Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
Signed-off-by: Martin Davis <mtnclimb@gmail.com>
@dr-jts dr-jts changed the title WIP: ConcaveHull for points with Length and Area criteria WIP: ConcaveHull for Points with Length and Area criteria Jan 4, 2022
@dr-jts dr-jts changed the title WIP: ConcaveHull for Points with Length and Area criteria WIP: ConcaveHull for Points Jan 4, 2022
@dr-jts dr-jts changed the title WIP: ConcaveHull for Points ConcaveHull for Points Jan 4, 2022
@dr-jts dr-jts marked this pull request as ready for review January 4, 2022 17:48
@dr-jts dr-jts merged commit d33f083 into locationtech:master Jan 4, 2022
@dr-jts dr-jts deleted the add-concavehull branch January 4, 2022 17:50
pramsey added a commit to libgeos/geos that referenced this pull request Jan 21, 2022
Port locationtech/jts#823, closes GH-549.
Adds in CAPI function, 
```
extern GEOSGeometry GEOS_DLL *GEOSConcaveHull(
    const GEOSGeometry* g,
    double ratio,
    unsigned int allowHoles);
```
At ratio 1.0, the concave hull == convex hull. Lower numbers promote more concavity.
@dr-jts
Copy link
Contributor Author

dr-jts commented Jan 26, 2022

The Flickr example (texas) link is broken.

Just worked for me... ?

@jodygarnett jodygarnett added this to the 1.19.0 milestone Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants