public static void ProcessTransaction(RectangleShape boundingBox, Collection <Feature> returnFeatures, FeatureSource featureSource, bool needUpdateProjection = false)
        {
            if (featureSource.IsInTransaction && featureSource.IsTransactionLive)
            {
                foreach (Feature feature in featureSource.TransactionBuffer.AddBuffer.Values)
                {
                    if (boundingBox.Intersects(feature.GetBoundingBox()))
                    {
                        var newFeature = needUpdateProjection ? ConvertToExternalProjection(feature, featureSource) : feature;
                        returnFeatures.Add(newFeature);
                    }
                }

                Dictionary <string, Feature> recordsInDictionary = new Dictionary <string, Feature>();
                if (featureSource.TransactionBuffer.EditBuffer.Count > 0 || featureSource.TransactionBuffer.DeleteBuffer.Count > 0)
                {
                    recordsInDictionary = GetFeaturesDictionaryFromCollecion(returnFeatures);
                }

                foreach (Feature feature in featureSource.TransactionBuffer.EditBuffer.Values)
                {
                    bool isContained = boundingBox.Intersects(feature.GetBoundingBox());
                    if (isContained)
                    {
                        if (recordsInDictionary.ContainsKey(feature.Id))
                        {
                            Feature oringalFeature = recordsInDictionary[feature.Id];
                            returnFeatures.Remove(oringalFeature);
                        }

                        var newFeature = needUpdateProjection ? ConvertToExternalProjection(feature, featureSource) : feature;
                        returnFeatures.Add(newFeature);
                    }
                    else if (!isContained && recordsInDictionary.ContainsKey(feature.Id))
                    {
                        Feature oringalFeature = recordsInDictionary[feature.Id];
                        returnFeatures.Remove(oringalFeature);
                    }
                }

                foreach (string id in featureSource.TransactionBuffer.DeleteBuffer)
                {
                    if (recordsInDictionary.ContainsKey(id))
                    {
                        if (boundingBox.Intersects(recordsInDictionary[id].GetBoundingBox()) && recordsInDictionary.ContainsKey(id))
                        {
                            Feature feature = recordsInDictionary[id];
                            returnFeatures.Remove(feature);
                        }
                    }
                }
            }
        }
Exemple #2
0
        private Feature GetPointFromLines(IEnumerable <LineShape> lines, PointShape targetPointShape, RectangleShape searchingArea)
        {
            Feature returnFeature = new Feature();

            foreach (LineShape targetLineShape in lines)
            {
                if (searchingArea.Intersects(targetLineShape))
                {
                    Vertex vertexToBeAdded = new Vertex(targetLineShape.GetClosestPointTo(targetPointShape, GeographyUnit.DecimalDegree));
                    return(new Feature(vertexToBeAdded));
                }
            }

            return(returnFeature);
        }
Exemple #3
0
        private Collection <QuadTreeNode> GetIntersectedCells(RectangleShape boundingBox, int level)
        {
            Collection <QuadTreeNode> result = new Collection <QuadTreeNode>();

            ulong queriedBboxLocation = QTreeHelper.GetLocation(maxExtent, boundingBox, level);

            lock (sync)
            {
                foreach (ulong key in qtree.Keys)
                {
                    //QuadCell cell = QTreeHelper.GetCellByLocation(maxExtent, key);
                    if (QTreeHelper.HasPart(queriedBboxLocation, key) && boundingBox.Intersects(QTreeHelper.GetCellByLocation(maxExtent, key).BoundingBox))
                    {
                        result.Add(qtree[key]);
                    }
                }
            }

            return(result);
        }
        private Collection<QuadTreeNode> GetIntersectedCells(RectangleShape boundingBox, int level)
        {
            Collection<QuadTreeNode> result = new Collection<QuadTreeNode>();

            ulong queriedBboxLocation = QTreeHelper.GetLocation(maxExtent, boundingBox, level);
            lock (sync)
            {
                foreach (ulong key in qtree.Keys)
                {
                    //QuadCell cell = QTreeHelper.GetCellByLocation(maxExtent, key);
                    if (QTreeHelper.HasPart(queriedBboxLocation, key) && boundingBox.Intersects(QTreeHelper.GetCellByLocation(maxExtent, key).BoundingBox))
                    {
                        result.Add(qtree[key]);
                    }
                }
            }

            return result;
        }
        //internal static void ActiveMap_MapClick(object sender, MapClickWpfMapEventArgs e)
        internal static void ActiveMap_MapClick(object sender, MapMouseClickInteractiveOverlayEventArgs e)
        {
            if (ViewModel.IsInModifyMode)
            {
                ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.Open();
                RectangleShape clickBuffer = GetClickBuffer(e.InteractionArguments.WorldX, e.InteractionArguments.WorldY);

                #region save feature ids to exclude temporary.

                var tmpFeatureIdsToExclude = new Collection <string>();
                foreach (var id in ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude)
                {
                    tmpFeatureIdsToExclude.Add(id);
                }
                ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Clear();

                #endregion save feature ids to exclude temporary.

                var foundFeature = ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.QueryTools
                                   .GetFeaturesIntersecting(clickBuffer, ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.GetDistinctColumnNames()).FirstOrDefault(tmpFeature => !tmpFeatureIdsToExclude.Contains(tmpFeature.Id));

                if (foundFeature == default(Feature))
                {
                    PlatformGeoCanvas geoCanvas = new PlatformGeoCanvas();
                    foundFeature = ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.InternalFeatures
                                   .Where(tmpFeature => tmpFeature.ColumnValues.ContainsKey(AnnotationTrackInteractiveOverlay.AnnotationTextColumnName) &&
                                          !String.IsNullOrEmpty(tmpFeature.ColumnValues[AnnotationTrackInteractiveOverlay.AnnotationTextColumnName]))
                                   .FirstOrDefault(textFeature =>
                    {
                        if (tmpFeatureIdsToExclude.Contains(textFeature.Id))
                        {
                            return(false);
                        }

                        TextStyle textStyle = ViewModel.CurrentAnnotationOverlay
                                              .GetSpecificTextStyle(textFeature.ColumnValues[AnnotationTrackInteractiveOverlay.ValueStyleMatchColumnName]);

                        DrawingRectangleF textArea = geoCanvas.MeasureText(textFeature.ColumnValues[AnnotationTrackInteractiveOverlay.AnnotationTextColumnName]
                                                                           , textStyle.Font);

                        PointShape textScreenPoint = GisEditor.ActiveMap.ToScreenCoordinate((PointShape)textFeature.GetShape());

                        double left   = textScreenPoint.X;
                        double top    = textScreenPoint.Y;
                        double right  = textScreenPoint.X + textArea.Width;
                        double bottom = textScreenPoint.Y + textArea.Height;

                        string placementString = textStyle.PointPlacement.ToString();
                        if (placementString.Contains("Left"))
                        {
                            left = textScreenPoint.X - textArea.Width;
                        }

                        if (placementString.Contains("Upper"))
                        {
                            top = textScreenPoint.Y - textArea.Height;
                        }

                        PointShape upperLeft  = GisEditor.ActiveMap.ToWorldCoordinate(new PointShape(left, top));
                        PointShape lowerRight = GisEditor.ActiveMap.ToWorldCoordinate(new PointShape(right, bottom));

                        RectangleShape textWorldArea = new RectangleShape(upperLeft, lowerRight);
                        return(textWorldArea.Intersects(new PointShape(e.InteractionArguments.WorldX, e.InteractionArguments.WorldY)));
                    });
                }

                #region restore feature ids to exclude

                foreach (var id in tmpFeatureIdsToExclude)
                {
                    ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Add(id);
                }

                #endregion restore feature ids to exclude

                ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.Close();

                if (foundFeature != default(Feature))
                {
                    var isShiftDown = Keyboard.Modifiers == ModifierKeys.Shift;
                    if (!isShiftDown)
                    {
                        CommitEdit(false);
                    }

                    bool isEditing = true;
                    if (!ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Contains(foundFeature.Id))
                    {
                        ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Add(foundFeature.Id);
                    }
                    else
                    {
                        isEditing = false;
                        if (isShiftDown)
                        {
                            ViewModel.CurrentAnnotationOverlay.TrackShapeLayer.FeatureIdsToExclude.Remove(foundFeature.Id);
                            if (ViewModel.CurrentEditOverlay.EditShapesLayer.InternalFeatures.Contains(foundFeature.Id))
                            {
                                ViewModel.CurrentEditOverlay.EditShapesLayer.InternalFeatures.Remove(foundFeature.Id);
                            }
                        }
                    }

                    if (isEditing)
                    {
                        SetAnnotationToEditMode(foundFeature);
                    }

                    ViewModel.CurrentEditOverlay.CalculateAllControlPoints();
                    ViewModel.CurrentAnnotationOverlay.Refresh();
                    ViewModel.CurrentEditOverlay.Refresh();
                    ViewModel.SyncUIState();
                    ViewModel.TakeSnapshot();
                }
                else
                {
                    if (ViewModel.CurrentEditOverlay.EditShapesLayer.InternalFeatures.Count > 0 ||
                        (MarkerHelper.CurrentMarkerOverlay != null && MarkerHelper.CurrentMarkerOverlay.Markers.Count > 0))
                    {
                        System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() => CommitEdit()));
                    }
                }
            }
        }
Exemple #6
0
        public static Collection <QuadCell> GetIntersectingCells(RectangleShape extent, BaseShape shape, int startLevel, int endLevel)
        {
            RectangleShape extentBoundingBox = SquaredExtent(extent);
            RectangleShape shapeBoundingBox  = shape.GetBoundingBox();

            Collection <QuadCell> result = new Collection <QuadCell>();

            if (shapeBoundingBox.Intersects(extentBoundingBox))
            {
                ulong location       = GetLocation(extentBoundingBox, shape, int.MaxValue);
                ulong reversedResult = Reverse(location);
                ulong temporaryValue = reversedResult;
                temporaryValue >>= 1;

                int locationLength = GetLevelsCount(temporaryValue);
                if (startLevel <= locationLength)
                {
                    int index = startLevel;
                    while (index <= endLevel)
                    {
                        ulong temporaryLocation = temporaryValue;
                        if (index <= locationLength)
                        {
                            MovePositionByIndex(ref temporaryLocation, index);
                            if (locationLength > 1)
                            {
                                result.Add(GetCellByLocation(extentBoundingBox, temporaryLocation));
                            }
                            else
                            {
                                result.Add(GetCellByLocation(extentBoundingBox, 0));
                            }
                        }
                        index++;
                    }
                }
                if (endLevel > locationLength)
                {
                    Queue <ulong> locationsToProcess = new Queue <ulong>();
                    locationsToProcess.Enqueue(location);

                    while (locationsToProcess.Count > 0)
                    {
                        ulong currentLocation = locationsToProcess.Dequeue();

                        for (int k = 1; k <= 4; k++)
                        {
                            ulong newLocation = (currentLocation << k) | 1;
                            result.Add(GetCellByLocation(extentBoundingBox, newLocation));
                            int newLocationsCount = GetLevelsCount(newLocation);
                            if (newLocationsCount < endLevel)
                            {
                                locationsToProcess.Enqueue(newLocation);
                            }
                        }
                    }
                }
            }
            //if (result.Count == 0)
            //{
            //    result.Add(GetCellByLocation(extentBoundingBox, "01"));
            //    result.Add(GetCellByLocation(extentBoundingBox, "02"));
            //    result.Add(GetCellByLocation(extentBoundingBox, "03"));
            //    result.Add(GetCellByLocation(extentBoundingBox, "04"));
            //}
            return(result);
        }