private Tms.Capabilities GetCapabilities()
        {
            var layers = EntitiesConverter.SourcesToLayers(this.tileSourceFabric.Sources);

            return(new Tms.Capabilities
            {
                ServiceTitle = this.tileSourceFabric.ServiceProperties.Title,
                ServiceAbstract = this.tileSourceFabric.ServiceProperties.Abstract,
                BaseUrl = this.BaseUrl,
                Layers = layers.ToArray(),
            });
        }
Example #2
0
        private static void DrawWebMercatorTilesToRasterCanvas(
            SKCanvas outputCanvas,
            int width,
            int height,
            Models.Bounds boundingBox,
            IList <Models.TileDataset> sourceTiles,
            uint backgroundColor,
            int tileSize)
        {
            var zoom         = sourceTiles[0].Z;
            var tileMinX     = sourceTiles.Min(t => t.X);
            var tileMinY     = sourceTiles.Min(t => t.Y);
            var tilesCountX  = sourceTiles.Max(t => t.X) - tileMinX + 1;
            var tilesCountY  = sourceTiles.Max(t => t.Y) - tileMinY + 1;
            var canvasWidth  = tilesCountX * tileSize;
            var canvasHeight = tilesCountY * tileSize;

            var imageInfo = new SKImageInfo(
                width: canvasWidth,
                height: canvasHeight,
                colorType: SKColorType.Rgba8888,
                alphaType: SKAlphaType.Premul);

            using var surface = SKSurface.Create(imageInfo);
            using var canvas  = surface.Canvas;
            canvas.Clear(new SKColor(backgroundColor));

            // Draw all tiles
            foreach (var sourceTile in sourceTiles)
            {
                var offsetX = (sourceTile.X - tileMinX) * tileSize;
                var offsetY = (sourceTile.Y - tileMinY) * tileSize;
                using var sourceImage = SKImage.FromEncodedData(sourceTile.ImageData);
                canvas.DrawImage(sourceImage, SKRect.Create(offsetX, offsetY, tileSize, tileSize)); // Source tile scaled to dest rectangle, if needed
            }

            // Clip and scale to requested size of output image
            var geoBBox         = EntitiesConverter.MapRectangleToGeographicalBounds(boundingBox);
            var pixelOffsetX    = WebMercator.LongitudeToPixelXAtZoom(geoBBox.MinLongitude, zoom) - tileSize * tileMinX;
            var pixelOffsetY    = WebMercator.LatitudeToPixelYAtZoom(geoBBox.MaxLatitude, zoom) - tileSize * tileMinY;
            var pixelWidth      = WebMercator.LongitudeToPixelXAtZoom(geoBBox.MaxLongitude, zoom) - WebMercator.LongitudeToPixelXAtZoom(geoBBox.MinLongitude, zoom);
            var pixelHeight     = WebMercator.LatitudeToPixelYAtZoom(geoBBox.MinLatitude, zoom) - WebMercator.LatitudeToPixelYAtZoom(geoBBox.MaxLatitude, zoom);
            var sourceRectangle = SKRect.Create((float)pixelOffsetX, (float)pixelOffsetY, (float)pixelWidth, (float)pixelHeight);
            var destRectangle   = SKRect.Create(0, 0, width, height);

            using SKImage canvasImage = surface.Snapshot();
            outputCanvas.DrawImage(canvasImage, sourceRectangle, destRectangle, new SKPaint {
                FilterQuality = SKFilterQuality.High,
            });
        }
Example #3
0
        public void ConvertUserEntityToUserDomainVerifiedByExpectedObjects()
        {
            //Given
            var expectedUserDomain = new UserDomain
            {
                Id      = 1,
                Name    = "Customer",
                Street  = "My street",
                ZipCode = "ZipCode",
                City    = "City",
                Orders  = new List <OrderDomain>
                {
                    new OrderDomain
                    {
                        OrderNumber  = "FA-10",
                        OrderDate    = new DateTime(2017, 5, 2),
                        OrderDetails = new List <OrderDetailDomain>
                        {
                            new OrderDetailDomain
                            {
                                ProductName = "Product 1",
                                Quantity    = 5,
                                UnitPrice   = 12.5,
                                Total       = 62.5
                            },
                            new OrderDetailDomain
                            {
                                ProductName = "Product 2",
                                Quantity    = 10,
                                UnitPrice   = 5.2,
                                Total       = 52.0
                            }
                        },
                        Total = 114.5
                    }
                }
            }.ToExpectedObject();

            //When
            UserDomain convertedUser = EntitiesConverter.Convert(_userEntity);

            //Then
            expectedUserDomain.ShouldEqual(convertedUser);
        }
Example #4
0
        public static List <Models.TileCoordinates> BuildTileCoordinatesList(Models.Bounds boundingBox, int width)
        {
            var geoBBox      = EntitiesConverter.MapRectangleToGeographicalBounds(boundingBox);
            var zoomLevel    = FindOptimalTileZoomLevel(width, geoBBox);
            var tileCoordMin = GetTileCoordinatesAtPoint(geoBBox.MinLongitude, geoBBox.MinLatitude, zoomLevel);
            var tileCoordMax = GetTileCoordinatesAtPoint(geoBBox.MaxLongitude, geoBBox.MaxLatitude, zoomLevel);

            var tileCoordinates = new List <Models.TileCoordinates>();

            for (var tileX = tileCoordMin.X; tileX <= tileCoordMax.X; tileX++)
            {
                for (var tileY = tileCoordMax.Y; tileY <= tileCoordMin.Y; tileY++)
                {
                    tileCoordinates.Add(new Models.TileCoordinates(tileX, tileY, zoomLevel));
                }
            }

            return(tileCoordinates);
        }
Example #5
0
        private IActionResult ProcessGetCapabilitiesRequest()
        {
            var layers = EntitiesConverter.SourcesToLayers(this.tileSourceFabric.Sources)
                         .Where(l => l.Format == ImageFormats.Png || l.Format == ImageFormats.Jpeg) // Only raster formats
                         .ToList();

            var xmlDoc = new CapabilitiesUtility(
                new Wmts.ServiceProperties
            {
                Title    = this.tileSourceFabric.ServiceProperties.Title,
                Abstract = this.tileSourceFabric.ServiceProperties.Abstract,
                Keywords = this.tileSourceFabric.ServiceProperties.KeywordsList,
            },
                BaseUrl + "/wmts",
                layers)
                         .GetCapabilities(); // TODO: fix base URL

            return(File(xmlDoc.ToUTF8ByteArray(), MediaTypeNames.Text.Xml));
        }
Example #6
0
        public void ConvertUserEntityToUserDomainVerifiedByClassicAssertions()
        {
            //Given
            var expectedUserDomain = new UserDomain
            {
                Id      = 1,
                Name    = "Customer",
                Street  = "My street",
                ZipCode = "ZipCode",
                City    = "City",
                Orders  = new OrderDomain[]
                {
                    new OrderDomain
                    {
                        OrderNumber  = "FA-10",
                        OrderDate    = new DateTime(2017, 5, 2),
                        OrderDetails = new List <OrderDetailDomain>
                        {
                            new OrderDetailDomain
                            {
                                ProductName = "Product 1",
                                Quantity    = 5,
                                UnitPrice   = 12.5,
                                Total       = 65.5
                            },
                            new OrderDetailDomain
                            {
                                ProductName = "Product 2",
                                Quantity    = 10,
                                UnitPrice   = 5.2,
                                Total       = 52.0
                            }
                        },
                        Total = 117.5
                    }
                }
            };

            //When
            UserDomain convertedUser = EntitiesConverter.Convert(_userEntity);

            //Then
            Assert.Equal(expectedUserDomain.Id, convertedUser.Id);
            Assert.Equal(expectedUserDomain.Name, convertedUser.Name);

            Assert.Equal(expectedUserDomain.Street, convertedUser.Street);
            Assert.Equal(expectedUserDomain.ZipCode, convertedUser.ZipCode);
            Assert.Equal(expectedUserDomain.City, convertedUser.City);

            Assert.Equal(expectedUserDomain.Orders.Count(), convertedUser.Orders.Count());

            var orderEntity = expectedUserDomain.Orders.First();
            var orderDomain = convertedUser.Orders.First();

            Assert.Equal(orderEntity.OrderNumber, orderDomain.OrderNumber);
            Assert.Equal(orderEntity.OrderDate, orderDomain.OrderDate);
            Assert.Equal(orderEntity.OrderDetails.Count(), orderDomain.OrderDetails.Count());

            var orderDetailEntity = orderEntity.OrderDetails.First();
            var orderDetailDomain = orderDomain.OrderDetails.First();

            Assert.Equal(orderDetailEntity.ProductName, orderDetailDomain.ProductName);
            Assert.Equal(orderDetailEntity.Quantity, orderDetailDomain.Quantity);
            Assert.Equal(orderDetailEntity.UnitPrice, orderDetailDomain.UnitPrice);
        }
Example #7
0
        public async Task <IActionResult> ProcessRequestAsync(
            string?service = null,
            string?request = null,
            string version = Identifiers.Version100,
            string?layer   = null,
#pragma warning disable IDE0060
            string style = "default", // Not used
#pragma warning restore IDE0060
            string format = MediaTypeNames.Image.Png,
            ////string tileMatrixSet = null,
            string?tileMatrix = null,
            int tileRow       = 0,
            int tileCol       = 0)
        {
            // TODO: check requirements of standard
            if ((String.Compare(service, Identifiers.WMTS, StringComparison.Ordinal) != 0) &&
                (String.Compare(service, Identifiers.WMS, StringComparison.Ordinal) != 0)) // QGIS compatibility
            {
                return(ResponseWithBadRequestError(Identifiers.MissingParameterValue, "SERVICE parameter is not defined"));
            }

            if (String.Compare(version, Identifiers.Version100, StringComparison.Ordinal) != 0)
            {
                return(ResponseWithBadRequestError(Identifiers.InvalidParameterValue, $"Invalid VERSION parameter value (must be {Identifiers.Version100})"));
            }

            if (String.Compare(request, Identifiers.GetCapabilities, StringComparison.Ordinal) == 0)
            {
                return(this.ProcessGetCapabilitiesRequest());
            }
            else if (String.Compare(request, Identifiers.GetTile, StringComparison.Ordinal) == 0)
            {
                if (String.IsNullOrEmpty(tileMatrix))
                {
                    return(ResponseWithBadRequestError(Identifiers.MissingParameter, "TILEMATRIX parameter is not defined"));
                }

                if (String.IsNullOrEmpty(layer))
                {
                    return(ResponseWithBadRequestError(Identifiers.MissingParameter, "LAYER parameter is not defined"));
                }

                if (!this.tileSourceFabric.Contains(layer))
                {
                    return(ResponseWithNotFoundError(Identifiers.NotFound, $"Specified layer '{layer}' was not found"));
                }

                if (String.IsNullOrEmpty(format))
                {
                    return(ResponseWithBadRequestError(Identifiers.MissingParameter, "FORMAT parameter is not defined"));
                }

                return(await GetTileAsync(layer, tileCol, tileRow, Int32.Parse(tileMatrix), EntitiesConverter.TileFormatToContentType(format)));
            }
            else
            {
                return(ResponseWithBadRequestError(Identifiers.MissingParameter, "Invaid request")); // TODO: more detailed
            }
        }
Example #8
0
        public async Task <IActionResult> ProcessGetTileRestfulRequestAsync(
            string?tileMatrixSet,
            string?tileMatrix,
            int tileRow,
            int tileCol,
            string version = Identifiers.Version100,
            string?layer   = null,
#pragma warning disable IDE0060
            string style = "default", // Not used
#pragma warning restore IDE0060
            string format = "png")
        {
            if (String.Compare(version, Identifiers.Version100, StringComparison.Ordinal) != 0)
            {
                return(ResponseWithBadRequestError(Identifiers.InvalidParameterValue, "Invalid VERSION parameter value (1.0.0 available only)"));
            }

            if (String.IsNullOrEmpty(tileMatrixSet))
            {
                return(ResponseWithBadRequestError(Identifiers.MissingParameter, "TILEMATRIXSET parameter is not defined"));
            }

            if (String.IsNullOrEmpty(tileMatrix))
            {
                return(ResponseWithBadRequestError(Identifiers.MissingParameter, "TILEMATRIX parameter is not defined"));
            }

            if (String.IsNullOrEmpty(layer))
            {
                return(ResponseWithBadRequestError(Identifiers.MissingParameter, "LAYER parameter is not defined"));
            }

            if (!this.tileSourceFabric.Contains(layer))
            {
                return(ResponseWithNotFoundError(Identifiers.NotFound, $"Specified layer '{layer}' was not found"));
            }

            if (String.IsNullOrEmpty(format))
            {
                return(ResponseWithBadRequestError(Identifiers.MissingParameter, "FORMAT parameter is not defined"));
            }

            return(await GetTileAsync(layer, tileCol, tileRow, Int32.Parse(tileMatrix), EntitiesConverter.TileFormatToContentType(format)));
        }