コード例 #1
0
        private void SetLayersForPoints(IntersectionsInLayer intersections, ProfileSurface surface)
        {
            var surfaceForSearch = new List <ProfileSurfacePoint>(surface.ProfileSurfacePoints);

            intersections.Lines = intersections.Lines.OrderBy(line => line.PointFromDistance).ToList();

            var accuracy = 0.0000001;

            foreach (var line in intersections.Lines)
            {
                var startPoint = surfaceForSearch.First(surfacePoint => surfacePoint.Distance >= line.PointFromDistance ||
                                                        Math.Abs(surfacePoint.Distance - line.PointFromDistance) < accuracy);

                surfaceForSearch =
                    surfaceForSearch.SkipWhile(surfacePoint => surfacePoint.Distance < startPoint.Distance).ToList();

                foreach (var point in surfaceForSearch)
                {
                    if (point.Distance >= startPoint.Distance)
                    {
                        if (point.Distance > line.PointToDistance + accuracy)
                        {
                            break;
                        }

                        if (point.Layers == 0)
                        {
                            point.Layers = line.LayerType;
                        }
                        else
                        {
                            point.Layers = point.Layers | line.LayerType;
                        }

                        if (point.Distance == line.PointToDistance)
                        {
                            break;
                        }
                    }
                }
            }
        }
コード例 #2
0
        private void CalcIntesectionsWithLayers(ProfileLine selectedLine, ProfileSession profileSession)
        {
            var allIntersectionLines = new List <IntersectionsInLayer>();
            var layers           = View.GetLayers();
            var spatialReference = ArcMap.Document.FocusMap.SpatialReference;

            List <IPolyline>    polylines;
            List <ProfilePoint> pointsFrom;

            profileSession.Layers = new List <string>();

            if (selectedLine == null)
            {
                return;
            }

            if (selectedLine.Line.SpatialReference != spatialReference)
            {
                selectedLine.Line.Project(spatialReference);
            }

            var lineSurface    = profileSession.ProfileSurfaces.First(surface => surface.LineId == selectedLine.Id);
            var profileSegment = profileSession.Segments.First(segment => segment.LineId == selectedLine.Id);
            var distance       = 0.0;

            if (profileSegment.IsPrimitive)
            {
                polylines  = ProfileLinesConverter.ConvertLineToPrimitivePolylines(lineSurface, selectedLine.Line.SpatialReference);
                pointsFrom = profileSegment.Vertices;
            }
            else
            {
                polylines = new List <IPolyline> {
                    selectedLine.Line
                };
                pointsFrom = new List <ProfilePoint> {
                    selectedLine.PointFrom
                };
            }

            int j = 0;

            for (int n = 0; n < polylines.Count; n++)
            {
                var intersectionLines = new List <IntersectionsInLayer>();

                for (int i = 0; i < layers.Count; i++)
                {
                    if (!string.IsNullOrEmpty(layers[i]))
                    {
                        var layer = EsriTools.GetLayer(layers[i], ArcMap.Document.FocusMap);
                        var lines = EsriTools.GetIntersections(polylines[n], layer);

                        var layerFullName = $"Path/{layer.Name}";

                        if (!profileSession.Layers.Exists(sessionLayer => sessionLayer == layerFullName))
                        {
                            profileSession.Layers.Add(layerFullName);
                        }

                        if (lines != null && lines.Count() > 0)
                        {
                            var layerType        = (LayersEnum)Enum.GetValues(typeof(LayersEnum)).GetValue(i);
                            var intersectionLine = new IntersectionsInLayer
                            {
                                Lines = ProfileLinesConverter.ConvertEsriPolylineToIntersectionLines(lines, pointsFrom[j], layerType, distance),
                                Type  = layerType,
                            };

                            intersectionLine.SetDefaultColor();
                            intersectionLines.Add(intersectionLine);
                            SetLayersForPoints(intersectionLine, lineSurface);
                        }
                    }
                }

                allIntersectionLines.AddRange(intersectionLines);

                if (polylines.Count > 1)
                {
                    j++;

                    if (n < polylines.Count - 1)
                    {
                        distance += EsriTools.CreatePolylineFromPoints(polylines[n].FromPoint, polylines[n + 1].FromPoint).Length;
                    }
                }
            }

            graphsController.SetIntersections(allIntersectionLines, selectedLine.Id);
        }