GeometryNoder.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import NodingValidator from '../NodingValidator'
  2. import NodedSegmentString from '../NodedSegmentString'
  3. import ArrayList from '../../../../../java/util/ArrayList'
  4. import LinearComponentExtracter from '../../geom/util/LinearComponentExtracter'
  5. import MCIndexSnapRounder from './MCIndexSnapRounder'
  6. export default class GeometryNoder {
  7. constructor() {
  8. GeometryNoder.constructor_.apply(this, arguments)
  9. }
  10. static constructor_() {
  11. this._geomFact = null
  12. this._pm = null
  13. this._isValidityChecked = false
  14. const pm = arguments[0]
  15. this._pm = pm
  16. }
  17. extractLines(geoms) {
  18. const lines = new ArrayList()
  19. const lce = new LinearComponentExtracter(lines)
  20. for (let it = geoms.iterator(); it.hasNext(); ) {
  21. const geom = it.next()
  22. geom.apply(lce)
  23. }
  24. return lines
  25. }
  26. setValidate(isValidityChecked) {
  27. this._isValidityChecked = isValidityChecked
  28. }
  29. node(geoms) {
  30. const geom0 = geoms.iterator().next()
  31. this._geomFact = geom0.getFactory()
  32. const segStrings = this.toSegmentStrings(this.extractLines(geoms))
  33. const sr = new MCIndexSnapRounder(this._pm)
  34. sr.computeNodes(segStrings)
  35. const nodedLines = sr.getNodedSubstrings()
  36. if (this._isValidityChecked) {
  37. const nv = new NodingValidator(nodedLines)
  38. nv.checkValid()
  39. }
  40. return this.toLineStrings(nodedLines)
  41. }
  42. toSegmentStrings(lines) {
  43. const segStrings = new ArrayList()
  44. for (let it = lines.iterator(); it.hasNext(); ) {
  45. const line = it.next()
  46. segStrings.add(new NodedSegmentString(line.getCoordinates(), null))
  47. }
  48. return segStrings
  49. }
  50. toLineStrings(segStrings) {
  51. const lines = new ArrayList()
  52. for (let it = segStrings.iterator(); it.hasNext(); ) {
  53. const ss = it.next()
  54. if (ss.size() < 2) continue
  55. lines.add(this._geomFact.createLineString(ss.getCoordinates()))
  56. }
  57. return lines
  58. }
  59. }