Exemplo n.º 1
0
        private void ZoomToFilterMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            MenuItem      menuItem      = (MenuItem)sender;
            LayerListItem layerListItem = (LayerListItem)menuItem.Tag;
            LayerListItem tempItem      = layerListItem;

            while (!(tempItem.ConcreteObject is FeatureLayer))
            {
                tempItem = tempItem.Parent;
            }
            FeatureLayer selectedLayer = tempItem.ConcreteObject as FeatureLayer;

            if (selectedLayer != null)
            {
                Collection <Feature> resultFeatures = new Collection <Feature>();
                selectedLayer.SafeProcess(() =>
                {
                    resultFeatures = selectedLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns);
                });

                FilterStyle filterStyle = (FilterStyle)layerListItem.ConcreteObject;
                foreach (var condition in filterStyle.Conditions)
                {
                    resultFeatures = condition.GetMatchingFeatures(resultFeatures);
                }
                if (resultFeatures.Count > 0)
                {
                    RectangleShape boundingBox = ExtentHelper.GetBoundingBoxOfItems(resultFeatures);
                    GisEditor.ActiveMap.CurrentExtent = boundingBox;
                    GisEditor.ActiveMap.Refresh();
                }
            }
        }
Exemplo n.º 2
0
        private static void ZoomToExtent()
        {
            RectangleShape resultExtent = null;

            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }
            if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Overlay && GisEditor.LayerListManager.SelectedLayerListItems.Count > 0)
            {
                Collection <RectangleShape> extents = new Collection <RectangleShape>();
                foreach (var item in GisEditor.LayerListManager.SelectedLayerListItems)
                {
                    var tmpOverlay = item.ConcreteObject as Overlay;
                    if (tmpOverlay != null)
                    {
                        extents.Add(tmpOverlay.GetBoundingBox());
                    }
                }
                resultExtent = ExtentHelper.GetBoundingBoxOfItems(extents);
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItems.Count > 0)
            {
                Collection <RectangleShape> extents = new Collection <RectangleShape>();
                foreach (var item in GisEditor.LayerListManager.SelectedLayerListItems)
                {
                    Layer tmpLayer = item.ConcreteObject as Layer;
                    if (tmpLayer != null && tmpLayer.HasBoundingBox)
                    {
                        tmpLayer.SafeProcess(() =>
                        {
                            extents.Add(tmpLayer.GetBoundingBox());
                        });
                    }
                }
                resultExtent = ExtentHelper.GetBoundingBoxOfItems(extents);
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Overlay)
            {
                resultExtent = (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Overlay).GetBoundingBox();
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Layer)
            {
                Layer layer = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Layer;
                if (layer.HasBoundingBox)
                {
                    layer.SafeProcess(() =>
                    {
                        resultExtent = layer.GetBoundingBox();
                    });
                }
            }

            if (resultExtent != null)
            {
                GisEditor.ActiveMap.CurrentExtent = resultExtent;
                GisEditor.ActiveMap.Refresh();
            }
        }
        private void operationImage_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
        {
            Point  mousePoint                = e.GetPosition(operationImage);
            double panPanelRadius            = panIconSize * .5;
            double globeRadius               = globeIconSize * .5;
            Point  center                    = new Point(panPanelRadius, panPanelRadius);
            double distanceFromMouseToCenter = Math.Sqrt(Math.Pow(mousePoint.X - center.X, 2) + Math.Pow(mousePoint.Y - center.Y, 2));

            if (distanceFromMouseToCenter <= globeRadius)
            {
                // zoom to whole world.
                if (CurrentMap != null && isGlobeButtonEnabled)
                {
                    Collection <BaseShape> rectangles = new Collection <BaseShape>();
                    foreach (Overlay overlay in CurrentMap.Overlays)
                    {
                        RectangleShape rect = overlay.GetBoundingBox();
                        if (rect != null)
                        {
                            rectangles.Add(rect);
                        }
                    }

                    if (rectangles.Count != 0)
                    {
                        RectangleShape targetExtent = OnGlobeButtonClick(ExtentHelper.GetBoundingBoxOfItems(rectangles));
                        if (targetExtent != null)
                        {
                            CurrentMap.CurrentExtent = targetExtent;
                            CurrentMap.Refresh();
                        }
                    }
                }
                e.Handled = true;
            }
            else if (distanceFromMouseToCenter <= panPanelRadius)
            {
                // change switcher mode.
                double degree = GetDegree(mousePoint.X - center.X, center.Y - mousePoint.Y);
                if ((degree >= 0 && degree < 90) || (degree <= 0 && degree >= -30))
                {
                    isSwitchedByMouse = true;
                    SwitcherMode      = SwitcherMode.TrackZoom;
                }
                else if ((degree >= 90 && degree <= 180) || (degree < -150 && degree >= -180))
                {
                    isSwitchedByMouse = true;
                    SwitcherMode      = SwitcherMode.Pan;
                }
                else
                {
                    isSwitchedByMouse = true;
                    SwitcherMode      = SwitcherMode.Identify;
                }

                e.Handled = true;
            }
        }
        private static void ShowOptionsIfNoSelectedFeatureInCurrentExtent(Collection <Feature> features)
        {
            MessageBoxResult result = MessageBox.Show(string.Format(GisEditor.LanguageManager.GetStringResource("GoogleEarthAnyFeaturesSelected")), GisEditor.LanguageManager.GetStringResource("GeneralMessageBoxInfoCaption"), MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                GisEditor.ActiveMap.CurrentExtent = ExtentHelper.GetBoundingBoxOfItems(features);
                GisEditor.ActiveMap.Refresh();
            }
        }
Exemplo n.º 5
0
        protected override RectangleShape GetBoundingBoxCore()
        {
            Collection <RectangleShape> boundingBoxs = new Collection <RectangleShape>();

            foreach (var rasterLayer in rasterLayers)
            {
                rasterLayer.Open();
                boundingBoxs.Add(rasterLayer.GetBoundingBox());
            }

            return(ExtentHelper.GetBoundingBoxOfItems(boundingBoxs));
        }
        private void ZoomToDataMenuItem_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            MenuItem      menuItem      = (MenuItem)sender;
            LayerListItem layerListItem = (LayerListItem)menuItem.Tag;
            LayerListItem tempItem      = layerListItem;

            while (!(tempItem.ConcreteObject is FeatureLayer))
            {
                tempItem = tempItem.Parent;
            }

            FeatureLayer selectedLayer = tempItem.ConcreteObject as FeatureLayer;

            if (selectedLayer != null)
            {
                selectedLayer.Open();
                RectangleShape      bbox    = selectedLayer.GetBoundingBox();
                Collection <string> filters = ((Styles.Style)layerListItem.ConcreteObject).Filters;

                Collection <string> returningColumnNames = ((Styles.Style)layerListItem.ConcreteObject).GetRequiredColumnNames();
                returningColumnNames = GetRequiredColumnNamesForLink(returningColumnNames, selectedLayer.FeatureSource);

//                IEnumerable<string> allColumns = selectedLayer.FeatureSource.GetColumns().Select(c => c.ColumnName);
//                Collection<Feature> allDataFeatures = selectedLayer.FeatureSource.GetFeaturesForDrawing(bbox, GisEditor.ActiveMap.Width,
//GisEditor.ActiveMap.Height, allColumns, filters);

                Collection <Feature> features = selectedLayer.FeatureSource.GetFeaturesForDrawing(bbox, GisEditor.ActiveMap.Width,
                                                                                                  GisEditor.ActiveMap.Height, returningColumnNames);

                //List<string> linkSourceNameStarts = GetLinkSourceNameStarts(selectedLayer.FeatureSource.LinkSources);
                //if (filters != null && filters.Count() > 0 && CheckHasLinkColumns(returningColumnNames, filters, linkSourceNameStarts))
                //{
                //    List<Feature> resultFeatureList = features.Where(f => CheckIsValidLinkFeature(f, linkSourceNameStarts)).ToList();
                //    features = new Collection<Feature>(resultFeatureList);
                //}

                Collection <Feature> resultFeatures = features;//new Collection<Feature>(allDataFeatures.Where(f => features.Any(t => t.Id.Equals(f.Id))).ToList());

                if (resultFeatures.Count > 0)
                {
                    RectangleShape boundingBox = ExtentHelper.GetBoundingBoxOfItems(resultFeatures);
                    GisEditor.ActiveMap.CurrentExtent = boundingBox;
                    GisEditor.ActiveMap.Refresh();
                }
            }
        }
Exemplo n.º 7
0
        private void btnMultipleFeatures_Click(object sender, EventArgs e)
        {
            Collection <string> featureIDs = new Collection <string>();

            featureIDs.Add("63");  // For US
            featureIDs.Add("6");   // For Canada
            featureIDs.Add("137"); // For Mexico

            FeatureLayer worldLayer = winformsMap1.FindFeatureLayer("WorldLayer");

            worldLayer.Open();
            Collection <Feature> features = worldLayer.FeatureSource.GetFeaturesByIds(featureIDs, new string[0]);

            worldLayer.Close();

            winformsMap1.CurrentExtent = ExtentHelper.GetBoundingBoxOfItems(features);

            winformsMap1.Refresh();
        }
Exemplo n.º 8
0
        private void MulitFeaturesButtonClick(object sender, EventArgs e)
        {
            Collection <string> featureIDs = new Collection <string>();

            featureIDs.Add("63");  // For US
            featureIDs.Add("6");   // For Canada
            featureIDs.Add("137"); // For Mexico

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

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

            lock (worldLayer)
            {
                if (!worldLayer.IsOpen)
                {
                    worldLayer.Open();
                }
                Collection <Feature> features = worldLayer.FeatureSource.GetFeaturesByIds(featureIDs, new string[0]);
                androidMap.CurrentExtent = ExtentHelper.GetBoundingBoxOfItems(features);

                highlightLayer.Open();
                highlightLayer.InternalFeatures.Clear();
                if (features.Count > 0)
                {
                    foreach (var feature in features)
                    {
                        highlightLayer.InternalFeatures.Add(feature);
                    }
                }
                highlightLayer.Close();
            }

            androidMap.Refresh();
        }
Exemplo n.º 9
0
        protected override RectangleShape GetBoundingBoxCore()
        {
            RectangleShape extent = ExtentHelper.GetBoundingBoxOfItems(ShapeLayer.MapShapes.Select(m => m.Value.Feature));

            return(extent);
        }
Exemplo n.º 10
0
        private void ZoomToFeatures(IEnumerable <Feature> features, FeatureLayer featureLayer)
        {
            RectangleShape extent        = features.Count() == 1 ? GetBoundingBox(features.FirstOrDefault()) : ExtentHelper.GetBoundingBoxOfItems(features);
            RectangleShape drawingExtent = ExtentHelper.GetDrawingExtent(extent, (float)GisEditor.ActiveMap.ActualWidth, (float)GisEditor.ActiveMap.ActualHeight);
            var            scale         = ExtentHelper.GetScale(drawingExtent, (float)map.ActualWidth, map.MapUnit);

            map.ZoomTo(extent.GetCenterPoint(), scale);
            //GisEditor.UIManager.RefreshPlugins(new RefreshArgs(extent.GetCenterPoint(), "Identify"));
            GisEditor.UIManager.RefreshPlugins(new RefreshArgs(new Tuple <IEnumerable <Feature>, FeatureLayer>(features, featureLayer), "Identify"));
        }
 protected override RectangleShape GetBoundingBoxCore()
 {
     return(ExtentHelper.GetBoundingBoxOfItems(TrackShapeLayer.InternalFeatures));
 }
Exemplo n.º 12
0
        private IEnumerable <Feature> StandardClip(FeatureLayer featureLayer, IEnumerable <Feature> features)
        {
            lock (featureLayer)
            {
                Collection <Feature> results = new Collection <Feature>();

                #region replace project to null

                bool isOpen = false;
                Proj4ProjectionInfo projectionInfo = featureLayer.GetProj4ProjectionInfo();
                if (projectionInfo != null && projectionInfo.CanProject)
                {
                    if (featureLayer.IsOpen)
                    {
                        featureLayer.Close();
                        projectionInfo.Close();
                        isOpen = true;
                    }
                    featureLayer.FeatureSource.Projection = null;
                }

                #endregion replace project to null

                Collection <Feature> tmpFeatures = new Collection <Feature>();
                if (projectionInfo != null && projectionInfo.CanProject)
                {
                    projectionInfo.Open();
                    foreach (var item in features)
                    {
                        tmpFeatures.Add(projectionInfo.ConvertToInternalProjection(item));
                    }
                    projectionInfo.Close();
                }
                else
                {
                    tmpFeatures = new Collection <Feature>(features.ToList());
                }

                if (!featureLayer.IsOpen)
                {
                    featureLayer.Open();
                }
                List <Feature> tmpSourceFeatures = featureLayer.FeatureSource.GetFeaturesInsideBoundingBox(ExtentHelper.GetBoundingBoxOfItems(tmpFeatures), featureLayer.GetDistinctColumnNames()).Select(f => f.MakeValidIfCan()).ToList();

                Collection <Feature> sourceFeatures = new Collection <Feature>(tmpSourceFeatures);
                if (projectionInfo != null)
                {
                    featureLayer.FeatureSource.Projection = projectionInfo.Projection;
                    if (isOpen)
                    {
                        featureLayer.Open();
                    }
                }

                SimpleShapeType simpleShapeType = SimpleShapeType.Unknown;
                var             shapeAdapter    = GisEditor.LayerManager.GetLayerPlugins(featureLayer.GetType()).FirstOrDefault() as FeatureLayerPlugin;
                if (shapeAdapter != null)
                {
                    simpleShapeType = shapeAdapter.GetFeatureSimpleShapeType(featureLayer);
                }
                if (featureLayer.IsOpen)
                {
                    featureLayer.Close();
                }

                int index = 1;
                int count = sourceFeatures.Count;
                if (simpleShapeType == SimpleShapeType.Point)
                {
                    return(StandardClipPoints(sourceFeatures, tmpFeatures));
                }
                else if (simpleShapeType == SimpleShapeType.Line)
                {
                    StandardClipLines(tmpFeatures, results, sourceFeatures, index, count);
                }
                else if (simpleShapeType == SimpleShapeType.Area)
                {
                    //MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(tmpFeatures));
                    List <AreaBaseShape> clippingAreaShapes = GetValidFeatures(tmpFeatures)
                                                              .Select(f => f.GetShape())
                                                              .OfType <AreaBaseShape>()
                                                              .ToList();

                    BaseShape         unionResultShape = SqlTypesGeometryHelper.Union(clippingAreaShapes);
                    MultipolygonShape areaBaseShape    = ConvertSqlQueryResultToMultiPolygonShape(unionResultShape);

                    foreach (var feature in sourceFeatures)
                    {
                        isCanceled = ReportProgress(index, count);
                        if (isCanceled)
                        {
                            break;
                        }

                        try
                        {
                            index++;
                            //if (areaBaseShape.Contains(feature))
                            if (SqlTypesGeometryHelper.Contains(areaBaseShape, feature))
                            {
                                results.Add(feature);
                            }
                            else
                            {
                                //var clippedShape = areaBaseShape.GetIntersection(feature);
                                AreaBaseShape targetAreaShape = feature.GetShape() as AreaBaseShape;
                                if (targetAreaShape != null)
                                {
                                    var clippedShape = SqlTypesGeometryHelper.GetIntersection(areaBaseShape, targetAreaShape) as MultipolygonShape;
                                    if (clippedShape != null && clippedShape.Polygons.Count > 0)
                                    {
                                        results.Add(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException("The ShapeFileType is not supported.");
                }

                Collection <Feature> convertedFeatures = new Collection <Feature>();
                if (projectionInfo != null && projectionInfo.CanProject)
                {
                    projectionInfo.Open();
                    foreach (var item in results)
                    {
                        convertedFeatures.Add(projectionInfo.ConvertToExternalProjection(item));
                    }
                    projectionInfo.Close();
                }
                else
                {
                    convertedFeatures = new Collection <Feature>(results.ToList());
                }

                return(convertedFeatures);
            }
        }
Exemplo n.º 13
0
        private IEnumerable <Feature> InverseClip(FeatureLayer featureLayer, IEnumerable <Feature> clippingFeatures)
        {
            lock (featureLayer)
            {
                if (!featureLayer.IsOpen)
                {
                    featureLayer.Open();
                }
                Collection <Feature> results         = featureLayer.FeatureSource.GetFeaturesOutsideBoundingBox(ExtentHelper.GetBoundingBoxOfItems(clippingFeatures), featureLayer.GetDistinctColumnNames());
                Collection <Feature> sourceFeatures  = new Collection <Feature>();
                SimpleShapeType      simpleShapeType = GisEditor.LayerManager.GetFeatureSimpleShapeType(featureLayer);
                int index = 1;
                if (simpleShapeType == SimpleShapeType.Point)
                {
                    featureLayer.Open();
                    Collection <Feature> allFeatures = featureLayer.FeatureSource.GetAllFeatures(featureLayer.GetDistinctColumnNames());
                    featureLayer.Close();
                    foreach (Feature f in results)
                    {
                        allFeatures.Remove(f);
                    }
                    foreach (var f in InverseClipPoints(allFeatures, clippingFeatures, simpleShapeType))
                    {
                        results.Add(f);
                    }
                }
                else if (simpleShapeType == SimpleShapeType.Line)
                {
                    bool isOpen = false;
                    Proj4ProjectionInfo projectionInfo = featureLayer.GetProj4ProjectionInfo();
                    //MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(clippingFeatures));
                    List <AreaBaseShape> clippingAreaShapes = GetValidFeatures(clippingFeatures)
                                                              .Select(f => f.GetShape())
                                                              .OfType <AreaBaseShape>()
                                                              .ToList();
                    MultipolygonShape areaBaseShape = AreaBaseShape.Union(clippingAreaShapes);

                    if (projectionInfo != null && projectionInfo.CanProject)
                    {
                        if (featureLayer.IsOpen)
                        {
                            featureLayer.Close();
                            projectionInfo.Close();
                            isOpen = true;
                        }
                        featureLayer.FeatureSource.Projection = null;
                    }
                    featureLayer.Open();
                    featureLayer.FeatureSource.GetFeaturesInsideBoundingBox(areaBaseShape.GetBoundingBox(), featureLayer.GetDistinctColumnNames()).ForEach(f => { if (!areaBaseShape.Contains(f))
                                                                                                                                                                  {
                                                                                                                                                                      sourceFeatures.Add(f);
                                                                                                                                                                  }
                                                                                                                                                           });
                    int count = sourceFeatures.Count;
                    if (projectionInfo != null)
                    {
                        featureLayer.FeatureSource.Projection = projectionInfo.Projection;
                        if (isOpen)
                        {
                            featureLayer.Open();
                        }
                    }
                    if (featureLayer.IsOpen)
                    {
                        featureLayer.Close();
                    }
                    foreach (var feature in sourceFeatures)
                    {
                        isCanceled = ReportProgress(index, count);
                        if (isCanceled)
                        {
                            break;
                        }

                        index++;
                        try
                        {
                            //if (areaBaseShape.IsDisjointed(feature))
                            if (SqlTypesGeometryHelper.IsDisjointed(areaBaseShape, feature))
                            {
                                results.Add(feature);
                            }
                            else
                            {
                                MultilineShape multiLine   = (MultilineShape)feature.GetShape();
                                MultilineShape resultShape = new MultilineShape();
                                foreach (LineShape lineShape in multiLine.Lines)
                                {
                                    //if (areaBaseShape.IsDisjointed(lineShape))
                                    if (SqlTypesGeometryHelper.IsDisjointed(areaBaseShape, lineShape))
                                    {
                                        resultShape.Lines.Add(lineShape);
                                    }
                                    else
                                    {
                                        var resultLine = lineShape.GetDifference(areaBaseShape);
                                        foreach (var line in resultLine.Lines)
                                        {
                                            resultShape.Lines.Add(line);
                                        }
                                    }
                                }
                                if (resultShape != null && resultShape.Lines.Count > 0)
                                {
                                    results.Add(new Feature(resultShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    }
                }
                else if (simpleShapeType == SimpleShapeType.Area)
                {
                    //MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(clippingFeatures));
                    List <AreaBaseShape> clippingAreaShapes = GetValidFeatures(clippingFeatures)
                                                              .Select(f => f.GetShape())
                                                              .OfType <AreaBaseShape>()
                                                              .ToList();

                    BaseShape         unionResultShape = SqlTypesGeometryHelper.Union(clippingAreaShapes);
                    MultipolygonShape areaBaseShape    = ConvertSqlQueryResultToMultiPolygonShape(unionResultShape);

                    bool isOpen = false;
                    Proj4ProjectionInfo projectionInfo = featureLayer.GetProj4ProjectionInfo();
                    if (projectionInfo != null && projectionInfo.CanProject)
                    {
                        if (featureLayer.IsOpen)
                        {
                            featureLayer.Close();
                            if (projectionInfo != null)
                            {
                                projectionInfo.Close();
                            }
                            isOpen = true;
                        }
                        featureLayer.FeatureSource.Projection = null;
                    }
                    if (!featureLayer.IsOpen)
                    {
                        featureLayer.Open();
                    }
                    featureLayer.FeatureSource.GetFeaturesInsideBoundingBox(areaBaseShape.GetBoundingBox(), featureLayer.GetDistinctColumnNames()).ForEach(f => sourceFeatures.Add(f));
                    if (featureLayer.IsOpen)
                    {
                        featureLayer.Close();
                    }
                    if (projectionInfo != null)
                    {
                        featureLayer.FeatureSource.Projection = projectionInfo.Projection;
                        if (isOpen)
                        {
                            featureLayer.Open();
                        }
                    }

                    int count = sourceFeatures.Count;
                    foreach (var feature in sourceFeatures)
                    {
                        isCanceled = ReportProgress(index, count);
                        if (isCanceled)
                        {
                            break;
                        }

                        index++;
                        try
                        {
                            //if (areaBaseShape.IsDisjointed(feature))
                            if (SqlTypesGeometryHelper.IsDisjointed(areaBaseShape, feature))
                            {
                                results.Add(feature);
                            }
                            else
                            {
                                //var clippedShape = ((AreaBaseShape)feature.GetShape()).GetDifference(areaBaseShape);
                                BaseShape         differenceResultShape = SqlTypesGeometryHelper.GetDifference((AreaBaseShape)feature.GetShape(), areaBaseShape);
                                MultipolygonShape clippedShape          = ConvertSqlQueryResultToMultiPolygonShape(differenceResultShape);
                                if (clippedShape != null && clippedShape.Polygons.Count > 0)
                                {
                                    results.Add(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException("The ShapeFileType is not supported.");
                }
                return(results);
            }
        }
        private static void ZoomToExtent()
        {
            RectangleShape resultExtent = null;

            if (GisEditor.LayerListManager.SelectedLayerListItem == null)
            {
                return;
            }
            if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Overlay && GisEditor.LayerListManager.SelectedLayerListItems.Count > 0)
            {
                Collection <RectangleShape> extents = new Collection <RectangleShape>();
                foreach (var item in GisEditor.LayerListManager.SelectedLayerListItems)
                {
                    var tmpOverlay = item.ConcreteObject as Overlay;
                    if (tmpOverlay != null)
                    {
                        extents.Add(tmpOverlay.GetBoundingBox());
                    }
                }
                resultExtent = ExtentHelper.GetBoundingBoxOfItems(extents);
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItems.Count > 0)
            {
                Collection <RectangleShape> extents = new Collection <RectangleShape>();
                foreach (var item in GisEditor.LayerListManager.SelectedLayerListItems)
                {
                    Layer tmpLayer = item.ConcreteObject as Layer;
                    if (tmpLayer != null && tmpLayer.HasBoundingBox)
                    {
                        tmpLayer.SafeProcess(() =>
                        {
                            extents.Add(tmpLayer.GetBoundingBox());
                        });

                        //tmpLayer.Open();
                        //extents.Add(tmpLayer.GetBoundingBox());
                        //tmpLayer.Close();
                    }
                }
                resultExtent = ExtentHelper.GetBoundingBoxOfItems(extents);
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Overlay)
            {
                resultExtent = (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Overlay).GetBoundingBox();
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is Layer)
            {
                Layer layer = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as Layer;
                if (layer.HasBoundingBox)
                {
                    layer.SafeProcess(() =>
                    {
                        resultExtent = layer.GetBoundingBox();
                    });
                }
            }
            else if (GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject is ValueItem)
            {
                string       value        = ((ValueItem)GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject).Value;
                string       columnName   = ((ValueStyle)GisEditor.LayerListManager.SelectedLayerListItem.Parent.ConcreteObject).ColumnName;
                FeatureLayer featureLayer = LayerListHelper.FindMapElementInTree <FeatureLayer>(GisEditor.LayerListManager.SelectedLayerListItem);
                if (featureLayer != null)
                {
                    System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.DialogResult.Yes;
                    FeatureLayerPlugin[] layerPlugins = GisEditor.LayerManager.GetLayerPlugins(featureLayer.GetType()).OfType <FeatureLayerPlugin>().ToArray();
                    if (layerPlugins.Length > 0 && !layerPlugins[0].CanQueryFeaturesEfficiently)
                    {
                        dialogResult = System.Windows.Forms.MessageBox.Show(GisEditor.LanguageManager.GetStringResource("ZoomToExtentWarning"), GisEditor.LanguageManager.GetStringResource("MapElementsListPluginZoomToExtent"), System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Information);
                    }
                    if (dialogResult == System.Windows.Forms.DialogResult.Yes)
                    {
                        Collection <Feature> features = new Collection <Feature>();
                        featureLayer.SafeProcess(() =>
                        {
                            features     = featureLayer.QueryTools.GetFeaturesByColumnValue(columnName, value);
                            resultExtent = ExtentHelper.GetBoundingBoxOfItems(features);
                        });
                        if (features.Count == 0)
                        {
                            MessageBoxHelper.ShowMessage("No features matched.", "Zoom to extent", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information);
                        }
                    }
                }
            }

            if (resultExtent != null)
            {
                GisEditor.ActiveMap.CurrentExtent = resultExtent;
                GisEditor.ActiveMap.Refresh();
            }
        }
        private void InitGridDefinition()
        {
            var entity = content.DataContext as GridWizardShareObject;

            RectangleShape gridExtent = new RectangleShape();
            List <Feature> features   = new List <Feature>();

            entity.SelectedFeatureLayer.SafeProcess(() =>
            {
                if (entity.HasSelectedFeatures && entity.OnlyUseSelectedFeatures)
                {
                    features   = GisEditor.SelectionManager.GetSelectedFeatures().Where(f => f.Tag != null && f.Tag == entity.SelectedFeatureLayer).ToList();
                    gridExtent = ExtentHelper.GetBoundingBoxOfItems(features);
                    gridExtent.ScaleUp(0.05);
                }
                else
                {
                    features   = entity.SelectedFeatureLayer.FeatureSource.GetAllFeatures(entity.SelectedFeatureLayer.FeatureSource.GetDistinctColumnNames()).ToList();
                    gridExtent = ExtentHelper.GetBoundingBoxOfItems(features);
                }
            });

            Dictionary <PointShape, double> dataPoints = new Dictionary <PointShape, double>();

            foreach (var item in features)
            {
                double columnValue = double.NaN;
                if (double.TryParse(item.ColumnValues[entity.SelectedDataColumn.ColumnName], out columnValue))
                {
                    var shape = item.GetShape();
                    if (shape.GetType().Equals(typeof(MultipointShape)))
                    {
                        foreach (var point in ((MultipointShape)shape).Points)
                        {
                            point.Tag = null;
                            dataPoints.Add(point, columnValue);
                        }
                    }
                    else
                    {
                        PointShape pointShape = (PointShape)shape;
                        pointShape.Tag = null;
                        dataPoints.Add(pointShape, columnValue);
                    }
                }
            }

            double tmpCellSize = 0.0;

            switch (GisEditor.ActiveMap.MapUnit)
            {
            case GeographyUnit.DecimalDegree:
                tmpCellSize = DecimalDegreesHelper.GetLongitudeDifferenceFromDistance(entity.CellSize, entity.SelectedCellSizeDistanceUnit, gridExtent.GetCenterPoint().Y);
                break;

            case GeographyUnit.Feet:
                tmpCellSize = Conversion.ConvertMeasureUnits(entity.CellSize, entity.SelectedCellSizeDistanceUnit, DistanceUnit.Feet);
                break;

            case GeographyUnit.Meter:
                tmpCellSize = Conversion.ConvertMeasureUnits(entity.CellSize, entity.SelectedCellSizeDistanceUnit, DistanceUnit.Meter);
                break;

            default:
                break;
            }

            entity.GridDefinition = new GridDefinition(gridExtent, tmpCellSize, -9999, dataPoints);
        }
Exemplo n.º 16
0
        private IEnumerable <Feature> StandardClip(FeatureSource featureSource, IEnumerable <Feature> features)
        {
            lock (featureSource)
            {
                Collection <Feature> results = new Collection <Feature>();

                //There is a bug about projection boundingbox, here is a workaround for it.
                bool       isOpen        = false;
                Projection tmpProjection = null;
                if (featureSource.Projection != null &&
                    featureSource.Projection is GISEditorManagedProj4Projection &&
                    ((GISEditorManagedProj4Projection)featureSource.Projection).IsProjectionParametersEqual)
                {
                    tmpProjection = featureSource.Projection;
                    if (featureSource.IsOpen)
                    {
                        featureSource.Close();
                        featureSource.Projection.Close();
                        isOpen = true;
                    }
                    featureSource.Projection = null;
                }

                if (!featureSource.IsOpen)
                {
                    featureSource.Open();
                }
                Collection <Feature> sourceFeatures = featureSource.GetFeaturesInsideBoundingBox(ExtentHelper.GetBoundingBoxOfItems(features), ReturningColumnsType.AllColumns);

                if (tmpProjection != null)
                {
                    featureSource.Projection = tmpProjection;
                    if (isOpen)
                    {
                        featureSource.Open();
                    }
                }

                ShapeFileType shapeFileType = ((ShapeFileFeatureSource)featureSource).GetShapeFileType();
                if (featureSource.IsOpen)
                {
                    featureSource.Close();
                }

                int index = 1;
                int count = sourceFeatures.Count;
                if (shapeFileType == ShapeFileType.Point || shapeFileType == ShapeFileType.Multipoint)
                {
                    return(StandardClipPoints(sourceFeatures, features, shapeFileType));
                }
                else if (shapeFileType == ShapeFileType.Polyline)
                {
                    MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(features));
                    foreach (var feature in sourceFeatures)
                    {
                        ReportProgress(index * 100 / count);
                        index++;
                        try
                        {
                            if (areaBaseShape.Contains(feature))
                            {
                                results.Add(feature);
                            }
                            else
                            {
                                var clippedShape = ((LineBaseShape)feature.GetShape()).GetIntersection(areaBaseShape);
                                if (clippedShape != null && clippedShape.Lines.Count > 0)
                                {
                                    results.Add(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    }
                }
                else if (shapeFileType == ShapeFileType.Polygon)
                {
                    MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(features));
                    foreach (var feature in sourceFeatures)
                    {
                        ReportProgress(index * 100 / count);
                        try
                        {
                            index++;
                            if (areaBaseShape.Contains(feature))
                            {
                                results.Add(feature);
                            }
                            else
                            {
                                var clippedShape = areaBaseShape.GetIntersection(feature);
                                if (clippedShape != null && clippedShape.Polygons.Count > 0)
                                {
                                    results.Add(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException("The ShapeFileType is not supported.");
                }
                return(results);
            }
        }
Exemplo n.º 17
0
        private IEnumerable <Feature> InverseClip(FeatureSource featureSource, IEnumerable <Feature> clippingFeatures)
        {
            lock (featureSource)
            {
                if (!featureSource.IsOpen)
                {
                    featureSource.Open();
                }
                Collection <Feature> results        = featureSource.GetFeaturesOutsideBoundingBox(ExtentHelper.GetBoundingBoxOfItems(clippingFeatures), ReturningColumnsType.AllColumns);
                Collection <Feature> sourceFeatures = new Collection <Feature>();
                ShapeFileType        shapeFileType  = ((ShapeFileFeatureSource)featureSource).GetShapeFileType();
                int index = 1;
                if (shapeFileType == ShapeFileType.Point || shapeFileType == ShapeFileType.Multipoint)
                {
                    featureSource.Open();
                    Collection <Feature> allFeatures = featureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
                    featureSource.Close();
                    foreach (Feature f in results)
                    {
                        allFeatures.Remove(f);
                    }
                    foreach (var f in InverseClipPoints(allFeatures, clippingFeatures, shapeFileType))
                    {
                        results.Add(f);
                    }
                }
                else if (shapeFileType == ShapeFileType.Polyline)
                {
                    bool              isOpen        = false;
                    Projection        tmpProjection = null;
                    MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(clippingFeatures));
                    if (featureSource.Projection != null &&
                        featureSource.Projection is GISEditorManagedProj4Projection &&
                        ((GISEditorManagedProj4Projection)featureSource.Projection).IsProjectionParametersEqual)
                    {
                        tmpProjection = featureSource.Projection;
                        if (featureSource.IsOpen)
                        {
                            featureSource.Close();
                            featureSource.Projection.Close();
                            isOpen = true;
                        }
                        featureSource.Projection = null;
                    }
                    featureSource.Open();
                    featureSource.GetFeaturesInsideBoundingBox(areaBaseShape.GetBoundingBox(), ReturningColumnsType.AllColumns).ForEach(f => { if (!areaBaseShape.Contains(f))
                                                                                                                                               {
                                                                                                                                                   sourceFeatures.Add(f);
                                                                                                                                               }
                                                                                                                                        });
                    int count = sourceFeatures.Count;
                    if (tmpProjection != null)
                    {
                        featureSource.Projection = tmpProjection;
                        if (isOpen)
                        {
                            featureSource.Open();
                        }
                    }
                    if (featureSource.IsOpen)
                    {
                        featureSource.Close();
                    }
                    foreach (var feature in sourceFeatures)
                    {
                        ReportProgress(index * 100 / count);
                        index++;
                        try
                        {
                            if (areaBaseShape.IsDisjointed(feature))
                            {
                                results.Add(feature);
                            }
                            else
                            {
                                MultilineShape multiLine   = (MultilineShape)feature.GetShape();
                                MultilineShape resultShape = new MultilineShape();
                                foreach (LineShape lineShape in multiLine.Lines)
                                {
                                    if (areaBaseShape.IsDisjointed(lineShape))
                                    {
                                        resultShape.Lines.Add(lineShape);
                                    }
                                    else
                                    {
                                        Collection <PointShape> points = new Collection <PointShape>();
                                        points.Add(new PointShape(lineShape.Vertices[0]));
                                        lineShape.GetIntersection(areaBaseShape).Lines.ForEach(l =>
                                        {
                                            PointShape p1 = new PointShape(l.Vertices[0]);
                                            if (points.Count(p => p.X == p1.X && p.Y == p1.Y && p.Z == p1.Z) <= 0)
                                            {
                                                points.Add(p1);
                                            }
                                            PointShape p2 = new PointShape(l.Vertices[l.Vertices.Count - 1]);
                                            if (points.Count(p => p.X == p2.X && p.Y == p2.Y && p.Z == p2.Z) <= 0)
                                            {
                                                points.Add(p2);
                                            }
                                        });
                                        PointShape endPoint = new PointShape(lineShape.Vertices[lineShape.Vertices.Count - 1]);
                                        if (points.Count(p => p.X == endPoint.X && p.Y == endPoint.Y && p.Z == endPoint.Z) <= 0)
                                        {
                                            points.Add(endPoint);
                                        }

                                        for (int i = 0; i < points.Count; i++)
                                        {
                                            if (i != points.Count - 1)
                                            {
                                                LineBaseShape lineBaseShape = lineShape.GetLineOnALine(points[i], points[i + 1]);

                                                if (!areaBaseShape.Intersects(lineBaseShape.GetCenterPoint()))
                                                {
                                                    resultShape.Lines.Add((LineShape)lineBaseShape);
                                                }
                                            }
                                        }
                                    }
                                }
                                if (resultShape != null && resultShape.Lines.Count > 0)
                                {
                                    results.Add(new Feature(resultShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    }
                }
                else if (shapeFileType == ShapeFileType.Polygon)
                {
                    MultipolygonShape areaBaseShape = AreaBaseShape.Union(GetValidFeatures(clippingFeatures));

                    bool       isOpen        = false;
                    Projection tmpProjection = null;
                    if (featureSource.Projection != null &&
                        featureSource.Projection is GISEditorManagedProj4Projection &&
                        ((GISEditorManagedProj4Projection)featureSource.Projection).IsProjectionParametersEqual)
                    {
                        tmpProjection = featureSource.Projection;
                        if (featureSource.IsOpen)
                        {
                            featureSource.Close();
                            featureSource.Projection.Close();
                            isOpen = true;
                        }
                        featureSource.Projection = null;
                    }
                    if (!featureSource.IsOpen)
                    {
                        featureSource.Open();
                    }
                    featureSource.GetFeaturesInsideBoundingBox(areaBaseShape.GetBoundingBox(), ReturningColumnsType.AllColumns).ForEach(f => { if (!areaBaseShape.IsDisjointed(f))
                                                                                                                                               {
                                                                                                                                                   sourceFeatures.Add(f);
                                                                                                                                               }
                                                                                                                                        });
                    if (featureSource.IsOpen)
                    {
                        featureSource.Close();
                    }
                    if (tmpProjection != null)
                    {
                        featureSource.Projection = tmpProjection;
                        if (isOpen)
                        {
                            featureSource.Open();
                        }
                    }

                    int count = sourceFeatures.Count;
                    foreach (var feature in sourceFeatures)
                    {
                        ReportProgress(index * 100 / count);
                        index++;
                        try
                        {
                            if (areaBaseShape.IsDisjointed(feature))
                            {
                                results.Add(feature);
                            }
                            else
                            {
                                var clippedShape = ((AreaBaseShape)feature.GetShape()).GetDifference(areaBaseShape);
                                if (clippedShape != null && clippedShape.Polygons.Count > 0)
                                {
                                    results.Add(new Feature(clippedShape.GetWellKnownBinary(), feature.Id, feature.ColumnValues));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
                        }
                    }
                }
                else
                {
                    throw new NotSupportedException("The ShapeFileType is not supported.");
                }
                return(results);
            }
        }