Esempio n. 1
0
        public static AreaBaseShape[] SubtractAreas(IEnumerable <Feature> features)
        {
            AreaBaseShape[] polygons = features.Select(f => f.MakeValidUsingSqlTypes().GetShape())
                                       .OfType <AreaBaseShape>()
                                       .Select(s => s.ToPolygonOrMultiPolygon()).ToArray();

            for (int i = 0; i < polygons.Length; i++)
            {
                AreaBaseShape firstLoopShape = polygons[i];
                for (int j = i + 1; j < polygons.Length; j++)
                {
                    AreaBaseShape secondLoopShape = polygons[j];
                    var           tempSharp       = firstLoopShape.GetDifference(secondLoopShape);
                    if (tempSharp != null)
                    {
                        firstLoopShape = tempSharp;
                    }
                }
                if (firstLoopShape != null)
                {
                    polygons[i] = firstLoopShape;
                }
            }

            return(polygons);
        }
Esempio n. 2
0
        private void trackOverlay_TrackEnded(object sender, TrackEndedTrackInteractiveOverlayEventArgs e)
        {
            //Gets the shape from the tracked polygon. The tracked shapes can be found in the TrackShapeLayer of the TrackOverlay.
            AreaBaseShape areaBaseShape = (AreaBaseShape)winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures[0].GetShape();

            //Gets the features of the counties that are completely within the tracked polygon.
            LayerOverlay          layerOverlay          = (LayerOverlay)winformsMap1.Overlays["LayerOverlay"];
            ShapeFileFeatureLayer shapeFileFeatureLayer = (ShapeFileFeatureLayer)layerOverlay.Layers["CountiesLayer"];
            Collection <Feature>  features = shapeFileFeatureLayer.QueryTools.GetFeaturesWithin(areaBaseShape, ReturningColumnsType.NoColumns);

            //Adds the shape of the selected counties features to AreaBaseShape collection to perform the Union.
            Collection <AreaBaseShape> areaBaseShapes = new Collection <AreaBaseShape>();

            foreach (Feature feature in features)
            {
                areaBaseShapes.Add((AreaBaseShape)feature.GetShape());
            }
            MultipolygonShape unionMultipolygonShape = MultipolygonShape.Union(areaBaseShapes);

            //Gets the MultiPolygonShape with the inner ring(s) being the result of the Union of the selected shapes.
            MultipolygonShape resultMultiPolygonShape = areaBaseShape.GetDifference(unionMultipolygonShape);

            //Adds the result to the InMemoryFeatureLayer for display on the map.
            LayerOverlay         dynamicOverlay       = (LayerOverlay)winformsMap1.Overlays["DynamicOverlay"];
            InMemoryFeatureLayer inMemoryFeatureLayer = (InMemoryFeatureLayer)dynamicOverlay.Layers["DynamicLayer"];

            inMemoryFeatureLayer.InternalFeatures.Clear();

            inMemoryFeatureLayer.InternalFeatures.Add(new Feature(resultMultiPolygonShape));

            //We clear the tracked shape so that it does not show on the map.
            winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures.Clear();

            winformsMap1.Refresh(winformsMap1.Overlays["DynamicOverlay"]);
        }
        private void btnDifference_Click(object sender, RoutedEventArgs e)
        {
            InMemoryFeatureLayer inMemoryLayer = (InMemoryFeatureLayer)mapView.FindFeatureLayer("InMemoryFeatureLayer");

            if (inMemoryLayer.InternalFeatures.Count > 1)
            {
                AreaBaseShape sourceShape = (AreaBaseShape)inMemoryLayer.InternalFeatures["AreaShape2"].GetShape();
                AreaBaseShape targetShape = (AreaBaseShape)inMemoryLayer.InternalFeatures["AreaShape1"].GetShape();
                AreaBaseShape resultShape = sourceShape.GetDifference(targetShape);

                inMemoryLayer.InternalFeatures.Clear();
                inMemoryLayer.InternalFeatures.Add("ResultFeature", new Feature(resultShape.GetWellKnownBinary(), "ResultFeature"));
                inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillBrush = new GeoSolidBrush(GeoColor.FromArgb(100, GeoColors.Blue));

                mapView.Overlays["InmemoryOverlay"].Refresh();
            }
        }
        private void DifferenceButtonClick(object sender, EventArgs e)
        {
            LayerOverlay         inMemoryOverlay = (LayerOverlay)androidMap.Overlays["InMemoryOverlay"];
            InMemoryFeatureLayer inMemoryLayer   = (InMemoryFeatureLayer)inMemoryOverlay.Layers["InMemoryFeatureLayer"];

            if (inMemoryLayer.InternalFeatures.Count > 1)
            {
                AreaBaseShape sourceShape = (AreaBaseShape)inMemoryLayer.InternalFeatures["AreaShape2"].GetShape();
                AreaBaseShape targetShape = (AreaBaseShape)inMemoryLayer.InternalFeatures["AreaShape1"].GetShape();
                AreaBaseShape resultShape = sourceShape.GetDifference(targetShape);

                inMemoryLayer.InternalFeatures.Clear();
                inMemoryLayer.InternalFeatures.Add("ResultFeature", new Feature(resultShape.GetWellKnownBinary(), "ResultFeature"));
                inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.Blue);

                androidMap.Overlays["InMemoryOverlay"].Refresh();
            }
        }