Пример #1
0
        private void BuildPaths(MapArgs e, IEnumerable <IFeature> features, out List <GraphicsPath> borderPaths)
        {
            borderPaths = new List <GraphicsPath>();
            Rectangle          clipRect    = ComputeClippingRectangle(e);
            Extent             drawExtents = e.PixelToProj(clipRect);
            SoutherlandHodgman shClip      = new SoutherlandHodgman(clipRect);

            for (int selectState = 0; selectState < 2; selectState++)
            {
                foreach (IPolygonCategory category in Symbology.Categories)
                {
                    // Determine the subset of the specified features that are visible and match the category
                    IPolygonCategory polygonCategory = category;
                    int i = selectState;
                    Func <IDrawnState, bool> isMember = state =>
                                                        state.SchemeCategory == polygonCategory &&
                                                        state.IsVisible &&
                                                        state.IsSelected == (i == 1);

                    var drawnFeatures = from feature in features
                                        where isMember(DrawingFilter[feature])
                                        select feature;

                    GraphicsPath borderPath = new GraphicsPath();
                    foreach (IFeature f in drawnFeatures)
                    {
                        BuildPolygon(DataSet.Vertex, f.ShapeIndex, borderPath, e,
                                     drawExtents.Contains(f.Envelope) ? null : shClip);
                    }
                    borderPaths.Add(borderPath);
                }
            }
        }
Пример #2
0
        private Tuple <IFeature, Coordinate> ComputSnapPointModeFeature(IFeatureLayer layer, Extent extent)
        {
            Tuple <IFeature, Coordinate> tuple = null;

            if (SnapMode == SnapMode.None || layer == null || extent == null)
            {
                return(tuple);
            }
            if ((SnapMode & SnapMode.Point) > 0 && (layer.DataSet.FeatureType == FeatureType.Point || layer.DataSet.FeatureType == FeatureType.MultiPoint))
            {
                var features = layer.DataSet.Select(extent);
                foreach (var feature in features)
                {
                    foreach (var coordinate in feature.Geometry.Coordinates)
                    {
                        if (extent.Contains(coordinate))
                        {
                            tuple = new Tuple <IFeature, Coordinate>(feature, coordinate);
                            break;
                        }
                    }
                    if (tuple != null)
                    {
                        break;
                    }
                }
            }
            return(tuple);
        }
Пример #3
0
 protected bool IsInExtent(Coordinate p)
 {
     if (_extentLocator != null)
     {
         return(_extentLocator.Locate(p) != Location.Exterior);
     }
     return(Extent.Contains(p));
 }
Пример #4
0
        public void ExtentContainsNullExtentTest()
        {
            Extent container = new Extent(0, 0, 10, 20);
            Extent contained = null;

            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.Throws <ArgumentNullException>(() => { container.Contains(contained); });
        }
Пример #5
0
        public void ExtentContainsNullCoordinateTest()
        {
            Extent     container = new Extent(0, 0, 10, 20);
            Coordinate c         = null;

            // ReSharper disable once ExpressionIsAlwaysNull
            Assert.Throws <ArgumentNullException>(delegate { container.Contains(c); });
        }
Пример #6
0
        private Tuple <IFeature, Coordinate> ComputSnapEndModeFeature(IFeatureLayer layer, Extent extent)
        {
            Tuple <IFeature, Coordinate> tuple = null;

            if (SnapMode == SnapMode.None || layer == null || extent == null)
            {
                return(tuple);
            }
            if ((SnapMode & SnapMode.End) > 0 && (layer.DataSet.FeatureType == FeatureType.Line || layer.DataSet.FeatureType == FeatureType.Polygon))
            {
                var features = layer.DataSet.Select(extent);
                foreach (var feature in features)
                {
                    for (int i = 0; i < feature.Geometry.NumGeometries; i++)
                    {
                        var geoItem    = feature.Geometry.GetGeometryN(i);
                        var firstCoord = geoItem.Coordinates.FirstOrDefault();
                        if (extent.Contains(firstCoord))
                        {
                            tuple = new Tuple <IFeature, Coordinate>(feature, firstCoord);
                        }
                        else
                        {
                            var lastCoord = geoItem.Coordinates.LastOrDefault();
                            if (extent.Contains(lastCoord))
                            {
                                tuple = new Tuple <IFeature, Coordinate>(feature, lastCoord);
                            }
                        }
                        if (tuple != null)
                        {
                            break;
                        }
                    }
                    if (tuple != null)
                    {
                        break;
                    }
                }
            }
            return(tuple);
        }
Пример #7
0
        /// <summary>
        /// ÇöÀç ¸¶¿ì½º À§Ä¡ÀÇ Á¤Á¡À» ÆíÁý ´ë»ó ÁÂÇ¥·Î ¼³Á¤ÇÕ´Ï´Ù.
        /// </summary>
        private void VertexHighlight()
        {
            Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);
            Extent    ext       = Map.PixelToProj(mouseRect);

            if (_activeVertex != null && !ext.Contains(_activeVertex))
            {
                _activeVertex = null;
                Map.Invalidate();
            }

            foreach (Coordinate c in _selectedFeature.Geometry.Coordinates)
            {
                if (ext.Contains(c))
                {
                    _activeVertex = c;
                    Map.Invalidate();
                }
            }
        }
Пример #8
0
        private void VertexHighlight()
        {
            // The feature is selected so color vertex that can be moved but don't highlight other shapes.
            Rectangle mouseRect = new Rectangle(_mousePosition.X - 3, _mousePosition.Y - 3, 6, 6);
            Extent    ext       = Map.PixelToProj(mouseRect);

            if (_activeVertex != null && !ext.Contains(_activeVertex))
            {
                _activeVertex = null;
                Map.Invalidate();
            }

            foreach (Coordinate c in _selectedFeature.Geometry.Coordinates)
            {
                if (ext.Contains(c))
                {
                    _activeVertex = c;
                    Map.Invalidate();
                }
            }
        }
Пример #9
0
        public void ExtentContainsCoordinateTest(ExtentTestData data)
        {
            Extent     container = new Extent(data.ContainerValues);
            var        vals      = data.ContainedValues;
            Coordinate contained = new Coordinate(vals[0], vals[1]);

            Assert.AreEqual(data.ExpectedReturnValue, container.Contains(contained));

            //// this is to make sure that the extent methods work the same way the IGeometry methods do
            // var containerEnv = container.ToEnvelope().ToPolygon();
            // var containedPnt = new Point(contained);
            // Assert.AreEqual(data.ExpectedReturnValue, containerEnv.Contains(containedPnt));
        }
Пример #10
0
        public void ExtentContainsExtentTest(ExtentTestData data)
        {
            Extent container = new Extent(data.ContainerValues);
            var    vals      = data.ContainedValues;
            Extent contained = new Extent(vals[0], vals[1], vals[2], vals[3]);

            Assert.AreEqual(data.ExpectedReturnValue, container.Contains(contained), "ExtentContainsExtent");

            // this is to make sure that the extent methods work the same way the IGeometry methods do
            var containerEnv = container.ToEnvelope().ToPolygon();
            var containedEnv = contained.ToEnvelope().ToPolygon();

            Assert.AreEqual(data.ExpectedReturnValue, containerEnv.Contains(containedEnv), "ExtentGeometryContainsExtentGeometry");
        }
Пример #11
0
        private void BuildPaths(MapArgs e, IEnumerable <IFeature> features, out Dictionary <FastDrawnState, GraphicsPath> borderPaths, bool selected)
        {
            borderPaths = new Dictionary <FastDrawnState, GraphicsPath>();

            if (selected && !DrawingFilter.DrawnStates.Any(_ => _.Value.IsSelected))
            {
                return;
            }

            Rectangle          clipRect    = ComputeClippingRectangle(e);
            Extent             drawExtents = e.PixelToProj(clipRect);
            SoutherlandHodgman shClip      = new SoutherlandHodgman(clipRect);

            var featureList = features as IList <IFeature> ?? features.ToList();

            foreach (var category in Symbology.Categories)
            {
                // Determine the subset of the specified features that are visible and match the category
                IFeatureCategory         polygonCategory = category;
                Func <IDrawnState, bool> isMember;

                if (selected)
                {
                    // get only selected features
                    isMember = state => state.SchemeCategory == polygonCategory && state.IsVisible && state.IsSelected;
                }
                else
                {
                    // get all features
                    isMember = state => state.SchemeCategory == polygonCategory && state.IsVisible;
                }

                var drawnFeatures = (from feature in featureList where isMember(DrawingFilter[feature]) select feature).ToList();

                if (drawnFeatures.Count > 0)
                {
                    GraphicsPath borderPath = new GraphicsPath();
                    foreach (IFeature f in drawnFeatures)
                    {
                        BuildPolygon(DataSet.Vertex, f.ShapeIndex, borderPath, e, drawExtents.Contains(f.Geometry.EnvelopeInternal) ? null : shClip);
                    }

                    borderPaths.Add(new FastDrawnState(selected, category), borderPath);
                }
            }
        }
Пример #12
0
        OutlineElement FindExtactMatch(int position)
        {
            if (!Extent.Contains(position))
            {
                return(null);
            }

            if (Children.Length == 0)
            {
                return(this);
            }

            var bestChild = Children.Select(entry => entry.FindExtactMatch(position))
                            .FirstOrDefault(c => c != null);

            return(bestChild ?? this);
        }
Пример #13
0
        private Tuple <IFeature, Coordinate> ComputSnapVertexModeFeature(IFeatureLayer layer, Extent extent)
        {
            Tuple <IFeature, Coordinate> tuple = null;

            if (SnapMode == SnapMode.None || layer == null || extent == null)
            {
                return(tuple);
            }
            if ((SnapMode & SnapMode.Vertex) > 0 && (layer.DataSet.FeatureType == FeatureType.Line || layer.DataSet.FeatureType == FeatureType.Polygon))
            {
                var features = layer.DataSet.Select(extent);
                foreach (var feature in features)
                {
                    for (int i = 0; i < feature.Geometry.NumGeometries; i++)
                    {
                        var geoItem = feature.Geometry.GetGeometryN(i);
                        for (int j = 1; j < geoItem.NumPoints - 1; j++)
                        {
                            var coord = geoItem.Coordinates[j];
                            if (extent.Contains(coord))
                            {
                                tuple = new Tuple <IFeature, Coordinate>(feature, coord);
                                break;
                            }
                        }
                        if (tuple != null)
                        {
                            break;
                        }
                    }
                    if (tuple != null)
                    {
                        break;
                    }
                }
            }
            return(tuple);
        }
Пример #14
0
        private void BuildPaths(MapArgs e, IEnumerable <int> indices, out Dictionary <FastDrawnState, GraphicsPath> paths, bool selected)
        {
            paths = new Dictionary <FastDrawnState, GraphicsPath>();

            var indiceList = indices as IList <int> ?? indices.ToList();

            FastDrawnState[] states = DrawnStatesNeeded ? DrawnStates : new FastDrawnState[0];
            if (DrawnStatesNeeded && indiceList.Max() >= states.Length)
            {
                AssignFastDrawnStates();
                states = DrawnStates;
            }

            if (selected && (!DrawnStatesNeeded || !DrawnStates.Any(_ => _.Selected)))
            {
                return;
            }

            if (ProgressReportingEnabled)
            {
                ProgressMeter = new ProgressMeter(ProgressHandler, "Building Paths", indiceList.Count);
            }

            FastDrawnState     state       = new FastDrawnState(selected, Symbology.Categories[0]);
            Extent             drawExtents = e.GeographicExtents;
            Rectangle          clipRect    = e.ProjToPixel(e.GeographicExtents);
            SoutherlandHodgman shClip      = new SoutherlandHodgman(clipRect);

            List <ShapeRange> shapes = DataSet.ShapeIndices;

            double[] vertices = DataSet.Vertex;

            foreach (int shp in indiceList)
            {
                if (ProgressReportingEnabled)
                {
                    ProgressMeter.Next();
                }
                if (shp >= shapes.Count)
                {
                    return;
                }
                ShapeRange shape = shapes[shp];
                if (!shape.Extent.Intersects(e.GeographicExtents))
                {
                    continue;
                }

                if (DrawnStatesNeeded)
                {
                    if (!states[shp].Visible || (selected && !states[shp].Selected))
                    {
                        continue;
                    }

                    state = new FastDrawnState(selected, states[shp].Category);
                }

                if (!paths.ContainsKey(state))
                {
                    paths.Add(state, new GraphicsPath(FillMode.Winding));
                }

                BuildPolygon(vertices, shapes[shp], paths[state], e, drawExtents.Contains(shape.Extent) ? null : shClip);
            }

            if (ProgressReportingEnabled)
            {
                ProgressMeter.Reset();
            }
        }
Пример #15
0
        private void BuildPaths(MapArgs e, IEnumerable <int> indices, out List <GraphicsPath> paths)
        {
            DateTime startTime = DateTime.Now;

            paths = new List <GraphicsPath>();
            Rectangle          clipRect    = ComputeClippingRectangle(e);
            Extent             drawExtents = e.PixelToProj(clipRect);
            SoutherlandHodgman shClip      = new SoutherlandHodgman(clipRect);

            List <GraphicsPath> graphPaths = new List <GraphicsPath>();
            Dictionary <FastDrawnState, GraphicsPath> borders = new Dictionary <FastDrawnState, GraphicsPath>();

            for (int selectState = 0; selectState < 2; selectState++)
            {
                foreach (IPolygonCategory category in Symbology.Categories)
                {
                    FastDrawnState state = new FastDrawnState(selectState == 1, category);

                    GraphicsPath border = new GraphicsPath();
                    borders.Add(state, border);
                    graphPaths.Add(border);
                }
            }

            paths.AddRange(graphPaths);

            List <ShapeRange> shapes = DataSet.ShapeIndices;

            double[] vertices = DataSet.Vertex;

            if (ProgressReportingEnabled)
            {
                ProgressMeter = new ProgressMeter(ProgressHandler, "Building Paths", indices.Count());
            }

            if (!DrawnStatesNeeded)
            {
                FastDrawnState state = new FastDrawnState(false, Symbology.Categories[0]);

                foreach (int shp in indices)
                {
                    if (ProgressReportingEnabled)
                    {
                        ProgressMeter.Next();
                    }
                    ShapeRange shape = shapes[shp];
                    if (!shape.Extent.Intersects(e.GeographicExtents))
                    {
                        return;
                    }
                    if (shp >= shapes.Count)
                    {
                        return;
                    }
                    if (!borders.ContainsKey(state))
                    {
                        return;
                    }

                    BuildPolygon(vertices, shapes[shp], borders[state], e, drawExtents.Contains(shape.Extent) ? null : shClip);
                }
            }
            else
            {
                FastDrawnState[] states = DrawnStates;
                foreach (GraphicsPath borderPath in borders.Values)
                {
                    if (borderPath != null)
                    {
                        borderPath.FillMode = FillMode.Winding;
                    }
                }

                foreach (int shp in indices)
                {
                    if (ProgressReportingEnabled)
                    {
                        ProgressMeter.Next();
                    }
                    if (shp >= shapes.Count)
                    {
                        return;
                    }
                    if (shp >= states.Length)
                    {
                        AssignFastDrawnStates();
                        states = DrawnStates;
                    }
                    if (states[shp].Visible == false)
                    {
                        continue;
                    }
                    ShapeRange shape = shapes[shp];
                    if (!shape.Extent.Intersects(e.GeographicExtents))
                    {
                        return;
                    }
                    if (drawExtents.Contains(shape.Extent))
                    {
                        FastDrawnState state = states[shp];
                        if (!borders.ContainsKey(state))
                        {
                            return;
                        }
                        BuildPolygon(vertices, shapes[shp], borders[state], e, null);
                    }
                    else
                    {
                        FastDrawnState state = states[shp];
                        if (!borders.ContainsKey(state))
                        {
                            return;
                        }
                        BuildPolygon(vertices, shapes[shp], borders[state], e, shClip);
                    }
                }
            }
            if (ProgressReportingEnabled)
            {
                ProgressMeter.Reset();
            }

            TimeSpan interval = DateTime.Now - startTime;

            totalTime += interval.TotalMilliseconds;

            //Console.WriteLine("Total milliseconds: " + totalTime.ToString());
        }
Пример #16
0
        private void button2_Click(object sender, EventArgs e)
        {
            // Iterate through each properties of shapefiles
            foreach (CropProperties property in _properties)
            {
                // Test if checked or not
                foreach (ListViewItem item in listView1.CheckedItems)
                {
                    if (item.Text.Contains(property.shp.Name))
                    {
                        // Get original shapefile and reproject to WGS84
                        Shapefile      file        = property.shp;
                        ProjectionInfo originalPrj = file.Projection;
                        ProjectionInfo WGS84       = ProjectionInfo.FromProj4String(KnownCoordinateSystems.Geographic.World.WGS1984.ToProj4String());
                        file.Reproject(WGS84);

                        // Create new shapefile & set projection
                        FeatureSet result = new FeatureSet(FeatureType.Polygon);
                        result.Projection = file.Projection;

                        // Set new extent
                        Extent extent = new Extent();
                        extent.SetValues(property.minCrop.Lng, property.minCrop.Lat, property.maxCrop.Lng, property.maxCrop.Lat);

                        // Copy feature data
                        result.CopyTableSchema(file);

                        foreach (Feature f in file.Features)
                        {
                            // Test to see if coord is within extent
                            Shape              shp    = f.ToShape();
                            IGeometry          geom   = shp.ToGeometry();
                            IList <Coordinate> coords = geom.Coordinates;
                            int hit = 0;
                            foreach (Coordinate coord in coords)
                            {
                                if (extent.Contains(coord))
                                {
                                    hit++;
                                }
                                else
                                {
                                    continue;
                                }
                            }
                            if (hit != 0)
                            {
                                // Iterate through coords in list
                                Polygon poly = new Polygon(coords);
                                result.AddFeature(poly).CopyAttributes(f);
                            }
                            else
                            {
                                continue;
                            }
                        }
                        // Project pts back to original and save
                        result.Reproject(originalPrj);
                        if (property.path.Contains(".shp"))
                        {
                            result.SaveAs(property.path, true);
                        }

                        else
                        {
                            result.SaveAs(property.path + ".shp", true);
                        }
                    }
                }
            }
            this.Close();
        }
Пример #17
0
 /// <summary>
 /// Gibt an, ob der angegebene Punkt innerhalb des Bereichs des Items liegt.
 /// Liefert false, falls es keinen definierten Bereich gibt (z.B. Projekt Items)
 /// </summary>
 public bool Contains(int position)
 {
     return(Extent.Contains(position));
 }
Пример #18
0
        public override void HandleEvent(ref Event Event)
        {
            bool  Tracking;
            int   P, S, ClickPart;
            Point Mouse;
            Rect  Extent;

            base.HandleEvent(ref Event);
            int I = 0;

            switch (Event.What)
            {
            case Event.MouseDown:
                Clicked();
                Mouse  = MakeLocal(Event.Where);
                Extent = GetExtent();
                Extent.Grow(1, 1);
                P         = (int)GetPos();
                S         = (int)GetSize() - 1;
                ClickPart = GetPartCode(Mouse, Extent, P, S);
                if (ClickPart == sbIndicator)
                {
                    do
                    {
                        Mouse = MakeLocal(Event.Where);
                        if (GetPartCode(Mouse, Extent, P, S) == ClickPart)
                        {
                            SetValue((int)(Value + ScrollStep(ClickPart)));
                        }
                    }while(MouseEvent(ref Event, Event.MouseAuto));
                }
                else
                {
                    do
                    {
                        Mouse    = MakeLocal(Event.Where);
                        Tracking = Extent.Contains(Mouse);
                        if (Tracking)
                        {
                            if (Size.X == 1)
                            {
                                I = Mouse.Y;
                            }
                            else
                            {
                                I = Mouse.X;
                            }
                            if (I < 0)
                            {
                                I = 1;
                            }
                            if (I > S)
                            {
                                I = S - 1;
                            }
                        }
                        else
                        {
                            I = (int)GetPos();
                        }
                        if (I != P)
                        {
                            DrawPos(I);
                            P = I;
                        }
                    }while(MouseEvent(ref Event, Event.MouseMove));
                    if (Tracking && (S > 2))
                    {
                        S -= 2;
                        SetValue(((P - 1) * (Max - Min) + (S >> 1)) / S + Min);
                    }
                }
                ClearEvent(ref Event);
                break;

            case Event.KeyDown:
                if ((State & StateFlags.Visible) != 0)
                {
                    ClickPart = sbIndicator;
                    if (Size.Y == 1)
                    {
                        switch (Drivers.CtrlToArrow(Event.KeyCode))
                        {
                        case KeyboardKeys.Left:
                            ClickPart = sbLeftArrow;
                            break;

                        case KeyboardKeys.Right:
                            ClickPart = sbRightArrow;
                            break;

                        case KeyboardKeys.CtrlLeft:
                            ClickPart = sbPageLeft;
                            break;

                        case KeyboardKeys.CtrlRight:
                            ClickPart = sbPageRight;
                            break;

                        case KeyboardKeys.Home:
                            I = Min;
                            break;

                        case KeyboardKeys.End:
                            I = Max;
                            break;

                        default:
                            return;
                        }
                    }
                    else
                    {
                        switch (Drivers.CtrlToArrow(Event.KeyCode))
                        {
                        case KeyboardKeys.Up:
                            ClickPart = sbUpArrow;
                            break;

                        case KeyboardKeys.Down:
                            ClickPart = sbDownArrow;
                            break;

                        case KeyboardKeys.PageUp:
                            ClickPart = sbPageUp;
                            break;

                        case KeyboardKeys.PageDown:
                            ClickPart = sbPageDown;
                            break;

                        case KeyboardKeys.CtrlPageUp:
                            I = Min;
                            break;

                        case KeyboardKeys.CtrlPageDown:
                            I = Max;
                            break;

                        default:
                            return;
                        }
                    }
                    Clicked();
                    if (ClickPart != sbIndicator)
                    {
                        I = (int)(Value + ScrollStep(ClickPart));
                    }
                    SetValue(I);
                    ClearEvent(ref Event);
                }
                break;
            }
        }