protected override void Execute()
        {
            if (Geometry is Point p1)
            {
                var point = new EsriJson.Net.Geometry.Point(p1.X, p1.Y);

                if (Transformer is not null)
                {
                    (var x, var y) = Transformer.MathTransform.Transform(point.X, point.Y);

                    point.X = x;
                    point.Y = y;
                }

                point.CRS = new Crs
                {
                    WellKnownId = WkId
                };

                Result = point;

                return;
            }

            var ringPoints = new List <EsriJson.Net.Geometry.RingPoint[]>();

            if (Geometry is MultiPolygon multiPolygon)
            {
                foreach (var p in multiPolygon.Geometries)
                {
                    ringPoints.AddRange(ExtractRings(p as Polygon));
                }
            }
            else if (Geometry is Polygon polygon)
            {
                ringPoints = ExtractRings(polygon);
            }

            var poly = new EsriJson.Net.Geometry.Polygon(ringPoints)
            {
                CRS = new Crs
                {
                    WellKnownId = WkId
                }
            };

            Result = poly;
        }
Exemplo n.º 2
0
        public async Task Should_convert_to_esri_graphic()
        {
            var responseContainer = new ApiResponseContainer <GeocodeAddressApiResponse> {
                Result = new GeocodeAddressApiResponse {
                    Candidates   = new Candidate[0],
                    InputAddress = "Input Address",
                    Location     = new Point {
                        X = 1,
                        Y = 1
                    },
                    Locator      = "Centerlines",
                    MatchAddress = "Matched Address",
                    Score        = 100,
                    Wkid         = 26912
                },
                Status = 200
            };

            var request = new EsriGraphic.Command(responseContainer);
            var result  = await _handler.Handle(request, new CancellationToken());

            var point = new EsriJson.Net.Geometry.Point(1, 1)
            {
                CRS = new Crs {
                    WellKnownId = 26912
                }
            };

            var attributes = new Dictionary <string, object> {
                { "location", new Point(1, 1) },
                { "score", 100.0 },
                { "locator", "Centerlines" },
                { "matchAddress", "Matched Address" },
                { "inputAddress", "Input Address" },
                { "scoreDifference", 0.0 }
            };

            var graphic    = JsonConvert.SerializeObject(new Graphic(point, attributes));
            var resultJson = JsonConvert.SerializeObject(result.Result);

            resultJson.ShouldBe(graphic);
        }