|
3 | 3 | import junit.framework.TestCase; |
4 | 4 |
|
5 | 5 | import com.esri.core.geometry.ogc.OGCGeometry; |
| 6 | +import com.esri.core.geometry.ogc.OGCGeometryCollection; |
6 | 7 | import com.esri.core.geometry.ogc.OGCLineString; |
7 | 8 | import com.esri.core.geometry.ogc.OGCMultiPoint; |
| 9 | +import com.esri.core.geometry.ogc.OGCMultiPolygon; |
8 | 10 | import com.esri.core.geometry.ogc.OGCPoint; |
9 | 11 | import com.esri.core.geometry.ogc.OGCPolygon; |
10 | 12 | import com.esri.core.geometry.ogc.OGCConcreteGeometryCollection; |
@@ -362,6 +364,168 @@ public void test_polygon_is_simple_for_OGC() { |
362 | 364 | } |
363 | 365 | } |
364 | 366 |
|
| 367 | + /* |
| 368 | + This will fail |
| 369 | + public void test_polygon_simplify_for_OGC() { |
| 370 | + try { |
| 371 | + { |
| 372 | + String s = "{\"rings\":[[[0, 0], [0, 10], [10, 10], [10, 0], [0, 0]]]}"; |
| 373 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 374 | + boolean res = g.isSimple(); |
| 375 | + assertTrue(res); |
| 376 | + assertTrue(g.isSimpleRelaxed()); |
| 377 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 378 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 379 | + assertTrue(og.geometryType().equals("Polygon")); |
| 380 | + assertTrue(((OGCPolygon)og).numInteriorRing() == 0); |
| 381 | + } |
| 382 | +
|
| 383 | + {// exterior ring is self-tangent |
| 384 | + String s = "{\"rings\":[[[0, 0], [0, 10], [5, 5], [10, 10], [10, 0], [5, 5], [0, 0]]]}"; |
| 385 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 386 | + boolean res = g.isSimple(); |
| 387 | + assertTrue(!res); |
| 388 | + assertTrue(g.isSimpleRelaxed()); |
| 389 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 390 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 391 | + res = og.isSimple(); |
| 392 | + assertTrue(res); |
| 393 | + assertTrue(og.geometryType().equals("MultiPolygon")); |
| 394 | + assertTrue(((OGCGeometryCollection)og).numGeometries() == 2); |
| 395 | + } |
| 396 | +
|
| 397 | + {// ring orientation (hole is cw) |
| 398 | + String s = "{\"rings\":[[[-100, -100], [-100, 100], [100, 100], [100, -100], [-100, -100]], [[0, 0], [5, 5], [10, 0], [0, 0]]]}"; |
| 399 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 400 | + boolean res = g.isSimple(); |
| 401 | + assertTrue(!res); |
| 402 | + assertTrue(!g.isSimpleRelaxed()); |
| 403 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 404 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 405 | + res = og.isSimple(); |
| 406 | + assertTrue(res); |
| 407 | + assertTrue(og.geometryType().equals("Polygon")); |
| 408 | + assertTrue(((OGCPolygon)og).numInteriorRing() == 1); |
| 409 | + } |
| 410 | +
|
| 411 | + {// ring order |
| 412 | + String s = "{\"rings\":[[[0, 0], [10, 0], [5, 5], [0, 0]], [[-100, -100], [-100, 100], [100, 100], [100, -100], [-100, -100]]]}"; |
| 413 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 414 | + boolean res = g.isSimple(); |
| 415 | + assertTrue(!res); |
| 416 | + assertTrue(g.isSimpleRelaxed()); |
| 417 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 418 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 419 | + res = og.isSimple(); |
| 420 | + assertTrue(res); |
| 421 | + assertTrue(og.geometryType().equals("Polygon")); |
| 422 | + } |
| 423 | +
|
| 424 | + { |
| 425 | + // hole is self tangent |
| 426 | + String s = "{\"rings\":[[[-100, -100], [-100, 100], [100, 100], [100, -100], [-100, -100]], [[0, 0], [5, 5], [10, 0], [10, 10], [5, 5], [0, 10], [0, 0]]]}"; |
| 427 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 428 | + boolean res = g.isSimple(); |
| 429 | + assertTrue(!res); |
| 430 | + assertTrue(g.isSimpleRelaxed()); |
| 431 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 432 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 433 | + res = og.isSimple(); |
| 434 | + assertTrue(res); |
| 435 | + assertTrue(og.geometryType().equals("Polygon")); |
| 436 | + assertTrue(((OGCPolygon)og).numInteriorRing() == 2); |
| 437 | + } |
| 438 | + { |
| 439 | + // two holes touch |
| 440 | + String s = "{\"rings\":[[[-100, -100], [-100, 100], [100, 100], [100, -100], [-100, -100]], [[0, 0], [10, 0], [5, 5], [0, 0]], [[10, 10], [0, 10], [5, 5], [10, 10]]]}"; |
| 441 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 442 | + boolean res = g.isSimple(); |
| 443 | + assertTrue(res); |
| 444 | + assertTrue(g.isSimpleRelaxed()); |
| 445 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 446 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 447 | + assertTrue(og.geometryType().equals("Polygon")); |
| 448 | + assertTrue(((OGCPolygon)og).numInteriorRing() == 2); |
| 449 | + } |
| 450 | + { |
| 451 | + // two holes touch, bad orientation |
| 452 | + String s = "{\"rings\":[[[-100, -100], [-100, 100], [100, 100], [100, -100], [-100, -100]], [[0, 0], [5, 5], [10, 0], [0, 0]], [[10, 10], [0, 10], [5, 5], [10, 10]]]}"; |
| 453 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 454 | + boolean res = g.isSimple(); |
| 455 | + assertTrue(!res); |
| 456 | + assertTrue(!g.isSimpleRelaxed()); |
| 457 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 458 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 459 | + assertTrue(og.geometryType().equals("Polygon")); |
| 460 | + assertTrue(((OGCPolygon)og).numInteriorRing() == 2); |
| 461 | + } |
| 462 | +
|
| 463 | + { |
| 464 | + // hole touches exterior in two spots |
| 465 | + //OperatorSimplifyOGC produces a multipolygon with two polygons without holes. |
| 466 | + String s = "{\"rings\":[[[-100, -100], [-100, 100], [0, 100], [100, 100], [100, -100], [0, -100], [-100, -100]], [[0, -100], [10, 0], [0, 100], [-10, 0], [0, -100]]]}"; |
| 467 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 468 | + boolean res = g.isSimple(); |
| 469 | + assertTrue(!res); |
| 470 | + assertTrue(g.isSimpleRelaxed()); |
| 471 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 472 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 473 | + assertTrue(og.geometryType().equals("MultiPolygon")); |
| 474 | + assertTrue(((OGCMultiPolygon)og).numGeometries() == 2); |
| 475 | + assertTrue(((OGCPolygon)((OGCMultiPolygon)og).geometryN(0)).numInteriorRing() == 0); |
| 476 | + assertTrue(((OGCPolygon)((OGCMultiPolygon)og).geometryN(1)).numInteriorRing() == 0); |
| 477 | + } |
| 478 | +
|
| 479 | + { |
| 480 | + // hole touches exterior in one spot |
| 481 | + //OperatorSimplifyOGC produces a polygons with a hole. |
| 482 | + String s = "{\"rings\":[[[-100, -100], [-100, 100], [0, 100], [100, 100], [100, -100], [0, -100], [-100, -100]], [[0, -100], [10, 0], [0, 90], [-10, 0], [0, -100]]]}"; |
| 483 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 484 | + boolean res = g.isSimple(); |
| 485 | + assertTrue(res); |
| 486 | + assertTrue(g.isSimpleRelaxed()); |
| 487 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 488 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 489 | + assertTrue(og.geometryType().equals("Polygon")); |
| 490 | + assertTrue(((OGCPolygon)og).numInteriorRing() == 1); |
| 491 | + } |
| 492 | +
|
| 493 | + { |
| 494 | + // exterior has inversion (non simple for OGC) |
| 495 | + //OperatorSimplifyOGC produces a polygons with a hole. |
| 496 | + String s = "{\"rings\":[[[-100, -100], [-100, 100], [0, 100], [100, 100], [100, -100], [0, -100], [10, 0], [0, 90], [-10, 0], [0, -100], [-100, -100]]]}"; |
| 497 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 498 | + boolean res = g.isSimple(); |
| 499 | + assertTrue(!res); |
| 500 | + assertTrue(g.isSimpleRelaxed()); |
| 501 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 502 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 503 | + assertTrue(og.geometryType().equals("Polygon")); |
| 504 | + assertTrue(((OGCPolygon)og).numInteriorRing() == 1); |
| 505 | + } |
| 506 | +
|
| 507 | + { |
| 508 | + // two holes touch in one spot, and they also touch exterior in |
| 509 | + // two spots, producing disconnected interior |
| 510 | + //OperatorSimplifyOGC produces two polygons with no holes. |
| 511 | + String s = "{\"rings\":[[[-100, -100], [-100, 100], [0, 100], [100, 100], [100, -100], [0, -100], [-100, -100]], [[0, -100], [10, -50], [0, 0], [-10, -50], [0, -100]], [[0, 0], [10, 50], [0, 100], [-10, 50], [0, 0]]]}"; |
| 512 | + OGCGeometry g = OGCGeometry.fromJson(s); |
| 513 | + boolean res = g.isSimple(); |
| 514 | + assertTrue(!res); |
| 515 | + assertTrue(g.isSimpleRelaxed()); |
| 516 | + Geometry resg = OperatorSimplifyOGC.local().execute(g.getEsriGeometry(), null, true, null); |
| 517 | + OGCGeometry og = OGCGeometry.createFromEsriGeometry(resg, null); |
| 518 | + assertTrue(og.geometryType().equals("MultiPolygon")); |
| 519 | + assertTrue(((OGCMultiPolygon)og).numGeometries() == 2); |
| 520 | + assertTrue(((OGCPolygon)((OGCMultiPolygon)og).geometryN(0)).numInteriorRing() == 0); |
| 521 | + assertTrue(((OGCPolygon)((OGCMultiPolygon)og).geometryN(1)).numInteriorRing() == 0); |
| 522 | + } |
| 523 | + } catch (Exception ex) { |
| 524 | + assertTrue(false); |
| 525 | + } |
| 526 | + } |
| 527 | + */ |
| 528 | + |
365 | 529 | public void test_polyline_is_simple_for_OGC() { |
366 | 530 | try { |
367 | 531 | { |
|
0 commit comments