public void LargeGeoJson_Lines(TestImageProvider <Rgba32> provider, string geoJsonFile, int aa, float sx, float sy)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(geoJsonFile));

            PointF[][] points = PolygonFactory.GetGeoJsonPoints(jsonContent, Matrix3x2.CreateScale(sx, sy));

            using Image <Rgba32> image = provider.GetImage();
            var options = new DrawingOptions()
            {
                GraphicsOptions = new GraphicsOptions()
                {
                    Antialias = aa > 0, AntialiasSubpixelDepth = aa
                },
            };

            foreach (PointF[] loop in points)
            {
                image.Mutate(c => c.DrawLines(options, Color.White, 1.0f, loop));
            }

            string details = $"_{System.IO.Path.GetFileName(geoJsonFile)}_{sx}x{sy}_aa{aa}";

            image.DebugSave(
                provider,
                details,
                appendPixelTypeToFileName: false,
                appendSourceFileOrDescription: false);
        }
        public void LargeGeoJson_Mississippi_Lines(TestImageProvider <Rgba32> provider, int pixelOffset)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(TestImages.GeoJson.States));

            FeatureCollection features = JsonConvert.DeserializeObject <FeatureCollection>(jsonContent);

            Feature missisipiGeom = features.Features.Single(f => (string)f.Properties["NAME"] == "Mississippi");

            Matrix3x2 transform = Matrix3x2.CreateTranslation(-87, -54)
                                  * Matrix3x2.CreateScale(60, 60)
                                  * Matrix3x2.CreateTranslation(pixelOffset, pixelOffset);
            IReadOnlyList <PointF[]> points = PolygonFactory.GetGeoJsonPoints(missisipiGeom, transform);

            using Image <Rgba32> image = provider.GetImage();

            foreach (PointF[] loop in points)
            {
                image.Mutate(c => c.DrawLines(Color.White, 1.0f, loop));
            }

            // Very strict tolerance, since the image is sparse (relaxed on .NET Framework)
            ImageComparer comparer = TestEnvironment.IsFramework
                ? ImageComparer.TolerantPercentage(1e-3f)
                : ImageComparer.TolerantPercentage(1e-7f);

            string details = $"PixelOffset({pixelOffset})";

            image.DebugSave(provider, details, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
            image.CompareToReferenceOutput(comparer, provider, testOutputDetails: details, appendPixelTypeToFileName: false, appendSourceFileOrDescription: false);
        }
        private Image <Rgba32> FillGeoJsonPolygons(TestImageProvider <Rgba32> provider, string geoJsonFile, int aa, Vector2 scale, Vector2 pixelOffset)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(geoJsonFile));

            PointF[][] points = PolygonFactory.GetGeoJsonPoints(jsonContent, Matrix3x2.CreateScale(scale) * Matrix3x2.CreateTranslation(pixelOffset));

            Image <Rgba32> image   = provider.GetImage();
            var            options = new DrawingOptions()
            {
                GraphicsOptions = new GraphicsOptions()
                {
                    Antialias = aa > 0, AntialiasSubpixelDepth = aa
                },
            };
            var rnd = new Random(42);

            byte[] rgb = new byte[3];
            foreach (PointF[] loop in points)
            {
                rnd.NextBytes(rgb);

                var color = Color.FromRgb(rgb[0], rgb[1], rgb[2]);
                image.Mutate(c => c.FillPolygon(options, color, loop));
            }

            return(image);
        }
            static PointF[][] GetPoints(FeatureCollection features)
            {
                Feature state = features.Features.Single(f => (string)f.Properties["NAME"] == "Mississippi");

                Matrix3x2 transform = Matrix3x2.CreateTranslation(-87, -54)
                                      * Matrix3x2.CreateScale(60, 60);

                return(PolygonFactory.GetGeoJsonPoints(state, transform).ToArray());
            }
        protected override PointF[][] GetPoints(FeatureCollection features)
        {
            Feature state = features.Features.Single(f => (string)f.Properties["NAME"] == "Utah");

            Matrix3x2 transform = Matrix3x2.CreateTranslation(-60, -40)
                                  * Matrix3x2.CreateScale(60, 60);

            return(PolygonFactory.GetGeoJsonPoints(state, transform).ToArray());
        }
        public void Missisippi_Skia(int offset)
        {
            string jsonContent = File.ReadAllText(TestFile.GetInputFileFullPath(TestImages.GeoJson.States));

            FeatureCollection features = JsonConvert.DeserializeObject <FeatureCollection>(jsonContent);

            Feature missisipiGeom = features.Features.Single(f => (string)f.Properties["NAME"] == "Mississippi");

            Matrix3x2 transform = Matrix3x2.CreateTranslation(-87, -54)
                                  * Matrix3x2.CreateScale(60, 60)
                                  * Matrix3x2.CreateTranslation(offset, offset);
            IReadOnlyList <PointF[]> points = PolygonFactory.GetGeoJsonPoints(missisipiGeom, transform);

            var path = new SKPath();

            foreach (PointF[] pts in points.Where(p => p.Length > 2))
            {
                path.MoveTo(pts[0].X, pts[0].Y);

                for (int i = 0; i < pts.Length; i++)
                {
                    path.LineTo(pts[i].X, pts[i].Y);
                }

                path.LineTo(pts[0].X, pts[0].Y);
            }

            var imageInfo = new SKImageInfo(10000, 10000);

            using var paint = new SKPaint
                  {
                      Style       = SKPaintStyle.Stroke,
                      Color       = SKColors.White,
                      StrokeWidth = 1f,
                      IsAntialias = true,
                  };

            using var surface = SKSurface.Create(imageInfo);
            SKCanvas canvas = surface.Canvas;

            canvas.Clear(new SKColor(0, 0, 0));
            canvas.DrawPath(path, paint);

            string outDir = TestEnvironment.CreateOutputDirectory("Skia");
            string fn     = System.IO.Path.Combine(outDir, $"Missisippi_Skia_{offset}.png");

            using SKImage image = surface.Snapshot();
            using SKData data   = image.Encode(SKEncodedImageFormat.Png, 100);

            using FileStream fs = File.Create(fn);
            data.SaveTo(fs);
        }
 protected virtual PointF[][] GetPoints(FeatureCollection features)
 => features.Features
 .SelectMany(f => PolygonFactory.GetGeoJsonPoints(f, Matrix3x2.CreateScale(60, 60)))
 .ToArray();