Find a point at a given distance along a line

10539
18
Jump to solution
12-28-2016 12:13 PM
GregRieck
Occasional Contributor III

Hello everyone,

Does anyone have any experience with or sample code or sample geoprocessing events etc. that will return a point X,Y along a line (polyline) given a specific distance? For example if the polyline is 1000 feet long I want to know where along that line 250 feet is from it's starting vertex. I want the results as a point string format {"x" : -118.15, "y" : 33.80, "spatialReference" : {"wkid" : 4326}} so I can mark that location with an image on the web site.

Thank You,

Greg

0 Kudos
1 Solution

Accepted Solutions
TomSellsted
MVP Regular Contributor

Greg,

I have a sample that may work the way you are suggesting.  Please take a look at:

Position Along 

It is completely client based, so no geoprocessing scripts required.

Regards,

Tom

View solution in original post

18 Replies
RebeccaStrauch__GISP
MVP Emeritus

I wonder if this would be a good starting point...

https://community.esri.com/docs/DOC-9065-traverse-widget-220 

find this, other custom widgets and other announcements from the community

/blogs/myAlaskaGIS/2016/03/09/web-appbuilder-developer-edition-customization-resource-list?sr=search...

GregRieck
Occasional Contributor III

Rebecca,

Thank you for your reply. 

No that's not quite what I'm looking for. Something more along the lines of this:

Polyline—Help | ArcGIS Desktop  search for positionAlongLine.

I'm looking for the point location along a line. If I provide the polyline feature and a distance it should return the point along the line at that distance. It should take into consideration any curve of the line. The point location will then be used to mark the position on the line where the point occurs.

I'm thinking I need to do this as a geoprocessing service for JS to be able to access it. I've do not have any experience in ArcPy or creating a service for JS to access. I was hoping someone might have utilize the positionAlongLine method in ArcPy and be willing to share their script. That would be a huge start for me. Meanwhile I'm reading and attempting to create this script on my own.

Greg

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

A GP service was going to be my next suggestion.  I have used positionAlongLine in arcpy scripts, but never as a GP service.  For example, taking a contour and creating a transect for 1/2 a given length, from the centroid (and shifting if needed), so probably more than what you are needing.  But I seem to always have to convert the line to a route.

TomSellsted
MVP Regular Contributor

Greg,

I have a sample that may work the way you are suggesting.  Please take a look at:

Position Along 

It is completely client based, so no geoprocessing scripts required.

Regards,

Tom

RebeccaStrauch__GISP
MVP Emeritus

I like it!  Do you have code you can share?  .....or is it already a widget you have out there?

It looks to work with graphics you draw.  Do you think it can be modified to work with a feature from a layer?  Maybe have to grab and copy first?  I could see when this might be useful for some of my projects. 

Edit:

Tom Sellsted  

I noticed that if I change the value in the box, the slider does not change.  Just fyi.   

Also, my numeric pad was acting strange, sometimes taking the numbers, sometimes using the directional functions. btw - using a Desktop Win7, using Firefox, num lock was on.  Since it is client side, my guess is it is a client side (user) error/problem.. Again, just an fyi.  

0 Kudos
TomSellsted
MVP Regular Contributor

Rebecca,

You can certainly do a "View Source" in your browser to look at the code.  It is not a widget.  It could be any polyline feature in your app.  The demo here allows you to key in a specific value or use the slider to calculate a percent of the total length of the polyline.

There are five functions that do the calculation for placing the point along the polyline.  About 90 lines of code.  It can be easily modified for your purposes.

Regards,

Tom

GregRieck
Occasional Contributor III

Thank You Tom.  

I think I can extract what I need from what you have provided to create a result that gives me a point X,Y that I can use to mark my location.

Greg

0 Kudos
TomSellsted
MVP Regular Contributor

Greg,

You are welcome!  I had used this method for placing arrows that represent bus locations based on their current schedule.  The original code was in ActionScript, but works well in JS too.

Regards,

Tom

0 Kudos
GregRieck
Occasional Contributor III

Tom,

Having a small issue. I'm positive its a spatial projection issue. My data is in 26912

NAD83 / UTM zone 12N: EPSG Projection -- Spatial Reference 

How can I get this working with my spatial reference? The big difference here is I am querying a polyline from my database and using that as the "var pl" variable. Instead of coming from a line drawn on the map like you do.

Greg

0 Kudos