Inheritance: IFeatures
Esempio n. 1
0
        public static MemoryProvider CreateProviderWithPointsWithSymbolStyles()
        {
            const string circleIconPath = @"Mapsui.Tests.Common.Resources.Images.circle.png";
            var circleIcon = typeof(Utilities).Assembly.GetManifestResourceStream(circleIconPath);
            var circleIconId = BitmapRegistry.Instance.Register(circleIcon);
            const string checkeredIconPath = @"Mapsui.Tests.Common.Resources.Images.checkered.png";
            var checkeredIcon = typeof(Utilities).Assembly.GetManifestResourceStream(checkeredIconPath);
            var checkeredIconId = BitmapRegistry.Instance.Register(checkeredIcon);

            var features = new Features
            {
                new Feature
                {
                    Geometry = new Point(50, 50),
                    Styles = new[] { new VectorStyle { Fill = new Brush(Color.Red) }}
                },
                new Feature
                {
                    Geometry = new Point(50, 100),
                    Styles = new[] { new SymbolStyle { BitmapId = circleIconId }}
                },
                new Feature
                {
                    Geometry = new Point(100, 50),
                    Styles = new[] { new SymbolStyle { BitmapId = checkeredIconId }}
                },
                new Feature
                {
                    Geometry = new Point(100, 100),
                    Styles = new[] { new VectorStyle { Fill = new Brush(Color.Green), Outline = null }}
                }
            };
            var provider = new MemoryProvider(features);
            return provider;
        }
Esempio n. 2
0
        public IEnumerable<IFeature> FetchTiles(BoundingBox boundingBox, double resolution)
        {
            var extent = new Extent(boundingBox.Min.X, boundingBox.Min.Y, boundingBox.Max.X, boundingBox.Max.Y);
            var levelId = BruTile.Utilities.GetNearestLevel(_source.Schema.Resolutions, resolution);
            var infos = _source.Schema.GetTileInfos(extent, levelId).ToList();

            ICollection<WaitHandle> waitHandles = new List<WaitHandle>();
                        
            foreach (TileInfo info in infos)    
            {
                if (_bitmaps.Find(info.Index) != null) continue;
                if (_queue.Contains(info.Index)) continue;
                var waitHandle = new AutoResetEvent(false);
                waitHandles.Add(waitHandle);
                _queue.Add(info.Index);
                ThreadPool.QueueUserWorkItem(GetTileOnThread, new object[] { _source, info, _bitmaps, waitHandle });
            }

            WaitHandle.WaitAll(waitHandles.ToArray());
            
            IFeatures features = new Features();
            foreach (TileInfo info in infos)
            {
                byte[] bitmap = _bitmaps.Find(info.Index);
                if (bitmap == null) continue;
                IRaster raster = new Raster(new MemoryStream(bitmap), new BoundingBox(info.Extent.MinX, info.Extent.MinY, info.Extent.MaxX, info.Extent.MaxY));
                IFeature feature = features.New();
                feature.Geometry = raster;
                features.Add(feature);
            }
            return features;
        }
Esempio n. 3
0
 public static MemoryProvider CreateProviderWithPointsWithVectorStyle()
 {
     var features = new Features
     {
         new Feature
         {
             Geometry = new Point(50, 50),
             Styles = new[] {new VectorStyle {Fill = new Brush(Color.Red)}}
         },
         new Feature
         {
             Geometry = new Point(50, 100),
             Styles = new[] {new VectorStyle {Fill = new Brush(Color.Yellow), Outline = new Pen(Color.Black, 2)}}
         },
         new Feature
         {
             Geometry = new Point(100, 50),
             Styles = new[] {new VectorStyle {Fill = new Brush(Color.Blue), Outline = new Pen(Color.White, 2)}}
         },
         new Feature
         {
             Geometry = new Point(100, 100),
             Styles = new[] {new VectorStyle {Fill = new Brush(Color.Green), Outline = null}}
         }
     };
     var provider = new MemoryProvider(features);
     return provider;
 }
Esempio n. 4
0
 private void RenderToRaster(IViewport viewport, ILayer layer, out IFeatures features)
 {
     var canvas = new Canvas();
     MapRenderer.RenderLayer(canvas, viewport, layer);
     canvas.UpdateLayout();
     var bitmap = BitmapRendering.BitmapConverter.ToBitmapStream(canvas, viewport.Width, viewport.Height);
     features = new Features { new Feature { Geometry = new Raster(bitmap, viewport.Extent) } };
 }
Esempio n. 5
0
 private static Features CreateFeatures(IEnumerable<IGeometry> randomPoints)
 {
     var features = new Features();
     var counter = 0;
     foreach (var point in randomPoints)
     {
         features.Add(new Feature { Geometry = point, ["Label"] = counter++.ToString() });
     }
     return features;
 }
Esempio n. 6
0
 private static MemoryProvider CreateRandomPointsProvider(BoundingBox box)
 {
     var randomPoints = PointLayerSample.GenerateRandomPoints(box, 200);
     var features = new Features();
     var count = 0;
     foreach (var point in randomPoints)
     {
         var feature = new Feature { Geometry = point };
         feature["Label"] = count.ToString(CultureInfo.InvariantCulture);
         features.Add(feature);
         count++;
     }
     return new MemoryProvider(features);
 }
        public System.Collections.Generic.IEnumerable<IFeature> GetFeaturesInView(BoundingBox box, double resolution)
        {
            var features = new Features();

            IRaster raster = null;
            var view = new Viewport { Resolution = resolution, Center = box.GetCentroid(), Width = (box.Width / resolution), Height = (box.Height / resolution) };
            if (TryGetMap(view, ref raster))
            {
                IFeature feature = features.New();
                feature.Styles.Add(new VectorStyle()); // this is not my fault
                feature.Geometry = raster;
                features.Add(feature);
            }
            return features;
        }
 private static IProvider CreateProviderWithRotatedBitmapSymbols()
 {
     var features = new Features
     {
         new Feature
         {
             Geometry = new Point(75, 75),
             Styles = new[] {new SymbolStyle {Fill = new Brush(Color.Red)}}
         }, // for reference
         CreateFeatureWithRotatedBitmapSymbol(75, 125, 90),
         CreateFeatureWithRotatedBitmapSymbol(125, 125, 180),
         CreateFeatureWithRotatedBitmapSymbol(125, 75, 270)
     };
     return new MemoryProvider(features);
 }
 public static Map PointsWithDifferentSymbolTypes()
 {
     var map = new Map { Viewport = { Center = new Point(0, 0), Width = 200, Height = 100, Resolution = 0.5 } };
     var features = new Features
     {
         Utilities.CreateSimplePointFeature(-20, 0, new SymbolStyle {Fill = new Brush { Color = Color.Gray}, Outline = new Pen(Color.Black), SymbolType = SymbolType.Ellipse}),
         Utilities.CreateSimplePointFeature(20, 0, new SymbolStyle {Fill = new Brush { Color = Color.Gray}, Outline = new Pen(Color.Black), SymbolType = SymbolType.Rectangle})
     };
     var layer = new MemoryLayer
     {
         DataSource = new MemoryProvider(features),
         Name = "Points with different symbol types"
     };
     map.Layers.Add(layer);
     return map;
 }
Esempio n. 10
0
 private static MemoryProvider CreateRandomPointsProvider(IEnumerable<IGeometry> randomPoints)
 {
     var features = new Features();
     var count = 0;
     foreach (var point in randomPoints)
     {
         var feature = new Feature
         {
             Geometry = point,
             [LabelColumn] = count.ToString(CultureInfo.InvariantCulture)
         };
         features.Add(feature);
         count++;
     }
     return new MemoryProvider(features);
 }
Esempio n. 11
0
 private static MemoryProvider CreateProviderWithLabels()
 {
     var features = new Features
     {
         new Feature
         {
             Geometry = new Point(50, 50),
             Styles = new[] {new VectorStyle {Fill = new Brush(Color.Gray), Outline = new Pen(Color.Black)}}
         },
         new Feature
         {
             Geometry = new Point(50, 150),
             Styles = new[] {new LabelStyle {Text = "Black Text", BackColor = null}}
         },
         new Feature
         {
             Geometry = new Point(150, 50),
             Styles =
                 new[]
                 {
                     new LabelStyle
                     {
                         Text = "Gray Backcolor",
                         BackColor = new Brush(Color.Gray),
                         ForeColor = Color.White
                     }
                 }
         },
         new Feature
         {
             Geometry = new Point(150, 150),
             Styles =
                 new[]
                 {
                     new LabelStyle
                     {
                         Text = "Black Halo",
                         ForeColor = Color.White,
                         Halo = new Pen(Color.Red),
                         BackColor = null
                     }
                 }
         }
     };
     var provider = new MemoryProvider(features);
     return provider;
 }
Esempio n. 12
0
        public static IEnumerable<IFeature> DataSetToFeatures(FeatureDataSet dataSet)
        {
            var features = new Features();

            foreach (FeatureDataTable table in dataSet.Tables)
            {
                foreach (FeatureDataRow row in table)
                {
                    IFeature feature = features.New();
                    feature.Geometry = row.Geometry;
                    foreach (DataColumn column in table.Columns)
                        feature[column.ColumnName] = row[column.ColumnName];

                    features.Add(feature);
                }
            }
            return features;
        }
Esempio n. 13
0
            public void DeleteFeatureReferenceType()
            {
                // Arrange
                const string keyField = "thekeyfield";
                var features = new Features(keyField);

                var feature1 = new Feature();
                feature1[keyField] = "a";
                features.Add(feature1);

                var feature2 = new Feature();
                feature2[keyField] = "b";
                features.Add(feature2);

                // Act
                var first = features.First(f => f[keyField].Equals("a"));
                features.Delete(first[keyField]);

                // Assert
                Assert.IsFalse(features.Any(f => f[keyField].Equals("a")));
            }
Esempio n. 14
0
        public static void RenderSymbolWithUnitTypes()
        {
            // arrange
            var viewport = new Viewport { Center = new Point(0, 0), Width = 200, Height = 100, Resolution = 0.5 };
            var features = new Features
                {
                    CreateFeature(-20, 0, new SymbolStyle {UnitType = UnitType.Pixel}),
                    CreateFeature(20, 0, new SymbolStyle {UnitType = UnitType.WorldUnit})
                };
            var layers = new[] { new InMemoryLayer(new MemoryProvider(features)) };
            var renderer = new MapRenderer();
            const string imagePath = ImagesFolder + "\\vector_symbol_unittype.png";
            
            // act
            renderer.Render(viewport, layers);
            var bitmap = renderer.ToBitmapStream(viewport.Width, viewport.Height);

            // aside
            if (Rendering.Default.WriteImageToDisk) WriteToDisk(imagePath, bitmap);

            // assert
            Assert.AreEqual(ReadFile(imagePath), bitmap.ToArray());
        }
Esempio n. 15
0
        public static Map CreateMap()
        {
            var features = new Features
            {
                CreateFeature(-20, 0, UnitType.Pixel),
                CreateFeature(20, 0, UnitType.WorldUnit)
            };

            var layer = new MemoryLayer
            {
                Style = null,
                DataSource = new MemoryProvider(features),
                Name = "Points in world units"
            };

            var map = new Map
            {
                BackColor = Color.Transparent,
                Viewport = {Center = new Point(0, 0), Width = 200, Height = 100, Resolution = 0.5}
            };
            map.Layers.Add(layer);
            return map;
        }
Esempio n. 16
0
        private static ILayer CreateMutatingTriangleLayer(BoundingBox envelope)
        {
            var layer = new MemoryLayer();

            var polygon = new Polygon(new LinearRing(GenerateRandomPoints(envelope, 3)));
            var feature = new Feature() { Geometry = polygon };
            var features = new Features();
            features.Add(feature);

            layer.DataSource = new MemoryProvider(features);

            PeriodicTask.Run(() =>
            {
                polygon.ExteriorRing = new LinearRing(GenerateRandomPoints(envelope, 3));
                // Clear cache for change to show
                feature.RenderedGeometry.Clear();
                // Trigger DataChanged notification
                layer.ViewChanged(true, layer.Envelope, 1);
            },
            TimeSpan.FromMilliseconds(1000));

            return layer;
        }
Esempio n. 17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryProvider"/>
 /// </summary>
 /// <param name="geometries">Set of geometries that this datasource should contain</param>
 public MemoryProvider(IEnumerable<IGeometry> geometries)
 {
     CRS = "";
     Features = new Features();
     foreach (IGeometry geometry in geometries)
     {
         IFeature feature = Features.New();
         feature.Geometry = geometry;
         Features.Add(feature);
     }
 }
Esempio n. 18
0
 public MemoryProvider()
 {
     CRS = "";
     Features = new Features();
 }
Esempio n. 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryProvider"/>
 /// </summary>
 /// <param name="geometry">Geometry to be in this datasource</param>
 public MemoryProvider(Geometry geometry)
 {
     CRS = "";
     Features = new Features();
     IFeature feature = Features.New();
     feature.Geometry = geometry;
     Features.Add(feature);
     SymbolSize = 64;
 }
Esempio n. 20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryProvider"/>
 /// </summary>
 /// <param name="features">Features to be included in this datasource</param>
 public MemoryProvider(IEnumerable<IFeature> features)
 {
     CRS = "";
     Features = new Features();
     foreach (var feature in features) Features.Add(feature);
 }
Esempio n. 21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryProvider"/>
 /// </summary>
 /// <param name="feature">Feature to be in this datasource</param>
 public MemoryProvider(IFeature feature)
 {
     SRID = -1;
     Features = new Features();
     Features.Add(feature);
 }
Esempio n. 22
0
 private MemoryProvider CreateRandomPointsProvider()
 {
     var randomPoints = PointLayerSample.GenerateRandomPoints(MapControl.Map.Envelope, 100);
     var features = new Features();
     var count = 0;
     foreach (var point in randomPoints)
     {
         var feature = new Feature { Geometry = point };
         feature["Label"] = count.ToString(CultureInfo.InvariantCulture);
         features.Add(feature);
         count++;
     }
     return new MemoryProvider(features);
 }
Esempio n. 23
0
 public MemoryProvider()
 {
     CRS      = "";
     Features = new Features();
 }
Esempio n. 24
0
 public MemoryProvider()
 {
     SRID = -1;
     Features = new Features();
 }
Esempio n. 25
0
        public IEnumerable<IFeature> GetFeaturesInView(BoundingBox box, double resolution)
        {
            //Use the spatial index to get a list of features whose boundingbox intersects bbox
            Collection<uint> objectlist = GetObjectIDsInView(box);
            IFeatures features = new Features();

            foreach (uint index in objectlist)
            {
                IFeature feature = dbaseFile.GetFeature(index, features);
                feature.Geometry = ReadGeometry(index);
                if (feature.Geometry != null)
                    if (feature.Geometry.GetBoundingBox().Intersects(box))
                        if (FilterDelegate == null || FilterDelegate(feature))
                            features.Add(feature);
            }
            return features;
        }
Esempio n. 26
0
 public IFeature Find(object value, string primaryKey)
 {
     return(Features.FirstOrDefault(f => f[primaryKey] != null && value != null &&
                                    f[primaryKey].Equals(value)));
 }
Esempio n. 27
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryProvider"/>
 /// </summary>
 /// <param name="feature">Feature to be in this datasource</param>
 public MemoryProvider(IFeature feature)
 {
     SRID     = -1;
     Features = new Features();
     Features.Add(feature);
 }
Esempio n. 28
0
 public MemoryProvider()
 {
     SRID     = -1;
     Features = new Features();
 }
Esempio n. 29
0
 public static Map PointsWithWorldUnits()
 {
     var map = new Map { Viewport = { Center = new Point(0, 0), Width = 200, Height = 100, Resolution = 0.5 } };
     var features = new Features
     {
         Utilities.CreateSimplePointFeature(-20, 0, new SymbolStyle {UnitType = UnitType.Pixel}),
         Utilities.CreateSimplePointFeature(20, 0, new SymbolStyle {UnitType = UnitType.WorldUnit})
     };
     var layer = new MemoryLayer { DataSource = new MemoryProvider(features), Name = "Points in world units"};
     map.Layers.Add(layer);
     return map;
 }
Esempio n. 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryProvider"/>
 /// </summary>
 /// <param name="feature">Feature to be in this datasource</param>
 public MemoryProvider(IFeature feature)
 {
     CRS = "";
     Features = new Features {feature};
 }
Esempio n. 31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MemoryProvider"/>
 /// </summary>
 /// <param name="geometry">Geometry to be in this datasource</param>
 public MemoryProvider(Geometry geometry)
 {
     SRID = -1;
     Features = new Features();
     IFeature feature = Features.New();
     feature.Geometry = geometry;
     Features.Add(feature);
 }
Esempio n. 32
0
        public IEnumerable<IFeature> GetFeaturesInView(BoundingBox box, double resolution)
        {
            lock (_syncRoot)
            {
                Open();
                try
                {
                    //Use the spatial index to get a list of features whose boundingbox intersects bbox
                    var objectlist = GetObjectIDsInView(box);
                    var features = new Features();

                    foreach (var index in objectlist)
                    {
                        var feature = _dbaseFile != null ? _dbaseFile.GetFeature(index, features) : new Feature();
                        feature.Geometry = ReadGeometry(index);
                        if (feature.Geometry == null) continue;
                        if (!feature.Geometry.GetBoundingBox().Intersects(box)) continue;
                        if (FilterDelegate != null && !FilterDelegate(feature)) continue;
                        features.Add(feature);
                    }
                    return features;
                }
                finally
                {
                    Close();
                }
            }
        }
Esempio n. 33
0
 /// <summary>
 /// Search for a feature
 /// </summary>
 /// <param name="value">Value to search for</param>
 /// <param name="fieldName">Name of the field to search in. This is the key of the T dictionary</param>
 /// <returns></returns>
 public IFeature?Find(object?value, string fieldName)
 {
     return(Features.FirstOrDefault(f => value != null && f[fieldName] == value));
 }