示例#1
0
        private void mapView_MapClick(object sender, MapClickMapViewEventArgs e)
        {
            FeatureLayer worldLayer = mapView.FindFeatureLayer("WorldLayer");

            // Find the country the user clicked on.
            worldLayer.Open();
            Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(e.WorldLocation, new string[1] {
                "CNTRY_NAME"
            });

            worldLayer.Close();

            // Determine the area of the country.
            if (selectedFeatures.Count > 0)
            {
                ProjectionConverter project = new ProjectionConverter(3857, 4326);
                project.Open();
                AreaBaseShape areaShape = (AreaBaseShape)project.ConvertToExternalProjection(selectedFeatures[0].GetShape());
                project.Close();
                double area        = areaShape.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareKilometers);
                string areaMessage = string.Format(CultureInfo.InvariantCulture, "{0} has an area of \r{1:N0} square kilometers.", selectedFeatures[0].ColumnValues["CNTRY_NAME"].Trim(), area);

                Popup popup = new Popup(e.WorldLocation);
                popup.Content = areaMessage;
                PopupOverlay popupOverlay = (PopupOverlay)mapView.Overlays["PopupOverlay"];
                popupOverlay.Popups.Clear();
                popupOverlay.Popups.Add(popup);
                popupOverlay.Refresh();
            }
        }
        private void WpfMap_Loaded(object sender, RoutedEventArgs e)
        {
            wpfMap1.MapUnit = GeographyUnit.DecimalDegree;
            wpfMap1.CurrentExtent = new RectangleShape(-177.39584350585937, 83.113876342773437, -52.617362976074219, 14.550546646118164);

            ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(@"..\..\SampleData\Data\Countries02.shp");

            worldLayer.Open();
            Feature feature = worldLayer.QueryTools.GetFeatureById("135", new string[0]);
            areaBaseShape = (AreaBaseShape)feature.GetShape();
            worldLayer.Close();

            InMemoryFeatureLayer simplificationLayer = new InMemoryFeatureLayer();
            simplificationLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            simplificationLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
            simplificationLayer.InternalFeatures.Add(feature);

            LayerOverlay simplificationOverlay = new LayerOverlay();
            simplificationOverlay.TileType = TileType.SingleTile;
            simplificationOverlay.Layers.Add(new BackgroundLayer(new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean)));
            simplificationOverlay.Layers.Add("SimplificationLayer", simplificationLayer);
            wpfMap1.Overlays.Add("SimplificationOverlay", simplificationOverlay);

            cmbSimplificationType.SelectedIndex = 0;
            cmbTolerance.SelectedIndex = 0;

            wpfMap1.Refresh();
        }
示例#3
0
        private void UseMapSimplification_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

            ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(Samples.RootDirectory + @"Data\Countries02.shp");

            worldLayer.Open();
            Feature feature = worldLayer.QueryTools.GetFeatureById("135", new string[0]);

            areaBaseShape = (AreaBaseShape)feature.GetShape();
            worldLayer.Close();

            InMemoryFeatureLayer simplificationLayer = new InMemoryFeatureLayer();

            simplificationLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            simplificationLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyles.Country1;
            simplificationLayer.InternalFeatures.Add(feature);

            LayerOverlay simplificationOverlay = new LayerOverlay();

            simplificationOverlay.Layers.Add("SimplificationLayer", simplificationLayer);
            winformsMap1.Overlays.Add("SimplificationOverlay", simplificationOverlay);

            winformsMap1.CurrentExtent = new RectangleShape(-177.39584350585937, 83.113876342773437, -52.617362976074219, 14.550546646118164);

            winformsMap1.Refresh();
        }
示例#4
0
        /// <summary>
        /// Unions all the features in the dividedCityLimits layer and displays the results on the map
        /// </summary>
        private void UnionShapes_OnClick(object sender, EventArgs e)
        {
            LayerOverlay layerOverlay = (LayerOverlay)mapView.Overlays["layerOverlay"];

            ShapeFileFeatureLayer dividedCityLimits = (ShapeFileFeatureLayer)layerOverlay.Layers["dividedCityLimits"];
            InMemoryFeatureLayer  unionLayer        = (InMemoryFeatureLayer)layerOverlay.Layers["unionLayer"];

            // Query the dividedCityLimits layer to get all the features
            dividedCityLimits.Open();
            var features = dividedCityLimits.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns);

            dividedCityLimits.Close();

            // Union all the features into a single Multipolygon Shape
            var union = AreaBaseShape.Union(features);

            // Add the union shape into unionLayer to display the result.
            // If this were to be a permanent change to the dividedCityLimits FeatureSource, you would modify the underlying data using BeginTransaction and CommitTransaction instead.
            unionLayer.InternalFeatures.Clear();
            unionLayer.InternalFeatures.Add(new Feature(union));

            // Hide the dividedCityLimits layer
            dividedCityLimits.IsVisible = false;

            // Redraw the layerOverlay to see the unioned features on the map
            layerOverlay.Refresh();
        }
        private void MapView_Loaded(object sender, RoutedEventArgs e)
        {
            mapView.MapUnit       = GeographyUnit.DecimalDegree;
            mapView.CurrentExtent = new RectangleShape(-177.39584350585937, 83.113876342773437, -52.617362976074219, 14.550546646118164);

            ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(SampleHelper.Get("Countries02_3857.shp"));

            worldLayer.Open();
            ProjectionConverter project = new ProjectionConverter(3857, 4326);

            project.Open();
            Feature feature = project.ConvertToExternalProjection(worldLayer.QueryTools.GetFeatureById("135", new string[0]));

            project.Close();
            areaBaseShape = (AreaBaseShape)feature.GetShape();
            worldLayer.Close();

            InMemoryFeatureLayer simplificationLayer = new InMemoryFeatureLayer();

            simplificationLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            simplificationLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = AreaStyle.CreateSimpleAreaStyle(GeoColor.FromArgb(255, 233, 232, 214), GeoColor.FromArgb(255, 118, 138, 69));
            simplificationLayer.InternalFeatures.Add(feature);

            LayerOverlay simplificationOverlay = new LayerOverlay();

            simplificationOverlay.TileType = TileType.SingleTile;
            simplificationOverlay.Layers.Add(new BackgroundLayer(new GeoSolidBrush(GeoColors.DeepOcean)));
            simplificationOverlay.Layers.Add("SimplificationLayer", simplificationLayer);
            mapView.Overlays.Add("SimplificationOverlay", simplificationOverlay);

            cmbSimplificationType.SelectedIndex = 0;
            cmbTolerance.SelectedIndex          = 0;
            mapView.Refresh();
        }
示例#6
0
        /// <summary>
        /// Scales the first feature in the cityLimits layer and displays the result on the map.
        /// </summary>
        private void ScaleShape_OnClick(object sender, EventArgs e)
        {
            LayerOverlay layerOverlay = (LayerOverlay)mapView.Overlays["layerOverlay"];

            ShapeFileFeatureLayer cityLimits  = (ShapeFileFeatureLayer)layerOverlay.Layers["cityLimits"];
            InMemoryFeatureLayer  scaledLayer = (InMemoryFeatureLayer)layerOverlay.Layers["scaledLayer"];

            // Query the cityLimits layer to get all the features
            cityLimits.Open();
            var features = cityLimits.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns);

            cityLimits.Close();

            // Scale the first feature by the scaleFactor TextBox on the UI
            var scale = AreaBaseShape.ScaleTo(features[0].GetShape(), Convert.ToSingle(scaleFactor.Text));

            // Add the scaled shape into scaledLayer to display the result.
            // If this were to be a permanent change to the cityLimits FeatureSource, you would modify the
            // underlying data using BeginTransaction and CommitTransaction instead.
            scaledLayer.InternalFeatures.Clear();
            scaledLayer.InternalFeatures.Add(new Feature(scale));

            // Redraw the layerOverlay to see the scaled feature on the map
            layerOverlay.Refresh();
        }
示例#7
0
        private void degreeTranslateShape_Click(object sender, EventArgs e)
        {
            LayerOverlay layerOverlay = (LayerOverlay)mapView.Overlays["layerOverlay"];

            ShapeFileFeatureLayer cityLimits      = (ShapeFileFeatureLayer)layerOverlay.Layers["cityLimits"];
            InMemoryFeatureLayer  translatedLayer = (InMemoryFeatureLayer)layerOverlay.Layers["translatedLayer"];

            // Query the cityLimits layer to get all the features
            cityLimits.Open();
            var features = cityLimits.QueryTools.GetAllFeatures(ReturningColumnsType.NoColumns);

            cityLimits.Close();

            // Translate the first feature's shape by the X and Y values on the UI in meters
            var translate = AreaBaseShape.TranslateByDegree(features[0].GetShape(), Convert.ToDouble(translateDistance.Text), Convert.ToDouble(translateAngle.Text), GeographyUnit.Meter, DistanceUnit.Meter);

            // Add the translated shape into translatedLayer to display the result.
            // If this were to be a permanent change to the cityLimits FeatureSource, you would modify the
            // underlying data using BeginTransaction and CommitTransaction instead.
            translatedLayer.InternalFeatures.Clear();
            translatedLayer.InternalFeatures.Add(new Feature(translate));

            // Redraw the layerOverlay to see the translated feature on the map
            layerOverlay.Refresh();
        }
示例#8
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"]);
        }
示例#9
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);
        }
        public static MultilineShape GetDifference(this LineShape masterLine, AreaBaseShape clippingArea)
        {
            MultilineShape resultMultiLineShape = new MultilineShape();
            var            masterGeoLine        = SqlGeometry.STGeomFromWKB(new SqlBytes(masterLine.GetWellKnownBinary()), 0);
            var            clippingGeoArea      = SqlGeometry.STGeomFromWKB(new SqlBytes(clippingArea.GetWellKnownBinary()), 0);
            var            resultWkb            = masterGeoLine.STSymDifference(clippingGeoArea).MakeValid().STAsBinary().Value;
            var            resultFeature        = new Feature(resultWkb);
            var            resultShape          = resultFeature.GetShape();

            if (resultShape is GeometryCollectionShape)
            {
                foreach (var line in ((GeometryCollectionShape)resultFeature.GetShape()).Shapes.OfType <LineShape>())
                {
                    resultMultiLineShape.Lines.Add(line);
                }
            }
            else if (resultShape is MultilineShape)
            {
                foreach (var item in ((MultilineShape)resultShape).Lines)
                {
                    resultMultiLineShape.Lines.Add(item);
                }
            }
            else if (resultShape is LineShape)
            {
                resultMultiLineShape.Lines.Add((LineShape)resultShape);
            }

            return(resultMultiLineShape);
        }
        private void btnUnion_Click(object sender, EventArgs e)
        {
            InMemoryFeatureLayer inMemoryLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("InMemoryFeatureLayer");

            if (inMemoryLayer.InternalFeatures.Count > 1)
            {
                GeoCollection <AreaBaseShape> areaBaseShapes = new GeoCollection <AreaBaseShape>();

                GeoCollection <Feature> features = inMemoryLayer.InternalFeatures;
                foreach (Feature feature in features)
                {
                    AreaBaseShape targetAreaBaseShape = feature.GetShape() as AreaBaseShape;
                    if (targetAreaBaseShape != null)
                    {
                        areaBaseShapes.Add(targetAreaBaseShape);
                    }
                }

                AreaBaseShape unionedAreaBaseShape = AreaBaseShape.Union(areaBaseShapes);
                unionedAreaBaseShape.Id = "UnionedFeature";
                inMemoryLayer.InternalFeatures.Clear();
                inMemoryLayer.InternalFeatures.Add("UnionedFeature", new Feature(unionedAreaBaseShape));
                inMemoryLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.SimpleColors.Green);

                winformsMap1.Refresh(winformsMap1.Overlays["InMemoryOverlay"]);
            }
        }
示例#12
0
        private static IEnumerable <PolygonShape> ToPolygons(this AreaBaseShape area)
        {
            Collection <PolygonShape> results = null;

            PolygonShape      polygon           = area as PolygonShape;
            MultipolygonShape multipolygonShape = area as MultipolygonShape;

            if (polygon != null)
            {
                results = new Collection <PolygonShape> {
                    polygon
                };
            }
            else if (multipolygonShape != null)
            {
                results = multipolygonShape.Polygons;
            }
            else
            {
                var polygonShape = area.GetType().GetMethod("ToPolygon").Invoke(null, null) as PolygonShape;
                results = new Collection <PolygonShape> {
                    polygonShape
                };
            }

            return(results);
        }
示例#13
0
        private void AndroidMap_MapSingleTap(object sender, Android.Views.MotionEvent e)
        {
            PointF     location = new PointF(e.GetX(), e.GetY());
            PointShape position = ExtentHelper.ToWorldCoordinate(androidMap.CurrentExtent, location.X,
                                                                 location.Y, androidMap.Width, androidMap.Height);

            LayerOverlay worldOverlay = (LayerOverlay)androidMap.Overlays["WorldOverlay"];
            FeatureLayer worldLayer   = (FeatureLayer)worldOverlay.Layers["WorldLayer"];

            LayerOverlay         highlightOverlay = (LayerOverlay)androidMap.Overlays["HighlightOverlay"];
            InMemoryFeatureLayer highlightLayer   = (InMemoryFeatureLayer)highlightOverlay.Layers["HighlightLayer"];

            worldLayer.Open();
            Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(position, new string[1] {
                "CNTRY_NAME"
            });

            worldLayer.Close();

            highlightLayer.Open();
            highlightLayer.InternalFeatures.Clear();
            if (selectedFeatures.Count > 0)
            {
                AreaBaseShape areaShape = (AreaBaseShape)selectedFeatures[0].GetShape();
                double        area      = areaShape.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareKilometers);
                messageTextView.Text = string.Format(CultureInfo.InvariantCulture, "{0} has an area of {1:N0} square kilometers.", selectedFeatures[0].ColumnValues["CNTRY_NAME"].Trim(), area);

                highlightLayer.InternalFeatures.Add(selectedFeatures[0]);
            }
            highlightLayer.Close();
            highlightOverlay.Refresh();
        }
示例#14
0
        public void SimplifyClick(Map map, GeoCollection <object> args)
        {
            if (null == areaBaseShape)
            {
                areaBaseShape = ((InMemoryFeatureLayer)map.StaticOverlay.Layers["SimplificationLayer"]).InternalFeatures[0].GetShape() as AreaBaseShape;
            }
            string toleranceString                   = args[0] as string;
            string simplificationTypeString          = args[1] as string;
            InMemoryFeatureLayer simplificationLayer = (InMemoryFeatureLayer)map.StaticOverlay.Layers["SimplificationLayer"];

            double             tolerance          = Convert.ToDouble(toleranceString, CultureInfo.InvariantCulture);
            SimplificationType simplificationType = SimplificationType.DouglasPeucker;

            switch (simplificationTypeString)
            {
            case "TopologyPreserving":
                simplificationType = SimplificationType.TopologyPreserving;
                break;

            case "DouglasPeucker":
                simplificationType = SimplificationType.DouglasPeucker;
                break;
            }

            MultipolygonShape multipolygonShape = areaBaseShape.Simplify(tolerance, simplificationType);

            simplificationLayer.InternalFeatures.Clear();
            simplificationLayer.InternalFeatures.Add(new Feature(multipolygonShape));
        }
示例#15
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);
        }
示例#16
0
        private void btnBuffer_Click(object sender, EventArgs e)
        {
            InMemoryFeatureLayer inMemoryLayer = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("InMemoryFeatureLayer");
            InMemoryFeatureLayer bufferLayer   = (InMemoryFeatureLayer)winformsMap1.FindFeatureLayer("BufferLayer");

            AreaBaseShape     baseShape     = (AreaBaseShape)inMemoryLayer.InternalFeatures["POLYGON"].GetShape();
            MultipolygonShape bufferedShape = baseShape.Buffer(100, 8, BufferCapType.Butt, GeographyUnit.DecimalDegree, DistanceUnit.Kilometer);
            Feature           bufferFeature = new Feature(bufferedShape.GetWellKnownBinary(), "Buffer1");

            bufferLayer.InternalFeatures.Clear();
            bufferLayer.InternalFeatures.Add("BufferFeature", bufferFeature);

            winformsMap1.Refresh(winformsMap1.Overlays["BufferOverlay"]);
        }
示例#17
0
        private void MouseMoved(object sender, MouseMovedTrackInteractiveOverlayEventArgs e)
        {
            //Gets the shape as it is being tracked and gets its properties to be displayed in labels og groupbox
            AreaBaseShape areaBaseShape = (AreaBaseShape)winformsMap1.TrackOverlay.TrackShapeLayer.InternalFeatures[0].GetShape();
            double        Perimeter     = Math.Round(areaBaseShape.GetPerimeter(winformsMap1.MapUnit, DistanceUnit.Kilometer));
            double        Area          = Math.Round(areaBaseShape.GetArea(winformsMap1.MapUnit, AreaUnit.SquareKilometers));

            lblPerimeter.Text = String.Format("{0:0,0}", Perimeter) + " km";
            lblArea.Text      = String.Format("{0:0,0}", Area) + " km2";

            //Sets the location (in screen coordinates) of the groupbox according to last moved vertex of the tracked shape (in world coordinates).
            ScreenPointF screenPointF = ThinkGeo.MapSuite.Core.ExtentHelper.ToScreenCoordinate(winformsMap1.CurrentExtent, e.MovedVertex.X, e.MovedVertex.Y, winformsMap1.Width, winformsMap1.Height);

            groupBoxInfo.Location = new Point((int)screenPointF.X + 30, (int)screenPointF.Y + 10);
        }
示例#18
0
        public void BufferFeature(Map map, GeoCollection <object> args)
        {
            if (null != map)
            {
                InMemoryFeatureLayer mapShapeLayer = (InMemoryFeatureLayer)((LayerOverlay)(map.CustomOverlays["BufferLayerOverLayer"])).Layers["InMemoryFeatureLayer"];
                InMemoryFeatureLayer bufferLayer   = (InMemoryFeatureLayer)((LayerOverlay)(map.CustomOverlays["BufferLayerOverLayer"])).Layers["BufferLayer"];

                AreaBaseShape     baseShape     = (AreaBaseShape)mapShapeLayer.InternalFeatures["POLYGON"].GetShape();
                MultipolygonShape bufferedShape = baseShape.Buffer(1000, 8, BufferCapType.Round, GeographyUnit.DecimalDegree, DistanceUnit.Kilometer);
                Feature           bufferFeature = new Feature(bufferedShape);

                bufferLayer.InternalFeatures.Clear();
                bufferLayer.InternalFeatures.Add("BufferFeature", bufferFeature);
                ((LayerOverlay)(map.CustomOverlays["BufferLayerOverLayer"])).Redraw();
            }
        }
示例#19
0
        private void BufferButtonClick(object sender, System.EventArgs e)
        {
            LayerOverlay bufferOverLay = (LayerOverlay)androidMap.Overlays["BufferOverlay"];

            InMemoryFeatureLayer inMemoryLayer = (InMemoryFeatureLayer)bufferOverLay.Layers["InMemoryFeatureLayer"];
            InMemoryFeatureLayer bufferLayer   = (InMemoryFeatureLayer)bufferOverLay.Layers["BufferLayer"];

            AreaBaseShape     baseShape     = (AreaBaseShape)inMemoryLayer.InternalFeatures["POLYGON"].GetShape();
            MultipolygonShape bufferedShape = baseShape.Buffer(100, 8, BufferCapType.Butt, GeographyUnit.DecimalDegree, DistanceUnit.Kilometer);
            Feature           bufferFeature = new Feature(bufferedShape.GetWellKnownBinary(), "Buffer1");

            bufferLayer.InternalFeatures.Clear();
            bufferLayer.InternalFeatures.Add("BufferFeature", bufferFeature);

            androidMap.Overlays["BufferOverlay"].Refresh();
        }
        public static Collection <AreaBaseShape> GetSplitResult(this AreaBaseShape polygon, Collection <LineShape> lines)
        {
            SqlGeometry polygonGeom = SqlGeometry.STGeomFromWKB(new SqlBytes(polygon.GetWellKnownBinary()), 0);

            if (!polygonGeom.STIsValid())
            {
                polygonGeom = polygonGeom.MakeValid();
            }
            //GeometryLibrary library = BaseShape.GeometryLibrary;
            //BaseShape.GeometryLibrary = GeometryLibrary.Unmanaged;
            foreach (var item in lines)
            {
                //MultipolygonShape multipolygon = item.Buffer(0.2, 8, BufferCapType.Square, GeographyUnit.DecimalDegree, DistanceUnit.Meter);
                MultipolygonShape multipolygon     = SqlTypesGeometryHelper.Buffer(item, 0.2, 8, BufferCapType.Square, GeographyUnit.DecimalDegree, DistanceUnit.Meter);
                SqlGeometry       multipolygonGeom = SqlGeometry.STGeomFromWKB(new SqlBytes(multipolygon.GetWellKnownBinary()), 0);
                if (!multipolygonGeom.STIsValid())
                {
                    multipolygonGeom = multipolygonGeom.MakeValid();
                }

                polygonGeom = polygonGeom.STDifference(multipolygonGeom);
            }

            //BaseShape.GeometryLibrary = library;

            byte[]    bytes = polygonGeom.STAsBinary().Value;
            BaseShape shape = BaseShape.CreateShapeFromWellKnownData(bytes) as AreaBaseShape;

            MultipolygonShape splittedMultipolygonShape = shape as MultipolygonShape;
            PolygonShape      splittedPolygonShape      = shape as PolygonShape;

            if (splittedMultipolygonShape == null && splittedPolygonShape != null)
            {
                splittedMultipolygonShape = new MultipolygonShape();
                splittedMultipolygonShape.Polygons.Add(splittedPolygonShape);
                shape = splittedMultipolygonShape;
            }

            Collection <AreaBaseShape> shapes = new Collection <AreaBaseShape>();

            if (splittedMultipolygonShape != null)
            {
                CloseSplittedPolygons(polygon, splittedMultipolygonShape, lines[0], GeographyUnit.DecimalDegree, DistanceUnit.Meter, .3);
                FillShapes(shapes, shape);
            }
            return(shapes);
        }
        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();
            }
        }
        public static void CloseSplittedPolygons(AreaBaseShape sourcePolygon, MultipolygonShape splitedPolygon, LineShape splitLine, GeographyUnit mapUnit, DistanceUnit distanceUnit, double distance)
        {
            var multiline = splitLine.GetIntersection(sourcePolygon);

            foreach (var vertex in multiline.Lines.SelectMany(l => l.Vertices))
            {
                var closeArea = new PointShape(vertex).Buffer(distance, mapUnit, distanceUnit).GetBoundingBox();
                foreach (var polygon in splitedPolygon.Polygons)
                {
                    CloseSplittedRing(vertex, closeArea, polygon.OuterRing);
                    foreach (var ring in polygon.InnerRings)
                    {
                        CloseSplittedRing(vertex, closeArea, ring);
                    }
                }
            }
        }
        private 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;
                    ReportProgress(progress);
                    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))
                            {
                                AreaBaseShape resultShape = originalShape.GetIntersection(matchShape);
                                if (resultShape != null)
                                {
                                    var columnValues      = GetColumnValues(feature, otherFeature);
                                    Feature resultFeature = new Feature(resultShape, columnValues);
                                    results.Push(resultFeature);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    });
                    index++;
                }
            }

            return(results);
        }
        private void AreaResizeMenuItem_Click(object sender, RoutedEventArgs e)
        {
            MenuItem         item      = (MenuItem)sender;
            Feature          feature   = (Feature)item.Tag;
            AreaBaseShape    areaShape = (AreaBaseShape)feature.GetShape();
            AreaResizeWindow window    = new AreaResizeWindow(areaShape);

            window.Owner = Application.Current.MainWindow;
            window.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            if (window.ShowDialog().GetValueOrDefault())
            {
                double orignalAcreage = window.OriginalAcreage;
                double acreage        = window.ResultAcreage;

                double difference = 1;

                while (difference > 0.05)
                {
                    if (acreage > orignalAcreage)
                    {
                        double percentage = (Math.Sqrt(acreage) / Math.Sqrt(orignalAcreage) * 100) % 100;
                        areaShape.ScaleUp(percentage);
                    }
                    else if (acreage == orignalAcreage)
                    {
                    }
                    else
                    {
                        double percentage = (Math.Sqrt(orignalAcreage) / Math.Sqrt(acreage) * 100) % 100;
                        areaShape.ScaleDown(percentage);
                    }
                    orignalAcreage = areaShape.GetArea(GisEditor.ActiveMap.MapUnit, AreaResizeWindow.DefaultAreaUnit);
                    difference     = Math.Abs(orignalAcreage - acreage) / acreage;
                }

                Feature tempfeature = GisEditor.ActiveMap.FeatureLayerEditOverlay.EditShapesLayer.InternalFeatures.FirstOrDefault(f => f.Id.Equals(feature.Id));
                if (tempfeature != null)
                {
                    GisEditor.ActiveMap.FeatureLayerEditOverlay.EditShapesLayer.InternalFeatures.Remove(tempfeature);
                    GisEditor.ActiveMap.FeatureLayerEditOverlay.EditShapesLayer.InternalFeatures.Add(tempfeature.Id, new Feature(areaShape, tempfeature.ColumnValues));
                    GisEditor.ActiveMap.FeatureLayerEditOverlay.TakeSnapshot();
                    GisEditor.ActiveMap.FeatureLayerEditOverlay.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();
            }
        }
示例#26
0
        public static Feature UnionAreaFeatures(IEnumerable <Feature> features)
        {
            Collection <Feature> tempFeatuers = new Collection <Feature>();

            foreach (var item in features)
            {
                if (!SqlTypesGeometryHelper.IsValid(item))
                {
                    tempFeatuers.Add(SqlTypesGeometryHelper.MakeValid(item));
                }
                else
                {
                    tempFeatuers.Add(item);
                }
            }

            var unionresult = AreaBaseShape.Union(tempFeatuers);

            return(new Feature(unionresult));
        }
        private void winformsMap1_MapClick(object sender, MapClickWinformsMapEventArgs e)
        {
            FeatureLayer worldLayer = winformsMap1.FindFeatureLayer("WorldLayer");

            // Find the country the user clicked on.
            worldLayer.Open();
            Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(e.WorldLocation, new string[1] {
                "CNTRY_NAME"
            });

            worldLayer.Close();

            // Determine the area of the country.
            if (selectedFeatures.Count > 0)
            {
                AreaBaseShape areaShape = (AreaBaseShape)selectedFeatures[0].GetShape();
                double        area      = areaShape.GetArea(GeographyUnit.DecimalDegree, AreaUnit.SquareKilometers);
                MessageBox.Show(string.Format(CultureInfo.InvariantCulture, "{0} has an area of {1:N0} square kilometers.", selectedFeatures[0].ColumnValues["CNTRY_NAME"].Trim(), area), "Area", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0);
            }
        }
示例#28
0
        public void ClickOnFeature(Map map, GeoCollection <object> args)
        {
            PointShape point = new PointShape(Convert.ToDouble(args[0]), Convert.ToDouble(args[1]));

            ShapeFileFeatureLayer worldLayer       = (ShapeFileFeatureLayer)((LayerOverlay)map.CustomOverlays[1]).Layers["WorldLayer"];
            InMemoryFeatureLayer  boundingBoxLayer = (InMemoryFeatureLayer)((LayerOverlay)map.CustomOverlays[2]).Layers["BoundingBoxLayer"];

            boundingBoxLayer.InternalFeatures.Clear();

            worldLayer.Open();
            Collection <Feature> selectedFeatures = worldLayer.QueryTools.GetFeaturesContaining(point, new string[0]);

            worldLayer.Close();

            if (selectedFeatures.Count > 0)
            {
                AreaBaseShape areaShape = (AreaBaseShape)selectedFeatures[0].GetShape();
                boundingBoxLayer.InternalFeatures.Add("BoundingBox", new Feature(areaShape.GetBoundingBox()));
            }
            ((LayerOverlay)map.CustomOverlays[2]).Redraw();
        }
示例#29
0
        /// <summary>
        /// Setup the map with the ThinkGeo Cloud Maps overlay to show a basic map
        /// </summary>
        protected override void OnAppearing()
        {
            base.OnAppearing();

            // It is important to set the map unit first to either feet, meters or decimal degrees.
            mapView.MapUnit = GeographyUnit.DecimalDegree;

            // Create the background world maps using vector tiles requested from the ThinkGeo Cloud Service and add it to the map.
            ThinkGeoCloudVectorMapsOverlay thinkGeoCloudVectorMapsOverlay = new ThinkGeoCloudVectorMapsOverlay("itZGOI8oafZwmtxP-XGiMvfWJPPc-dX35DmESmLlQIU~", "bcaCzPpmOG6le2pUz5EAaEKYI-KSMny_WxEAe7gMNQgGeN9sqL12OA~~", ThinkGeoCloudVectorMapsMapType.Light);

            mapView.Overlays.Add(thinkGeoCloudVectorMapsOverlay);

            // Creating a rectangle area we will use to generate the polygons and also start the map there.
            RectangleShape currentExtent = new RectangleShape(-10810995.245624, 3939081.90719325, -10747552.5124997, 3884429.43227297);

            //Do all the things we need to setup the polygon layer and overlay such as creating all the polygons etc.
            AddPolygonOverlay(AreaBaseShape.ScaleDown(currentExtent.GetBoundingBox(), 80).GetBoundingBox());

            //Set the maps current extent so we start there
            mapView.CurrentExtent = currentExtent;
        }
示例#30
0
        public void DifferenceFeature(Map map, GeoCollection <object> args)
        {
            if (null != map)
            {
                InMemoryFeatureLayer mapShapeLayer = (InMemoryFeatureLayer)((LayerOverlay)map.CustomOverlays["OverLayer"]).Layers["InMemoryFeatureLayer"];

                if (mapShapeLayer.InternalFeatures.Count > 1)
                {
                    AreaBaseShape targetShape = (AreaBaseShape)mapShapeLayer.InternalFeatures["AreaShape1"].GetShape();

                    mapShapeLayer.Open();
                    mapShapeLayer.EditTools.BeginTransaction();
                    mapShapeLayer.EditTools.GetDifference("AreaShape2", targetShape);
                    mapShapeLayer.EditTools.Delete("AreaShape1");
                    mapShapeLayer.EditTools.CommitTransaction();
                    mapShapeLayer.Close();
                    mapShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(100, GeoColor.StandardColors.Blue);
                }
                ((LayerOverlay)map.CustomOverlays["OverLayer"]).Redraw();
            }
        }
        public AreaResizeWindow(AreaBaseShape areaShape)
        {
            InitializeComponent();

            this.areaShape = areaShape;

            distanceUnits = new Collection <AreaUnit>();
            double acreage = areaShape.GetArea(GisEditor.ActiveMap.MapUnit, defaultAreaUnit);

            origalAcreageTb.Text = acreage.ToString();
            targetAcreageTb.Text = acreage.ToString();
            tempAcreage          = targetAcreageTb.Text;

            foreach (AreaUnit item in Enum.GetValues(typeof(AreaUnit)))
            {
                distanceUnits.Add(item);
            }

            cmxDistanceUnit.ItemsSource  = distanceUnits;
            cmxDistanceUnit.SelectedItem = defaultAreaUnit;
        }