LocationIndexedLine.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import LineString from '../geom/LineString'
  2. import IllegalArgumentException from '../../../../java/lang/IllegalArgumentException'
  3. import LinearLocation from './LinearLocation'
  4. import LocationIndexOfPoint from './LocationIndexOfPoint'
  5. import LocationIndexOfLine from './LocationIndexOfLine'
  6. import ExtractLineByLocation from './ExtractLineByLocation'
  7. import MultiLineString from '../geom/MultiLineString'
  8. export default class LocationIndexedLine {
  9. constructor() {
  10. LocationIndexedLine.constructor_.apply(this, arguments)
  11. }
  12. static constructor_() {
  13. this._linearGeom = null
  14. const linearGeom = arguments[0]
  15. this._linearGeom = linearGeom
  16. this.checkGeometryType()
  17. }
  18. clampIndex(index) {
  19. const loc = index.copy()
  20. loc.clamp(this._linearGeom)
  21. return loc
  22. }
  23. project(pt) {
  24. return LocationIndexOfPoint.indexOf(this._linearGeom, pt)
  25. }
  26. checkGeometryType() {
  27. if (!(this._linearGeom instanceof LineString || this._linearGeom instanceof MultiLineString)) throw new IllegalArgumentException('Input geometry must be linear')
  28. }
  29. extractPoint() {
  30. if (arguments.length === 1) {
  31. const index = arguments[0]
  32. return index.getCoordinate(this._linearGeom)
  33. } else if (arguments.length === 2) {
  34. const index = arguments[0], offsetDistance = arguments[1]
  35. const indexLow = index.toLowest(this._linearGeom)
  36. return indexLow.getSegment(this._linearGeom).pointAlongOffset(indexLow.getSegmentFraction(), offsetDistance)
  37. }
  38. }
  39. isValidIndex(index) {
  40. return index.isValid(this._linearGeom)
  41. }
  42. getEndIndex() {
  43. return LinearLocation.getEndLocation(this._linearGeom)
  44. }
  45. getStartIndex() {
  46. return new LinearLocation()
  47. }
  48. indexOfAfter(pt, minIndex) {
  49. return LocationIndexOfPoint.indexOfAfter(this._linearGeom, pt, minIndex)
  50. }
  51. extractLine(startIndex, endIndex) {
  52. return ExtractLineByLocation.extract(this._linearGeom, startIndex, endIndex)
  53. }
  54. indexOf(pt) {
  55. return LocationIndexOfPoint.indexOf(this._linearGeom, pt)
  56. }
  57. indicesOf(subLine) {
  58. return LocationIndexOfLine.indicesOf(this._linearGeom, subLine)
  59. }
  60. }