I'm currently trying convert a Polyline into evenly spaced MapPoints. For instance if I have Polyline of two points such as:
var builder = new PolylineBuilder(SpatialReference.Wgs84);
var part = new List<MapPoint>();
part.Add(new MapPoint(x1, y1);
part.Add(new MapPoint(x2,y2);
builder.AddPart(part);
var polyLine = builder.ToGeometry();
I would like to specify a certain spacing e.g. 10 meters, and then generate n different MapPoints along the Polyline. For example, if the total distance (L2) between the vertices(x1,y1), (x2,y2) on the Polyline is 95 meters then I would generate 9 MapPoints that are 10 meters spaced apart (the remaining 5 meters would be disregarded).
To specify a little more, the distance between the two Polyline vertices will not be significantly large (they definitely will be in the same UTM zone) so it is safe to assume the line will not be curved, and is straight.
Any suggestions?
Solved! Go to Solution.
Hi Dan. You should use the DensifyGeodetic method in GeometryEngine. This method does what you describe.
Example code would look like this:
Polyline densifiedLine = (Polyline)GeometryEngine.DensifyGeodetic(polyLine, 10, LinearUnits.Meters, GeodeticCurveType.Geodesic);
You can get all of the map points from the resulting Polyline.
var points = densifiedLine.Parts.SelectMany(part => part.Points);
We have a sample for densified and generalized geometry.
Zack
So I realized I could convert from lat/lon points <---> UTM coordinates using CoordinateFormatter.ToUTM() <---> CoordinateFormatter.FromUTM(). If I convert into UTM coordinates then I should be able to find the angle between the two vertices using arctan2() and then recursively add points using ynew = r * sin(angle) + yprev, xnew = r * cos(angle) + xprev. Then convert back to lat/lon points and generate the mapPoints that way.
I don't know if this is the most effecient way, but it's the first thing that came to my mind. I would still appreciate suggestions/responses.
Hi Dan. You should use the DensifyGeodetic method in GeometryEngine. This method does what you describe.
Example code would look like this:
Polyline densifiedLine = (Polyline)GeometryEngine.DensifyGeodetic(polyLine, 10, LinearUnits.Meters, GeodeticCurveType.Geodesic);
You can get all of the map points from the resulting Polyline.
var points = densifiedLine.Parts.SelectMany(part => part.Points);
We have a sample for densified and generalized geometry.
Zack
Looks nice simple and exactly what I was looking for. Thanks Zack!