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

along should support negative offset #2148

Open
evolkmann opened this issue Jul 16, 2021 · 3 comments · May be fixed by #2573
Open

along should support negative offset #2148

evolkmann opened this issue Jul 16, 2021 · 3 comments · May be fixed by #2573

Comments

@evolkmann
Copy link

@turfjs/along should allow a negative offset.

Example

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "properties": {},
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [
            9.309196472167969,
            52.23736673260212
          ],
          [
            9.33314323425293,
            52.24073057268207
          ]
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "marker-color": "#7e7e7e",
        "marker-size": "medium",
        "marker-symbol": "",
        "info": "1 mile offset"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          9.332232811468383,
          52.24060278205829
        ]
      }
    },
    {
      "type": "Feature",
      "properties": {
        "marker-color": "#7e7e7e",
        "marker-size": "medium",
        "marker-symbol": "",
        "info": "I would expect a point around here for `-1 mile`"
      },
      "geometry": {
        "type": "Point",
        "coordinates": [
          9.286966323852539,
          52.23434431509133
        ]
      }
    }
  ]
}

When you use along with 1 mile offset, the point is correctly returned. If I call the function with -1 mile, an error is thrown.

I briefly tried to implement this inside the along source without a quick success, so I raise this issue as a reminder and maybe someone else also has a need for this requirement.

My current workaround is to flip the original line (swap coordinates) and apply a positive offset.

Version: 6.5.0

@twelch
Copy link
Collaborator

twelch commented Jul 17, 2021

Sounds like a nice addition.

@JamesLMilner
Copy link
Collaborator

Thanks for raising this as an idea, appreciate the input. Unfortunately I'm not sure this makes sense for one primary reason which is that this seems to work on the assumption that a LineString Feature is straight. For example -1 mile along a non straight line would lead to the question of -1 mile in which direction? As such I am not convinced this should be implemented. I'll leave this open for a bit if someone can describe how this might work.

@twelch
Copy link
Collaborator

twelch commented Jul 18, 2021

I interpreted the use case as - I want the point 1 mile along the line, starting from the end of the Linestring, instead of the beginning.

Instead of flipping the order of the Linestring coordinates and using a positive distance to make it work as @evolkmann mentioned for a workaround, the along method could accept a negative distance which would indicate to start from the end Position of the Linestring and work backwards 1 mile.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants