예제 #1
0
        public PasteResult Paste(int layerHandle, Shapefile sf)
        {
            if (sf == null || IsEmpty)
            {
                return(PasteResult.NoInput);
            }
            if (!sf.InteractiveEditing)
            {
                return(PasteResult.NoInput);
            }
            if (IsEmpty)
            {
                return(PasteResult.NoInput);
            }

            if (_buffer.ShapefileType != sf.ShapefileType)
            {
                return(PasteResult.ShapeTypeMismatch);
            }

            var fieldMap = _buffer.BuildFieldMap(sf);

            var undoList = App.Map.UndoList;

            undoList.BeginBatch();

            sf.SelectNone();

            for (int i = 0; i < _buffer.NumShapes; i++)
            {
                int shapeIndex = sf.EditAddShape(_buffer.Shape[i].Clone()); // don't create a copy, buffer won't be used any more
                _buffer.CopyAttributes(i, sf, shapeIndex, fieldMap);        // TODO: don't use field map for the same shapefile
                undoList.Add(tkUndoOperation.uoAddShape, layerHandle, shapeIndex);
                sf.ShapeSelected[shapeIndex] = true;
            }

            undoList.EndBatch();

            Clear();
            return(PasteResult.Ok);
        }
예제 #2
0
 public static void CopyAttributes(this Shapefile sf, int sourceIndex, int targetIndex)
 {
     sf.CopyAttributes(sourceIndex, sf, targetIndex);
 }
        /// <summary>
        /// Runs explode operation
        /// </summary>
        private static ExplodeResult Explode(int layerHandle, Shapefile sf)
        {
            var dict = new Dictionary <int, Shape[]>();

            // exploding
            for (int i = 0; i < sf.NumShapes; i++)
            {
                object result = null;
                if (sf.ShapeSelected[i])
                {
                    sf.Shape[i].Explode(ref result);
                    var shapes = result as object[];
                    if (shapes != null && shapes.Any())
                    {
                        dict[i] = shapes.Cast <Shape>().ToArray();
                    }
                    else
                    {
                        return(ExplodeResult.Failed);
                    }
                }
            }

            int newSelectionStart = sf.NumShapes - sf.NumSelected;
            var undoList          = App.Map.UndoList;

            undoList.BeginBatch();

            // add new shapes
            var list = dict.ToList();

            foreach (var item in list)
            {
                foreach (var shp in item.Value.ToList())
                {
                    int shapeIndex = sf.EditAddShape(shp);

                    sf.CopyAttributes(item.Key, shapeIndex);

                    if (shapeIndex != -1)
                    {
                        undoList.Add(tkUndoOperation.uoAddShape, layerHandle, shapeIndex);
                    }
                }
            }

            // remove the old ones
            for (int i = sf.NumShapes - 1; i >= 0; i--)
            {
                if (sf.ShapeSelected[i])
                {
                    undoList.Add(tkUndoOperation.uoRemoveShape, layerHandle, i);
                    sf.EditDeleteShape(i);
                }
            }

            undoList.EndBatch();

            for (int i = newSelectionStart; i < sf.NumShapes; i++)
            {
                sf.ShapeSelected[i] = true;
            }

            return(ExplodeResult.Ok);
        }