JTS-豪斯多夫距离计算DiscreteHausdorffDistance

org.locationtech.jts.algorithm.distance.DiscreteHausdorffDistance 使用说明

离散豪斯多夫距离,Hausdorff距离以Felix Hausdorff(1868-1942)命名的,是一个集合到另一个集合中最近点的最大距离.

hausdorff理论参考

hausdorff理论参考

DiscreteHausdorffDistance.distance(g1,g2)

说明

计算g1,与g2的豪斯多夫距离,densifyFrac默认0,densifyFrac:作用稀疏点,通过带入公式(numSubSegs = (int) Math.rint(1.0/fraction))求segment分组数量

操作示例

JTS-豪斯多夫距离计算DiscreteHausdorffDistance_第1张图片

@Test
public void distanceTest() throws ParseException {

    Geometry g1 = wktReader.read("POLYGON ((330 490, 337 479, 341 467, 346 454, 351 442, 355 431, 361 419, 368 408, 375 393, 385 378, 393 369, 402 361, 412 359, 422 358, 437 358, 454 358, 465 358, 476 360, 487 362, 499 365, 510 367, 520 369, 531 371, 542 374, 552 376, 569 383, 581 388, 591 393, 596 402, 601 415, 604 426, 607 439, 609 453, 610 466, 611 479, 611 489, 611 501, 610 511, 604 520, 597 529, 589 535, 580 540, 567 546, 557 550, 544 554, 532 559, 520 561, 510 563, 500 564, 488 565, 476 567, 466 567, 455 568, 443 568, 432 568, 422 568, 412 568, 402 568, 390 568, 380 569, 370 569, 370 570, 330 490))");
    Geometry g2 = wktReader.read("POLYGON ((590 310, 578 312, 567 310, 554 304, 539 298, 525 291, 512 283, 501 279, 493 272, 484 264, 476 257, 470 248, 465 239, 460 225, 458 214, 456 203, 456 191, 456 179, 456 168, 462 155, 469 147, 480 136, 489 131, 503 124, 519 118, 530 115, 541 111, 553 108, 565 106, 578 104, 592 102, 605 101, 620 101, 636 101, 649 101, 664 101, 676 103, 688 106, 700 109, 710 114, 720 118, 737 128, 750 138, 759 148, 767 158, 774 172, 780 185, 785 198, 787 209, 789 220, 789 230, 789 241, 789 255, 789 266, 785 277, 778 290, 766 301, 754 311, 736 320, 725 323, 713 328, 700 331, 689 334, 679 336, 668 339, 657 341, 647 342, 630 343, 614 344, 603 344, 591 344, 580 344, 571 339, 563 333, 555 327, 550 318, 546 308, 556 308, 568 312, 579 315, 590 318, 600 321, 640 300, 590 310))");

    System.out.println(DiscreteHausdorffDistance.distance(g1,g2));

    System.out.println(g2.distance(g1));

}

你可能感兴趣的:(JTS,GIS,gis,jts)