private IEnumerable <Feature> GetFeaturesFromTempFile()
        {
            featureSource.Open();
            var allFeatures = featureSource.GetAllFeatures(featureSource.GetDistinctColumnNames());

            featureSource.Close();

            return(allFeatures.Where(f =>
            {
                var shape = f.GetShape();
                return shape is AreaBaseShape || shape is LineBaseShape;
            }));
        }
Exemplo n.º 2
0
        private void FastestPath(BuildingRoutingDataRtgRoutingSourceEventArgs e)
        {
            featureSource.Open();
            Feature feature = featureSource.GetFeatureById(e.LineShape.Id, new string[] { "CFCC" });

            if (feature.ColumnValues["CFCC"].CompareTo("A4") < 0)
            {
                e.RouteSegment.Weight = e.RouteSegment.Weight / SpeedOfHighWay;
            }
            else
            {
                e.RouteSegment.Weight = e.RouteSegment.Weight / SpeedOfLocalRoad;
            }
        }
Exemplo n.º 3
0
        protected override Style GetStyleCore(FeatureSource featureSource)
        {
            Collection <GeoColor> familyColors = GeoColor.GetColorsInQualityFamily(Color, EndColor, classBreakCount, ColorWheelDirection);

            featureSource.Open();
            int featureCount = featureSource.GetCount();

            double[] values = new double[featureCount];
            for (int i = 0; i < featureCount; i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double  columnValue;
                double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue);
                values[i] = columnValue;
            }
            featureSource.Close();

            ClassBreakStyle classBreakStyle = new ClassBreakStyle(SelectedColumns[0])
            {
                BreakValueInclusion = BreakValueInclusion.IncludeValue
            };

            double[] classBreakValues = GetClusterClassBreaks(values, ClassBreaksCount - 1);
            for (int i = 0; i < classBreakValues.Length; i++)
            {
                ClassBreak classBreak = new ClassBreak(classBreakValues[i], AreaStyles.CreateSimpleAreaStyle(new GeoColor(this.Opacity, familyColors[i]), GeoColor.FromHtml("#f05133"), 1));
                classBreakStyle.ClassBreaks.Add(classBreak);
            }

            return(classBreakStyle);
        }
Exemplo n.º 4
0
        protected override Style GetStyleCore(FeatureSource featureSource)
        {
            double totalValue = 0;

            featureSource.Open();
            int featureCount = featureSource.GetCount();

            for (int i = 0; i < featureCount; i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double  columnValue;
                double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue);
                totalValue += columnValue;
            }
            featureSource.Close();
            double pointToValueRatio = DotDensityValue / (totalValue / featureCount);

            CustomDotDensityStyle dotDensityStyle = new CustomDotDensityStyle();

            dotDensityStyle.ColumnName        = SelectedColumns[0];
            dotDensityStyle.PointToValueRatio = pointToValueRatio;
            dotDensityStyle.CustomPointStyle  = new PointStyle(PointSymbolType.Circle, new GeoSolidBrush(GeoColor.FromArgb(Opacity, Color)), 4);

            return(dotDensityStyle);
        }
Exemplo n.º 5
0
        protected override Collection <Style> GetStylesCore(FeatureSource featureSource)
        {
            double totalValue = 0;

            featureSource.Open();
            int featureCount = featureSource.GetCount();

            for (int i = 0; i < featureCount; i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double  columnValue;
                double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue);
                totalValue += columnValue;
            }
            featureSource.Close();

            CustomDotDensityStyle dotDensityStyle = new CustomDotDensityStyle();

            dotDensityStyle.ColumnName        = SelectedColumns[0];
            dotDensityStyle.PointToValueRatio = DotDensityValue / (totalValue / featureCount);
            dotDensityStyle.CustomPointStyle  = PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(Opacity, Color), 4);

            return(new Collection <Style>()
            {
                dotDensityStyle
            });
        }
        protected override Collection<Style> GetStylesCore(FeatureSource featureSource)
        {
            // here we generated a class break style and a text style.
            Collection<GeoColor> familyColors = GeoColor.GetColorsInQualityFamily(Color, EndColor, classBreakCount, ColorWheelDirection);

            featureSource.Open();
            int featureCount = featureSource.GetCount();
            double[] values = new double[featureCount];
            for (int i = 0; i < featureCount; i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double columnValue;
                if (double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue))
                {
                    values[i] = columnValue;
                }
            }
            featureSource.Close();

            ClassBreakStyle classBreakStyle = new ClassBreakStyle(SelectedColumns[0]) { BreakValueInclusion = BreakValueInclusion.IncludeValue };
            double[] classBreakValues = GetClusterClassBreaks(values, ClassBreakCount - 1);
            for (int i = 0; i < classBreakValues.Length; i++)
            {
                ClassBreak classBreak = new ClassBreak(classBreakValues[i], AreaStyles.CreateSimpleAreaStyle(new GeoColor(this.Opacity, familyColors[i]), GeoColor.FromHtml("#f05133"), 1));
                classBreakStyle.ClassBreaks.Add(classBreak);
            }

            return new Collection<Style>() { classBreakStyle, TextStyles.Country1("NAME") };
        }
        protected override Collection<Style> GetStylesCore(FeatureSource featureSource)
        {
            // here we generate CustomDotDensityStyle.
            double totalValue = 0;
            featureSource.Open();
            int featureCount = featureSource.GetCount();
            for (int i = 0; i < featureCount; i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double columnValue;

                if (double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue))
                {
                    totalValue += columnValue;
                }
            }
            featureSource.Close();

            CustomDotDensityStyle dotDensityStyle = new CustomDotDensityStyle();
            dotDensityStyle.ColumnName = SelectedColumns[0];
            dotDensityStyle.PointToValueRatio = DotDensityValue / (totalValue / featureCount);
            dotDensityStyle.CustomPointStyle = PointStyles.CreateSimpleCircleStyle(GeoColor.FromArgb(Opacity, Color), 4);

            return new Collection<Style>() { dotDensityStyle };
        }
        private void Split()
        {
            var args = new UpdatingTaskProgressEventArgs(TaskState.Updating);

            featureSource.Open();
            Collection <Feature> allFeatures = featureSource.GetAllFeatures(featureSource.GetDistinctColumnNames());
            var columns = featureSource.GetColumns();

            featureSource.Close();

            var featuresGroups = allFeatures.GroupBy(tmpFeature
                                                     => tmpFeature.ColumnValues[splitColumnName]).ToArray();

            int i     = 0;
            int count = exportConfigs.Count;

            foreach (var config in exportConfigs)
            {
                try
                {
                    string folderName = outputPath;
                    string fileName   = config.Value;
                    if (String.IsNullOrEmpty(fileName))
                    {
                        fileName = String.Format(CultureInfo.InvariantCulture, "{0}_{1}.shp", layerName, config.Key);
                    }

                    fileName = Path.ChangeExtension(fileName, ".shp");
                    string finalShapeFilePath = Path.Combine(folderName, fileName);
                    var    featureGroup       = featuresGroups.FirstOrDefault(group => group.Key == config.Key || (config.Key.Equals("<Blank>", StringComparison.Ordinal) && group.Key.Equals(string.Empty, StringComparison.Ordinal)));
                    if (featureGroup != null)
                    {
                        var info = new FileExportInfo(featureGroup, columns, finalShapeFilePath, wkt);
                        Export(info);
                    }

                    args.Current    = ++i;
                    args.UpperBound = count;
                    args.Message    = String.Format(CultureInfo.InvariantCulture, "Building... ({0}/{1})", args.Current, args.UpperBound);
                    OnUpdatingProgress(args);
                    isCanceled = args.TaskState == TaskState.Canceled;

                    if (isCanceled)
                    {
                        break;
                    }
                }
                catch (Exception ex)
                {
                    var errorArgs = new UpdatingTaskProgressEventArgs(TaskState.Error);
                    errorArgs.Error = new ExceptionInfo(ex.Message, ex.StackTrace, ex.Source);
                    GisEditor.LoggerManager.Log(LoggerLevel.Debug, ex.Message, new ExceptionInfo(ex));
                    OnUpdatingProgress(errorArgs);
                    continue;
                }
            }
        }
Exemplo n.º 9
0
        public virtual RoadNetwork CreateNetwork(FeatureSource featureSource)
        {
            featureSource.Open();
            QTreeSpatialIndex qtree = new QTreeSpatialIndex(featureSource.GetBoundingBox());

            #if DEBUG
            long featureCount = featureSource.GetCount();
            #endif

            RoadNetwork roadNetwork = new RoadNetwork();
            Collection<Feature> features = featureSource.GetAllFeatures(ReturningColumnsType.NoColumns);
            featureSource.Close();
            Collection<Collection<Feature>> featureGroups = GroupFeatures(features);
            int done = 0;
            var tasks = (from items in featureGroups
                         select Task.Factory.StartNew(() =>
                         {
                             var clonedFeatureSource = featureSource.CloneDeep();
                             clonedFeatureSource.Open();
                             foreach (var feature in items)
                             {
                                 Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
                                 // Get the lineshape of the processing feature.
                                 foreach (LineShape processingLineShape in processingLineShapes)
                                 {
                                     BuildNetworkNode(clonedFeatureSource, qtree, roadNetwork, processingLineShape.Vertices[0]);
                                     BuildNetworkNode(clonedFeatureSource, qtree, roadNetwork, processingLineShape.Vertices[processingLineShape.Vertices.Count - 1]);
                                 }
                                 done++;
                                 Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, done));
                             }

                         })).ToArray();
            //foreach (Feature feature in features)
            //{
            //    Task.Factory.StartNew(() =>
            //    {
            //        Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
            //        // Get the lineshape of the processing feature.
            //        foreach (LineShape processingLineShape in processingLineShapes)
            //        {
            //            BuildNetworkNode(featureSource, qtree, roadNetwork, processingLineShape.Vertices[0]);
            //            BuildNetworkNode(featureSource, qtree, roadNetwork, processingLineShape.Vertices[processingLineShape.Vertices.Count - 1]);
            //        }
            //    }
            //   );
            Task.WaitAll(tasks);

            #if DEBUG

            #endif

            //}
            //featureSource.Close();

            return roadNetwork;
        }
        private Collection <Feature> GetFeaturesToExplode(FeatureSource featureSource)
        {
            featureSource.Open();
            var allFeatures = featureSource.GetAllFeatures(featureSource.GetDistinctColumnNames());

            columns = featureSource.GetColumns();
            featureSource.Close();

            return(allFeatures);
        }
        private Collection <Feature> GetFeaturesToDissolve()
        {
            featureSource.Open();
            featureColumns = featureSource.GetColumns();
            var allFeatures = featureSource.GetAllFeatures(ReturningColumnsType.AllColumns);

            featureSource.Close();

            return(allFeatures);
        }
Exemplo n.º 12
0
        public virtual RoadNetwork CreateNetwork(FeatureSource featureSource)
        {
            featureSource.Open();
            QTreeSpatialIndex qtree = new QTreeSpatialIndex(featureSource.GetBoundingBox());

#if DEBUG
            long featureCount = featureSource.GetCount();
#endif

            RoadNetwork          roadNetwork = new RoadNetwork();
            Collection <Feature> features    = featureSource.GetAllFeatures(ReturningColumnsType.NoColumns);
            featureSource.Close();
            Collection <Collection <Feature> > featureGroups = GroupFeatures(features);
            int done  = 0;
            var tasks = (from items in featureGroups
                         select Task.Factory.StartNew(() =>
            {
                var clonedFeatureSource = featureSource.CloneDeep();
                clonedFeatureSource.Open();
                foreach (var feature in items)
                {
                    Collection <LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
                    // Get the lineshape of the processing feature.
                    foreach (LineShape processingLineShape in processingLineShapes)
                    {
                        BuildNetworkNode(clonedFeatureSource, qtree, roadNetwork, processingLineShape.Vertices[0]);
                        BuildNetworkNode(clonedFeatureSource, qtree, roadNetwork, processingLineShape.Vertices[processingLineShape.Vertices.Count - 1]);
                    }
                    done++;
                    Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, done));
                }
            })).ToArray();
            //foreach (Feature feature in features)
            //{
            //    Task.Factory.StartNew(() =>
            //    {
            //        Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
            //        // Get the lineshape of the processing feature.
            //        foreach (LineShape processingLineShape in processingLineShapes)
            //        {
            //            BuildNetworkNode(featureSource, qtree, roadNetwork, processingLineShape.Vertices[0]);
            //            BuildNetworkNode(featureSource, qtree, roadNetwork, processingLineShape.Vertices[processingLineShape.Vertices.Count - 1]);
            //        }
            //    }
            //   );
            Task.WaitAll(tasks);

#if DEBUG
#endif

            //}
            //featureSource.Close();

            return(roadNetwork);
        }
        private Collection <Feature> GetFeaturesToBuffer(string featureSourceInString)
        {
            FeatureSource featureSource = (FeatureSource)GetObjectFromString(featureSourceInString);

            featureSource.Open();
            var allFeatures = featureSource.GetAllFeatures(ReturningColumnsType.AllColumns);

            columns = featureSource.GetColumns();
            featureSource.Close();

            return(allFeatures);
        }
Exemplo n.º 14
0
        private void UserControl_Load(object sender, EventArgs e)
        {
            RenderMap();

            featureSource = new ShapeFileFeatureSource(Path.Combine(rootPath, "DallasCounty-4326.shp"));
            featureSource.Open();
            RoutingSource routingSource = new RtgRoutingSource(Path.Combine(rootPath, "HighwayFirst.rtg"));

            routingEngine = new RoutingEngine(routingSource, featureSource);
            routingEngine.RoutingAlgorithm.FindingRoute += new EventHandler <FindingRouteRoutingAlgorithmEventArgs>(Algorithm_FindingPath);

            this.cbmPrioritiy.Text = "On Foot";
        }
Exemplo n.º 15
0
        private static Dictionary <PointShape, double> GetDataPoints(FeatureSource featureSource)
        {
            featureSource.Open();
            Dictionary <PointShape, double> features = (from feature in featureSource.GetAllFeatures(new string[] { "LONGITUDE", "LATITIUDE", "MAGNITUDE" })
                                                        where double.Parse(feature.ColumnValues["MAGNITUDE"]) > 0
                                                        select new PointShape
            {
                X = double.Parse(feature.ColumnValues["LONGITUDE"], CultureInfo.InvariantCulture),
                Y = double.Parse(feature.ColumnValues["LATITIUDE"], CultureInfo.InvariantCulture),
                Z = double.Parse(feature.ColumnValues["MAGNITUDE"], CultureInfo.InvariantCulture)
            }).ToDictionary(point => point, point => point.Z);

            return(features);
        }
Exemplo n.º 16
0
        private void Initialize()
        {
            Collection <GeoColor> levelAreaColors = new Collection <GeoColor>();

            levelAreaColors.Add(GeoColor.FromHtml("#FFFFBE"));
            levelAreaColors.Add(GeoColor.FromHtml("#FDFF9E"));
            levelAreaColors.Add(GeoColor.FromHtml("#FDFF37"));
            levelAreaColors.Add(GeoColor.FromHtml("#FDDA04"));
            levelAreaColors.Add(GeoColor.FromHtml("#FFA701"));
            levelAreaColors.Add(GeoColor.FromHtml("#FF6F02"));
            levelAreaColors.Add(GeoColor.FromHtml("#EC0000"));
            levelAreaColors.Add(GeoColor.FromHtml("#B90000"));
            levelAreaColors.Add(GeoColor.FromHtml("#850100"));
            levelAreaColors.Add(GeoColor.FromHtml("#620001"));
            levelAreaColors.Add(GeoColor.FromHtml("#450005"));
            levelAreaColors.Add(GeoColor.FromHtml("#2B0804"));

            FeatureSource.Open();

            Dictionary <PointShape, double> dataPoints         = GetDataPoints();
            GridInterpolationModel          interpolationModel = new InverseDistanceWeightedGridInterpolationModel(3, double.MaxValue);

            isoLineLayer = new DynamicIsoLineLayer(dataPoints, GetClassBreakValues(dataPoints.Values, 12), interpolationModel, IsoLineType.ClosedLinesAsPolygons);

            isoLineLayer.CellWidthInPixel  = 32;
            isoLineLayer.CellHeightInPixel = 32;
            levelClassBreakStyle           = new ClassBreakStyle(isoLineLayer.DataValueColumnName);
            levelClassBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), new GeoSolidBrush(new GeoColor(100, levelAreaColors[0])))));
            for (int i = 0; i < IsoLineLevels.Count - 1; i++)
            {
                if (!levelClassBreakStyle.ClassBreaks.Any(c => c.Value == IsoLineLevels[i + 1]))
                {
                    levelClassBreakStyle.ClassBreaks.Add(new ClassBreak(IsoLineLevels[i + 1], new AreaStyle(new GeoPen(GeoColor.FromHtml("#FE6B06"), 1), new GeoSolidBrush(new GeoColor(100, levelAreaColors[i + 1])))));
                }
            }
            isoLineLayer.CustomStyles.Add(levelClassBreakStyle);

            TextStyle textStyle = TextStyles.CreateSimpleTextStyle(isoLineLayer.DataValueColumnName, "Arial", 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, 0, 0);

            textStyle.HaloPen               = new GeoPen(GeoColor.StandardColors.White, 2);
            textStyle.OverlappingRule       = LabelOverlappingRule.NoOverlapping;
            textStyle.SplineType            = SplineType.StandardSplining;
            textStyle.DuplicateRule         = LabelDuplicateRule.UnlimitedDuplicateLabels;
            textStyle.TextLineSegmentRatio  = 9999999;
            textStyle.FittingLineInScreen   = true;
            textStyle.SuppressPartialLabels = true;
            textStyle.NumericFormat         = "{0:0.00}";
            isoLineLayer.CustomStyles.Add(textStyle);
        }
Exemplo n.º 17
0
        private void RenderMap()
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#e6e5d1"));
            winformsMap1.CurrentExtent = new RectangleShape(-97.7717794617797, 30.3120942308639, -97.7082647523071, 30.2667756273482);

            WorldMapKitWmsDesktopOverlay worldMapKitsOverlay = new WorldMapKitWmsDesktopOverlay();

            winformsMap1.Overlays.Add(worldMapKitsOverlay);

            InMemoryFeatureLayer routingLayer = new InMemoryFeatureLayer();

            featureSource = new ShapeFileFeatureSource(@"..\..\SampleData\Austinstreets.shp");
            featureSource.Open();
            Feature startRoad = featureSource.GetFeatureById(txtStartId.Text, ReturningColumnsType.NoColumns);

            featureSource.Close();
            Feature startPoint = new Feature(startRoad.GetShape().GetCenterPoint().GetWellKnownBinary(), txtStartId.Text);

            routingLayer.InternalFeatures.Add(txtStartId.Text, startPoint);

            routingLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
            routingLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush = new GeoSolidBrush(GeoColor.FromArgb(100, GeoColor.StandardColors.Blue));
            routingLayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle.OuterPen.Color = GeoColor.StandardColors.Red;
            routingLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel             = ApplyUntilZoomLevel.Level20;
            LayerOverlay routingOverlay = new LayerOverlay();

            routingOverlay.Layers.Add("RoutingLayer", routingLayer);
            winformsMap1.Overlays.Add("RoutingOverlay", routingOverlay);

            InMemoryFeatureLayer routingExtentLayer = new InMemoryFeatureLayer();

            routingExtentLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle    = new AreaStyle(new GeoPen(GeoColor.SimpleColors.Green));
            routingExtentLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            routingExtentLayer.InternalFeatures.Add(new Feature(new RectangleShape(-97.815409, 30.369949, -97.657999, 30.217922)));
            routingOverlay.Layers.Add("RoutingExtentLayer", routingExtentLayer);

            InMemoryFeatureLayer facilityLayer = new InMemoryFeatureLayer();

            facilityLayer.Open();
            facilityLayer.Columns.Add(new FeatureSourceColumn("NAME"));
            facilityLayer.Close();
            facilityLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle   = PointStyles.Capital1;
            facilityLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            routingOverlay.Layers.Add("FacilityLayer", facilityLayer);

            winformsMap1.Refresh();
        }
        private void Initialize()
        {
            Dictionary <PointShape, double> dataPoints = new Dictionary <PointShape, double>();

            if (!FeatureSource.IsOpen)
            {
                FeatureSource.Open();
            }

            Collection <Feature> allFeatures = FeatureSource.GetAllFeatures(new Collection <string>()
            {
                Resources.LongitudeColumnName, Resources.LatitudeColumnName, Resources.MagnitudeColumnName
            });
            var featureColumnQuery = allFeatures.Where(n => double.Parse(n.ColumnValues[Resources.MagnitudeColumnName]) > 0).Select(n => new
            {
                Longitude = double.Parse(n.ColumnValues[Resources.LongitudeColumnName]),
                Latitude  = double.Parse(n.ColumnValues[Resources.LatitudeColumnName]),
                Magnitude = double.Parse(n.ColumnValues[Resources.MagnitudeColumnName])
            });

            foreach (var column in featureColumnQuery)
            {
                dataPoints.Add(new PointShape(column.Longitude, column.Latitude), column.Magnitude);
            }

            double[]            dataCollection = dataPoints.Select(n => n.Value).ToArray();
            Collection <double> isoLineLevels  = new Collection <double>(GetClassBreakValues(dataCollection, 12).ToList());

            isoLineLayer = new DynamicIsoLineLayer(dataPoints, isoLineLevels, new InverseDistanceWeightedGridInterpolationModel(3, double.MaxValue), IsoLineType.ClosedLinesAsPolygons);

            isoLineLayer.CustomStyles.Add(LevelClassBreakStyle);

            //Create the text styles to label the lines
            TextStyle textStyle = TextStyles.CreateSimpleTextStyle(isoLineLayer.DataValueColumnName, "Arial", 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, 0, 0);

            textStyle.HaloPen               = new GeoPen(GeoColor.StandardColors.White, 2);
            textStyle.OverlappingRule       = LabelOverlappingRule.NoOverlapping;
            textStyle.SplineType            = SplineType.StandardSplining;
            textStyle.DuplicateRule         = LabelDuplicateRule.UnlimitedDuplicateLabels;
            textStyle.TextLineSegmentRatio  = 9999999;
            textStyle.FittingLineInScreen   = true;
            textStyle.SuppressPartialLabels = true;
            textStyle.NumericFormat         = "{0:0.00}";
            isoLineLayer.CustomStyles.Add(textStyle);
        }
Exemplo n.º 19
0
        protected override void RunCore(Dictionary <string, string> parameters)
        {
            ParseParameters(parameters);
            var clippingFeatures = GetClippingFeatures();

            masterLayerFeatureSource.Open();
            var columns = masterLayerFeatureSource.GetColumns();

            masterLayerFeatureSource.Close();

            var clippedFeatures = Clip(masterLayerFeatureSource, clippingFeatures, clipType);

            ExportToFile(outputPath, clippedFeatures, columns);

            var args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating);

            args.Message = "Finished";
            OnUpdatingProgress(args);
        }
Exemplo n.º 20
0
        private void UserControl_Load(object sender, EventArgs e)
        {
            featureSource = new ShapeFileFeatureSource(Path.Combine(rootPath, "DallasCounty-4326.shp"));
            allowArea     = new PolygonShape(txtAvoidWkt.Text);
            featureSource.Open();
            Collection <Feature> features = featureSource.SpatialQuery(allowArea, QueryType.Within, ReturningColumnsType.NoColumns);

            featureSource.Close();
            allowFeatureIds = new Collection <string>();
            foreach (Feature item in features)
            {
                allowFeatureIds.Add(item.Id);
            }
            RoutingSource routingSource = new RtgRoutingSource(Path.Combine(rootPath, "DallasCounty-4326.shortest.rtg"));

            routingEngine = new RoutingEngine(routingSource, new AStarRoutingAlgorithm(), featureSource);

            RenderMap();
        }
        protected override Collection <Style> GetStylesCore(FeatureSource featureSource)
        {
            // here we generate a ValueCircle Style.
            double minValue = double.MaxValue;
            double maxValue = double.MinValue;

            featureSource.Open();
            for (int i = 0; i < featureSource.GetCount(); i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double  columnValue;
                if (double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue))
                {
                    if (columnValue < minValue)
                    {
                        minValue = columnValue;
                    }
                    else if (columnValue > maxValue)
                    {
                        maxValue = columnValue;
                    }
                }
            }
            featureSource.Close();

            ValueCircleStyle valueCircleStyle = new ValueCircleStyle();

            valueCircleStyle.ColumnName         = SelectedColumns[0];
            valueCircleStyle.DrawingRadiusRatio = radiusRatio;
            valueCircleStyle.MinValidValue      = minValue;
            valueCircleStyle.MaxValidValue      = maxValue;
            valueCircleStyle.MinCircleAreaInDefaultZoomLevel = 80;
            valueCircleStyle.MaxCircleAreaInDefaultZoomLevel = 10000;
            valueCircleStyle.InnerColor = GeoColor.FromArgb(this.Opacity, Color);
            valueCircleStyle.OuterColor = GeoColor.SimpleColors.White;

            return(new Collection <Style>()
            {
                valueCircleStyle
            });
        }
Exemplo n.º 22
0
        private void btnRoute_Click(object sender, EventArgs e)
        {
            Algorithm         algorithm     = new AStarAlgorithm();
            RoutingSource     routingSource = new CustomRoutingSource(new ShapeFileFeatureSource(@"..\..\App_Data\Austinstreets.shp"));
            Collection <Road> pathIDs       = algorithm.GetShortestPath(routingSource, txtStartId.Text, txtEndId.Text);

            Collection <Feature> features = new Collection <Feature>();
            Dictionary <string, ShapeFileFeatureSource> featureSources = new Dictionary <string, ShapeFileFeatureSource>();

            for (int i = 0; i < pathIDs.Count; i++)
            {
                FeatureSource featureSource = routingSource.GetFeatureSourceByroadId(pathIDs[i].Id);
                featureSource.Open();
                features.Add(featureSource.GetFeatureById(routingSource.GetFeatureIdByroadId(pathIDs[i].Id).ToString(), ReturningColumnsType.NoColumns));
                featureSource.Close();
            }

            winformsMap1.Overlays["RoutingOverlay"].Lock.EnterWriteLock();
            try
            {
                InMemoryFeatureLayer inmemoryLayer = (InMemoryFeatureLayer)((LayerOverlay)winformsMap1.Overlays["RoutingOverlay"]).Layers["RoutingLayer"];
                inmemoryLayer.InternalFeatures.Clear();

                foreach (Feature feature in features)
                {
                    inmemoryLayer.InternalFeatures.Add(feature);
                }

                inmemoryLayer.Open();
                winformsMap1.CurrentExtent = inmemoryLayer.GetBoundingBox();
                inmemoryLayer.Close();
            }
            finally
            {
                winformsMap1.Overlays["RoutingOverlay"].Lock.ExitWriteLock();
            }

            winformsMap1.Refresh();
        }
Exemplo n.º 23
0
        public static void SafeProcess <T>(this FeatureSource featureSource, Action <T> processAction, T parameter)
        {
            lock (featureSource)
            {
                bool isClosed = false;
                if (!featureSource.IsOpen)
                {
                    featureSource.Open();
                    isClosed = true;
                }

                if (processAction != null)
                {
                    processAction(parameter);
                }

                if (isClosed)
                {
                    featureSource.Close();
                }
            }
        }
Exemplo n.º 24
0
        private void Algorithm_FindingPath(object sender, FindingRouteRoutingAlgorithmEventArgs e)
        {
            Collection <string> beContainedFeatureIds = new Collection <string>();

            featureSource.Open();
            Collection <string> startPointAdjacentIds = e.RouteSegment.StartPointAdjacentIds;
            Collection <string> endPointAdjacentIds   = e.RouteSegment.EndPointAdjacentIds;

            featureSource.Close();

            foreach (string id in startPointAdjacentIds)
            {
                if (!allowFeatureIds.Contains(id))
                {
                    beContainedFeatureIds.Add(id);
                }
            }
            foreach (string id in endPointAdjacentIds)
            {
                if (!allowFeatureIds.Contains(id))
                {
                    beContainedFeatureIds.Add(id);
                }
            }

            // Remove the ones that be contained in the avoidable area
            foreach (string id in beContainedFeatureIds)
            {
                if (e.RouteSegment.StartPointAdjacentIds.Contains(id))
                {
                    e.RouteSegment.StartPointAdjacentIds.Remove(id);
                }
                if (e.RouteSegment.EndPointAdjacentIds.Contains(id))
                {
                    e.RouteSegment.EndPointAdjacentIds.Remove(id);
                }
            }
        }
        protected override Collection <Style> GetStylesCore(FeatureSource featureSource)
        {
            // here we generated a class break style and a text style.
            Collection <GeoColor> familyColors = GeoColor.GetColorsInQualityFamily(Color, EndColor, classBreakCount, ColorWheelDirection);

            featureSource.Open();
            int featureCount = featureSource.GetCount();

            double[] values = new double[featureCount];
            for (int i = 0; i < featureCount; i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double  columnValue;
                if (double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue))
                {
                    values[i] = columnValue;
                }
            }
            featureSource.Close();

            ClassBreakStyle classBreakStyle = new ClassBreakStyle(SelectedColumns[0])
            {
                BreakValueInclusion = BreakValueInclusion.IncludeValue
            };

            double[] classBreakValues = GetClusterClassBreaks(values, ClassBreakCount - 1);
            for (int i = 0; i < classBreakValues.Length; i++)
            {
                ClassBreak classBreak = new ClassBreak(classBreakValues[i], AreaStyles.CreateSimpleAreaStyle(new GeoColor(this.Opacity, familyColors[i]), GeoColor.FromHtml("#f05133"), 1));
                classBreakStyle.ClassBreaks.Add(classBreak);
            }

            return(new Collection <Style>()
            {
                classBreakStyle, TextStyles.CreateSimpleTextStyle("NAME", "Arial", 8, DrawingFontStyles.Bold, GeoColor.StandardColors.Black, GeoColor.StandardColors.White, 3)
            });
        }
        protected override Collection<Style> GetStylesCore(FeatureSource featureSource)
        {
            // here we generate a ValueCircle Style.
            double minValue = double.MaxValue;
            double maxValue = double.MinValue;

            featureSource.Open();
            for (int i = 0; i < featureSource.GetCount(); i++)
            {
                Feature feature = featureSource.GetFeatureById((i + 1).ToString(CultureInfo.InvariantCulture), SelectedColumns);
                double columnValue;
                if (double.TryParse(feature.ColumnValues[SelectedColumns[0]], out columnValue))
                {
                    if (columnValue < minValue)
                    {
                        minValue = columnValue;
                    }
                    else if (columnValue > maxValue)
                    {
                        maxValue = columnValue;
                    }
                }
            }
            featureSource.Close();

            ValueCircleStyle valueCircleStyle = new ValueCircleStyle();
            valueCircleStyle.ColumnName = SelectedColumns[0];
            valueCircleStyle.DrawingRadiusRatio = radiusRatio;
            valueCircleStyle.MinValidValue = minValue;
            valueCircleStyle.MaxValidValue = maxValue;
            valueCircleStyle.MinCircleAreaInDefaultZoomLevel = 80;
            valueCircleStyle.MaxCircleAreaInDefaultZoomLevel = 10000;
            valueCircleStyle.InnerColor = GeoColor.FromArgb(this.Opacity, Color);
            valueCircleStyle.OuterColor = GeoColor.SimpleColors.White;

            return new Collection<Style>(){valueCircleStyle};
        }
        public static void SafeProcess(this FeatureSource featureSource, Action process)
        {
            bool isClosed = false;

            if (!featureSource.IsOpen)
            {
                featureSource.Open();
                isClosed = true;
            }

            if (process != null)
            {
                process();
            }

            if (isClosed)
            {
                featureSource.Close();
                if (featureSource.Projection != null)
                {
                    featureSource.Projection.Close();
                }
            }
        }
Exemplo n.º 28
0
        private void Split()
        {
            try
            {
                var args = new UpdatingProgressLongRunningTaskPluginEventArgs(LongRunningTaskState.Updating);

                featureSource.Open();
                Collection <Feature> allFeatures = featureSource.GetAllFeatures(ReturningColumnsType.AllColumns);
                var columns = featureSource.GetColumns();
                featureSource.Close();

                var featuresGroups = allFeatures.GroupBy(tmpFeature
                                                         => tmpFeature.ColumnValues[splitColumnName]);

                int i     = 0;
                int count = exportConfigs.Count;
                exportConfigs.ForEach(config =>
                {
                    string folderName = outputPath;
                    string fileName   = config.Value;
                    if (String.IsNullOrEmpty(fileName))
                    {
                        fileName = String.Format(CultureInfo.InvariantCulture, "{0}_{1}.shp", layerName, config.Key);
                    }

                    if (!fileName.EndsWith(".shp", StringComparison.OrdinalIgnoreCase))
                    {
                        fileName += ".shp";
                    }

                    string finalShapeFilePath = Path.Combine(folderName, fileName);

                    if (File.Exists(finalShapeFilePath) && overwriteOutputFiles)
                    {
                        //CloseExistingLayersAndCollectOverlaysToRefresh(this, finalShapeFilePath);
                        RemoveShapeFile(finalShapeFilePath);
                    }

                    //this.OutputShapeFileNames.Add(finalShapeFilePath);
                    var featureGroup = featuresGroups.FirstOrDefault(group => group.Key == config.Key);
                    if (featureGroup != null)
                    {
                        ShpFileExporter exporter = new ShpFileExporter();
                        exporter.ExportToFile(new FileExportInfo(featureGroup, columns, finalShapeFilePath, wkt));
                    }

                    args.Message = String.Format(CultureInfo.InvariantCulture, "Building... ({0}/{1})", ++i, count);
                    OnUpdatingProgress(args);
                });
            }
            catch (Exception ex)
            {
                //HandleExceptionFromInvalidFeature(feature.Id, ex.Message);
            }
            finally
            {
                //this.IsBusy = false;
                //this.BusyContent = String.Empty;
                //this.CurrentThread = null;
            }
        }
Exemplo n.º 29
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.º 30
0
        public virtual void ImportData(FeatureSource featureSourceForRead, FeatureSource featureSourceForSave)
        {
            bool readCompleted = false;

            featureSourceForRead.Open();
            featureSourceForSave.Open();
#if DEBUG
            long featureCount = featureSourceForRead.GetCount();
#endif
            Collection <Feature> features = featureSourceForRead.GetAllFeatures(ReturningColumnsType.AllColumns);
            Collection <Collection <Feature> > featureGroups = GroupFeatures(features);
            var writeTasks = (from items in featureGroups
                              select Task.Factory.StartNew(() => WriteFeaturesIntoQueue(items, featureSourceForRead))).ToArray();


            var readTask = Task.Factory.StartNew(() =>
            {
                while (!readCompleted || queue.Count > 0)
                {
                    while (queue.Count > 0)
                    {
                        Collection <Feature> lineFeatures = queue.Dequeue();
                        SaveFeatures(lineFeatures, featureSourceForSave);
                    }
                }
            });

            Task.WaitAll(writeTasks);
            readCompleted = true;
            Task.WaitAny(readTask);
            #region Old version
            //foreach (Feature feature in features)
            //{
            //    Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
            //    // Get the lineshape of the processing feature.
            //    foreach (LineShape processingLineShape in processingLineShapes)
            //    {
            //        // Define a variable to save the points where the adjacent lines intersect with current processing line.
            //        Collection<PointShape> crossingPoints = new Collection<PointShape>();

            //        // Get all the lines in current processing shape bounds.
            //        Collection<Feature> adjacentFeatures = featureSourceForRead.GetFeaturesInsideBoundingBox(processingLineShape.GetBoundingBox(), ReturningColumnsType.NoColumns);

            //        // Loop and see if the queried shape is intersected with processing shape.
            //        foreach (Feature adjacentFeature in adjacentFeatures)
            //        {
            //            LineBaseShape adjacentLineShape = adjacentFeature.GetShape() as LineBaseShape;
            //            MultipointShape tempCrossingPoints = processingLineShape.GetCrossing(adjacentLineShape);

            //            // The queried shape is intersected with processing shape.
            //            foreach (PointShape point in tempCrossingPoints.Points)
            //            {
            //                bool hasAdded = false;
            //                foreach (var item in crossingPoints)
            //                {
            //                    if (point.X == item.X && point.Y == item.Y)
            //                    {
            //                        hasAdded = true;
            //                        break;
            //                    }
            //                }
            //                if (!hasAdded)
            //                {
            //                    crossingPoints.Add(point);
            //                }
            //            }
            //        }

            //        // Order the crossing points following the sequence of line vertex.
            //        Collection<FlagedVertex> vertecesOfNewLine = GeometryHelper.AddCrossingPointToLine(processingLineShape, crossingPoints);

            //        // Split current processing lineshape into segments.
            //        featureSourceForSave.BeginTransaction();
            //        Collection<Vertex> verteces = new Collection<Vertex>();
            //        foreach (var vertex in vertecesOfNewLine)
            //        {
            //            verteces.Add(vertex.Vertex);
            //            if (vertex.Flag)
            //            {
            //                if (verteces.Count >= 2)
            //                {
            //                    LineShape segment = new LineShape(verteces);
            //                    featureSourceForSave.AddFeature(new Feature(segment, feature.ColumnValues));

            //                    verteces.RemoveAt(0);
            //                }
            //            }
            //        }
            //        featureSourceForSave.CommitTransaction();
            //    }

            //#if DEBUG
            //Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, featureCount));
            //#endif
            //}

            #endregion
            featureSourceForRead.Close();
            featureSourceForSave.Close();
        }
Exemplo n.º 31
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);
            }
        }
Exemplo n.º 32
0
 protected override void OpenCore()
 {
     base.OpenCore();
     featureSource.Open();
 }
Exemplo n.º 33
0
        public virtual void ImportData(FeatureSource featureSourceForRead, FeatureSource featureSourceForSave)
        {
            bool readCompleted = false;
            featureSourceForRead.Open();
            featureSourceForSave.Open();
            #if DEBUG
            long featureCount = featureSourceForRead.GetCount();
            #endif
            Collection<Feature> features = featureSourceForRead.GetAllFeatures(ReturningColumnsType.AllColumns);
            Collection<Collection<Feature>> featureGroups = GroupFeatures(features);
            var writeTasks = (from items in featureGroups
                              select Task.Factory.StartNew(() => WriteFeaturesIntoQueue(items, featureSourceForRead))).ToArray();

            var readTask = Task.Factory.StartNew(() =>
            {
                while (!readCompleted || queue.Count > 0)
                {
                    while (queue.Count > 0)
                    {
                        Collection<Feature> lineFeatures = queue.Dequeue();
                        SaveFeatures(lineFeatures, featureSourceForSave);
                    }
                }
            });

            Task.WaitAll(writeTasks);
            readCompleted = true;
            Task.WaitAny(readTask);
            #region Old version
            //foreach (Feature feature in features)
            //{
            //    Collection<LineShape> processingLineShapes = GeometryHelper.GetLineShapes(feature);
            //    // Get the lineshape of the processing feature.
            //    foreach (LineShape processingLineShape in processingLineShapes)
            //    {
            //        // Define a variable to save the points where the adjacent lines intersect with current processing line.
            //        Collection<PointShape> crossingPoints = new Collection<PointShape>();

            //        // Get all the lines in current processing shape bounds.
            //        Collection<Feature> adjacentFeatures = featureSourceForRead.GetFeaturesInsideBoundingBox(processingLineShape.GetBoundingBox(), ReturningColumnsType.NoColumns);

            //        // Loop and see if the queried shape is intersected with processing shape.
            //        foreach (Feature adjacentFeature in adjacentFeatures)
            //        {
            //            LineBaseShape adjacentLineShape = adjacentFeature.GetShape() as LineBaseShape;
            //            MultipointShape tempCrossingPoints = processingLineShape.GetCrossing(adjacentLineShape);

            //            // The queried shape is intersected with processing shape.
            //            foreach (PointShape point in tempCrossingPoints.Points)
            //            {
            //                bool hasAdded = false;
            //                foreach (var item in crossingPoints)
            //                {
            //                    if (point.X == item.X && point.Y == item.Y)
            //                    {
            //                        hasAdded = true;
            //                        break;
            //                    }
            //                }
            //                if (!hasAdded)
            //                {
            //                    crossingPoints.Add(point);
            //                }
            //            }
            //        }

            //        // Order the crossing points following the sequence of line vertex.
            //        Collection<FlagedVertex> vertecesOfNewLine = GeometryHelper.AddCrossingPointToLine(processingLineShape, crossingPoints);

            //        // Split current processing lineshape into segments.
            //        featureSourceForSave.BeginTransaction();
            //        Collection<Vertex> verteces = new Collection<Vertex>();
            //        foreach (var vertex in vertecesOfNewLine)
            //        {
            //            verteces.Add(vertex.Vertex);
            //            if (vertex.Flag)
            //            {
            //                if (verteces.Count >= 2)
            //                {
            //                    LineShape segment = new LineShape(verteces);
            //                    featureSourceForSave.AddFeature(new Feature(segment, feature.ColumnValues));

            //                    verteces.RemoveAt(0);
            //                }
            //            }
            //        }
            //        featureSourceForSave.CommitTransaction();
            //    }

            //#if DEBUG
            //Console.WriteLine(string.Format("Done {0} in {1}", feature.Id, featureCount));
            //#endif
            //}

            #endregion
            featureSourceForRead.Close();
            featureSourceForSave.Close();
        }