public static Collection <Feature> GetFeaturesIntersecting(this QueryTools queryTools, BaseShape targetShape, IEnumerable <string> returningColumnNames, bool useSqlType)
        {
            Collection <Feature> returnFeatures = null;

            if (useSqlType)
            {
                returnFeatures = new Collection <Feature>();
                RectangleShape       boundingBox         = targetShape.GetBoundingBox();
                Collection <Feature> allPossibleFeatures = queryTools.GetFeaturesInsideBoundingBox(boundingBox, returningColumnNames);
                foreach (Feature feature in allPossibleFeatures)
                {
                    BaseShape sourceShape = feature.GetShape();
                    sourceShape = SqlTypesGeometryHelper.MakeValid(sourceShape);
                    targetShape = SqlTypesGeometryHelper.MakeValid(targetShape);
                    bool intersects = SqlTypesGeometryHelper.Intersects(sourceShape, targetShape);
                    if (intersects)
                    {
                        returnFeatures.Add(feature);
                    }
                }
            }
            else
            {
                returnFeatures = queryTools.GetFeaturesIntersecting(targetShape, returningColumnNames);
            }
            return(returnFeatures);
        }
Пример #2
0
        public IEnumerable <Feature> IntersectFeatures(IEnumerable <Feature> features)
        {
            List <Feature> featuresList = features.ToList();

            var results       = new ConcurrentStack <Feature>();
            var featureGroups = featuresList.GroupBy(feature => feature.Tag).ToList();
            int index         = 1;

            for (int i = 0; i < featureGroups.Count; i++)
            {
                var group = featureGroups[i];
                foreach (var feature in group)
                {
                    int progress = index * 100 / featuresList.Count;
                    isCanceled = ReportProgress(progress, index, featuresList.Count);
                    if (isCanceled)
                    {
                        break;
                    }

                    var otherFeatures = featureGroups.Where(g => featureGroups.IndexOf(g) > i).SelectMany(f => f);
                    Parallel.ForEach(otherFeatures, otherFeature =>
                    {
                        try
                        {
                            AreaBaseShape originalShape = (AreaBaseShape)feature.GetShape();
                            AreaBaseShape matchShape    = (AreaBaseShape)otherFeature.GetShape();

                            //if (originalShape.Intersects(matchShape))
                            if (SqlTypesGeometryHelper.Intersects(originalShape, matchShape))
                            {
                                //AreaBaseShape resultShape = originalShape.GetIntersection(matchShape);
                                AreaBaseShape resultShape = (AreaBaseShape)SqlTypesGeometryHelper.GetIntersection(originalShape, matchShape);
                                if (resultShape != null)
                                {
                                    var columnValues      = GetColumnValues(feature, otherFeature);
                                    Feature resultFeature = new Feature(resultShape, columnValues);
                                    results.Push(resultFeature);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    });

                    index++;
                }
            }

            return(results);
        }
Пример #3
0
        private IEnumerable <Feature> StandardClipPoints(IEnumerable <Feature> masterFeatures, IEnumerable <Feature> clippingFeatures)
        {
            ConcurrentQueue <Feature> results = new ConcurrentQueue <Feature>();
            int index = 1;
            int count = masterFeatures.Count();
            ConcurrentQueue <Feature> cqMasterFeatures = new ConcurrentQueue <Feature>(masterFeatures);

            if (count > 0)
            {
                var firstFeature = masterFeatures.FirstOrDefault();
                var firstWktType = firstFeature.GetWellKnownType();
                if (firstWktType == WellKnownType.Point)
                {
                    Parallel.ForEach(cqMasterFeatures, feature =>
                    {
                        index++;
                        isCanceled = ReportProgress(index, count);
                        if (isCanceled)
                        {
                            return;
                        }

                        if (clippingFeatures.Any(f =>
                        {
                            try //{ return f.GetShape().Intersects(feature); }
                            {
                                return(SqlTypesGeometryHelper.Intersects(f.GetShape(), feature));
                            }
                            catch (Exception ex)
                            {
                                GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                                HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                                return(false);
                            }
                        }))
                        {
                            results.Enqueue(feature);
                        }
                    });
                }
                else
                {
                    Parallel.ForEach(cqMasterFeatures, feature =>
                    {
                        isCanceled = ReportProgress(index, count);
                        if (isCanceled)
                        {
                            return;
                        }

                        index++;
                        MultipointShape multiPoints = feature.GetShape() as MultipointShape;
                        if (multiPoints != null)
                        {
                            MultipointShape resultPoints = new MultipointShape();
                            Parallel.ForEach(multiPoints.Points, p =>
                            {
                                if (clippingFeatures.Any(f =>
                                {
                                    try //{ return f.GetShape().Intersects(p); }
                                    {
                                        return(SqlTypesGeometryHelper.Intersects(f.GetShape(), p));
                                    }
                                    catch (Exception ex)
                                    {
                                        GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                                        HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                                        return(false);
                                    }
                                }))
                                {
                                    resultPoints.Points.Add(p);
                                }
                            });
                            if (resultPoints.Points.Count > 0)
                            {
                                results.Enqueue(new Feature(resultPoints.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                            }
                        }
                    });
                }
            }
            return(results);
        }