2

I am looking for a method in the ArcGIS Pro SDK 2.2 that will return the measure distance along a given polyline geometry.

Here is the python method

 measure = polylineGeometry.measureOnLine(pointGeometry)
1

The QueryPointAndDistance3D works great here is the Meth

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;

namespace MTools
{
    internal class StationFeatures : Button
    {
        protected override void OnClick()
        {
            StationFeature();
        }
        public async void StationFeature()
        {
            await QueuedTask.Run(() =>
            {
                MapView mapView = MapView.Active;
                var listFeatureLayers = mapView.Map.Layers.OfType<FeatureLayer>()
                    .ToList()
                    .Where(x => x.ShapeType == esriGeometryType.esriGeometryPoint);
                var centerline = mapView.Map.Layers.OfType<FeatureLayer>()
                    .Where(x => x.Name == LayerModel.LayerName.ToString())
                    .First();
                FeatureClass fcLine = centerline.GetFeatureClass();
                QueryFilter queryFilter = new QueryFilter()
                {
                    WhereClause = "OBJECTID IS NOT NULL"
                };
                using (RowCursor linecursor = fcLine.Search(queryFilter, true))
                {
                    while (linecursor.MoveNext())
                    {
                        using (Feature lineFeature = (Feature)linecursor.Current)
                        {
                            Polyline centerpolyline = (Polyline)lineFeature.GetShape();
                            foreach(var pointFeatureLayer in listFeatureLayers.ToList())
                            {
                                FeatureClass pointFc = pointFeatureLayer.GetFeatureClass();
                                FeatureClassDefinition pointFcDef = pointFc.GetDefinition();
                                IEnumerable<Field> fields = pointFcDef.GetFields().Where(x=>x.Name=="MEAS_STATION");
                                if (fields.Count() > 0)
                                {
                                    using(RowCursor featurecursor = pointFc.Search(queryFilter, true))
                                    {
                                        while (featurecursor.MoveNext())
                                        {
                                            using (Feature pointFeature = (Feature)featurecursor.Current)
                                            {
                                                double distanceAlongCurve, distanceFromCurve;
                                                AsRatioOrLength asRatOrLen = AsRatioOrLength.AsLength;
                                                SegmentExtension extension = SegmentExtension.NoExtension;
                                                MapPoint featurePoint = (MapPoint)pointFeature.GetShape();
                                                MapPoint mPoint = GeometryEngine.Instance.QueryPointAndDistance3D(centerpolyline, extension, featurePoint, asRatOrLen, out distanceAlongCurve, out distanceFromCurve);
                                                MessageBox.Show(distanceAlongCurve.ToString());
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.