public void WhenAABBIsEnlargedExtentsAreChangedAppropriately() { _testAabb.Grow(5); Assert.That(_testAabb.Center, Is.EqualTo(new Vector2(10, 10))); Assert.That(_testAabb.Min, Is.EqualTo(new Vector2(-2.5f, -2.5f))); Assert.That(_testAabb.Max, Is.EqualTo(new Vector2(22.5f, 22.5f))); }
private KDTree buildVertexIndex(List <SDMinVertex> weightedVertices, Polyline polyline) { BoundingRectangle br = polyline.GetBoundingRectangle(); br.Grow(PlanimetryAlgorithms.Tolerance); KDTree result = new KDTree(br); result.MaxDepth = 14; result.MinObjectCount = 10; result.BoxSquareThreshold = br.Width * br.Height / 10000; result.Build(weightedVertices); return(result); }
private void GetMap(NameValueCollection requestParams, Stream responseOutputStream, ref string responseContentType) { #region Verify the request if (requestParams["LAYERS"] == null) { WmsException(WmsExceptionCode.NotApplicable, "Required parameter LAYERS not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["STYLES"] == null) { WmsException(WmsExceptionCode.NotApplicable, "Required parameter STYLES not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["SRS"] == null) { WmsException(WmsExceptionCode.NotApplicable, "Required parameter SRS not specified.", responseOutputStream, ref responseContentType); return; } else { string authCode = "EPSG:-1"; if (!string.IsNullOrEmpty(_map.CoodrinateSystemWKT)) { IInfo coordinateSystem = CoordinateSystemWktDeserializer.Parse(_map.CoodrinateSystemWKT); authCode = coordinateSystem.Authority + ":" + coordinateSystem.AuthorityCode.ToString(); } if (requestParams["SRS"] != authCode) { WmsException(WmsExceptionCode.InvalidSRS, "SRS is not supported", responseOutputStream, ref responseContentType); return; } } if (requestParams["BBOX"] == null) { WmsException(WmsExceptionCode.InvalidDimensionValue, "Required parameter BBOX not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["WIDTH"] == null) { WmsException(WmsExceptionCode.InvalidDimensionValue, "Required parameter WIDTH not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["HEIGHT"] == null) { WmsException(WmsExceptionCode.InvalidDimensionValue, "Required parameter HEIGHT not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["FORMAT"] == null) { WmsException(WmsExceptionCode.NotApplicable, "Required parameter FORMAT not specified.", responseOutputStream, ref responseContentType); return; } #endregion #region Render Settings Color backColor = Color.White; if (_map.CosmeticRaster.Visible) { //Cosmetic layer all broken, this does not allow its use. WmsException(WmsExceptionCode.NotApplicable, "WMS not support this settings rendering.", responseOutputStream, ref responseContentType); return; } if (string.Compare(requestParams["TRANSPARENT"], "TRUE", _ignoreCase) == 0) { backColor = Color.Transparent; } else if (requestParams["BGCOLOR"] != null) { try { backColor = ColorTranslator.FromHtml("#" + requestParams["BGCOLOR"]); } catch { WmsException(WmsExceptionCode.NotApplicable, "Parameter BGCOLOR has wrong value.", responseOutputStream, ref responseContentType); return; } } ImageCodecInfo imageEncoder = getEncoderInfo(requestParams["FORMAT"]); if (imageEncoder == null) { WmsException(WmsExceptionCode.NotApplicable, "Wrong mime-type in FORMAT parameter.", responseOutputStream, ref responseContentType); return; } int width = 0; int height = 0; if (!int.TryParse(requestParams["WIDTH"], out width)) { WmsException(WmsExceptionCode.InvalidDimensionValue, "Parameter WIDTH has wrong value.", responseOutputStream, ref responseContentType); return; } else if (_description.MaxWidth > 0 && width > _description.MaxWidth) { WmsException(WmsExceptionCode.OperationNotSupported, "WIDTH parameter value is too large.", responseOutputStream, ref responseContentType); return; } if (!int.TryParse(requestParams["HEIGHT"], out height)) { WmsException(WmsExceptionCode.InvalidDimensionValue, "Parameter HEIGHT has wrong value.", responseOutputStream, ref responseContentType); return; } else if (_description.MaxHeight > 0 && height > _description.MaxHeight) { WmsException(WmsExceptionCode.OperationNotSupported, "HEIGHT parameter value is too large.", responseOutputStream, ref responseContentType); return; } BoundingRectangle originalBbox = ParseBbox(requestParams["bbox"]); if (originalBbox == null) { WmsException(WmsExceptionCode.NotApplicable, "Wrong BBOX parameter.", responseOutputStream, ref responseContentType); return; } #endregion //Selected by default. bool[] _defaultVisibility = new bool[_map.Layers.Count()]; int j = 0; foreach (LayerBase layer in _map.Layers) { _defaultVisibility[j] = layer.Visible; layer.Visible = false; //Turning off all the layers. j++; } lock (_syncRoot) { LayerBase[] useLayers = null; int[] indexLayers = null; #region Checking layers of inquiry if (!string.IsNullOrEmpty(requestParams["LAYERS"])) { #region Getting layers of inquiry string[] layers = requestParams["LAYERS"].Split(new[] { ',' }); if (_description.LayerLimit > 0) { if (layers.Length == 0 && _map.Layers.Count > _description.LayerLimit || layers.Length > _description.LayerLimit) { WmsException(WmsExceptionCode.OperationNotSupported, "The number of layers in the query exceeds the limit of layers in the WMS.", responseOutputStream, ref responseContentType); return; } } #endregion useLayers = new LayerBase[layers.Length]; indexLayers = new int[layers.Length]; for (int i = 0; i < layers.Length; i++) { var layer = layers[i]; var findLayer = false; for (int k = 0; k < _map.Layers.Count; k++) { if (string.Equals(_map.Layers[k].Alias, layer, StringComparison.InvariantCultureIgnoreCase)) { useLayers[i] = _map.Layers[k]; indexLayers[i] = k; findLayer = true; break; } } if (!findLayer) { WmsException(WmsExceptionCode.LayerNotDefined, "Layer \"" + layer + "\" not found.", responseOutputStream, ref responseContentType); return; } } Array.Sort(indexLayers, useLayers); } #endregion BoundingRectangle bboxWithGutters = (BoundingRectangle)originalBbox.Clone(); bboxWithGutters.Grow((double)GutterSize * originalBbox.Width / (double)width); try { using (Image bmp = GetImage(width, height, backColor, useLayers, bboxWithGutters)) { EncoderParameters encoderParams = new EncoderParameters(1); encoderParams.Param[0] = new EncoderParameter( System.Drawing.Imaging.Encoder.Quality, (long)_imageQuality); using (MemoryStream ms = new MemoryStream()) { bmp.Save(ms, imageEncoder, encoderParams); byte[] buffer = ms.ToArray(); responseContentType = imageEncoder.MimeType; responseOutputStream.Write(buffer, 0, buffer.Length); } } } catch (Exception except) { WmsException(WmsExceptionCode.NotApplicable, except.Message, responseOutputStream, ref responseContentType); return; } for (j = 0; j < _map.Layers.Count(); j++) // Restore everything as it was. { _map.Layers[j].Visible = _defaultVisibility[j]; } } }
private void init() { _nodes.Clear(); _edges.Clear(); _sourceSegments.Clear(); int pointCount = 0; _sourceBounds = new BoundingRectangle(); if (_sourceGeometry1 != null) { _sourceBounds.Join(_sourceGeometry1.GetBoundingRectangle()); pointCount += _sourceGeometry1.CoordinateCount; } if (_sourceGeometry2 != null) { _sourceBounds.Join(_sourceGeometry2.GetBoundingRectangle()); pointCount += _sourceGeometry2.CoordinateCount; } if (pointCount > 800) { _sourceBounds.Grow(PlanimetryAlgorithms.Tolerance * 10); _splittedSegmentIndex = new KDTree(_sourceBounds); _splittedSegmentIndex.MaxDepth = 20; _splittedSegmentIndex.BoxSquareThreshold = _sourceBounds.Width * _sourceBounds.Height / 10000; } }
/// <summary> /// Request GetTile /// </summary> private void GetTile(NameValueCollection requestParams, Stream responseOutputStream, ref string responseContentType) { #region Verify the request if (requestParams["LAYERS"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter LAYER not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["STYLES"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter STYLE not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["TILEMATRIXSET"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter TILEMATRIXSET not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["TILEMATRIX"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter TILEMATRIX not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["TILEROW"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter TILEROW not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["TILECOL"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter TILECOL not specified.", responseOutputStream, ref responseContentType); return; } if (requestParams["FORMAT"] == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Required parameter FORMAT not specified.", responseOutputStream, ref responseContentType); return; } #endregion #region Render Settings Color backColor = Color.FromArgb(0, 0, 0, 0); if (_map.CosmeticRaster.Visible) { //Cosmetic layer all broken, this does not allow its use. WmtsException(WmtsExceptionCode.NotApplicable, "WMTS not support this settings rendering.", responseOutputStream, ref responseContentType); return; } //Render for inscriptions. var wmsFeatureRender = new WmsFeatureRender(_map.RenderingSettings); ImageCodecInfo imageEncoder = getEncoderInfo(requestParams["FORMAT"]); if (imageEncoder == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Wrong mime-type in FORMAT parameter.", responseOutputStream, ref responseContentType); return; } int tileRow = 0; int tileCol = 0; if (!int.TryParse(requestParams["TILEROW"], out tileRow)) { WmtsException(WmtsExceptionCode.InvalidDimensionValue, "Parameter TILEROW has wrong value.", responseOutputStream, ref responseContentType); return; } if (!int.TryParse(requestParams["TILECOL"], out tileCol)) { WmsException(WmsExceptionCode.InvalidDimensionValue, "Parameter TILECOL has wrong value.", responseOutputStream, ref responseContentType); return; } string tileMatrixName = "EPSG:3857:0"; if (requestParams["TILEMATRIX"] != null) { tileMatrixName = requestParams["TILEMATRIX"]; } Tile tile = new Tile(_map, (uint)tileRow, (uint)tileCol); tile.ScaleDenominator = _description.GetScaleDenominator(_description.ZoomLevel[tileMatrixName]); tile.PixelSize = _description.GetPixelSize(_description.ZoomLevel[tileMatrixName]); tile.ZoomLevel = (uint)_description.ZoomLevel[tileMatrixName]; int width = tile.Width, height = tile.Height; BoundingRectangle originalBbox = tile.BBox; if (originalBbox == null) { WmtsException(WmtsExceptionCode.NotApplicable, "Wrong Tile parameters.", responseOutputStream, ref responseContentType); return; } #endregion //Selected by default. bool[] _defaultVisibility = new bool[_map.Layers.Count()]; int j = 0; foreach (LayerBase layer in _map.Layers) { _defaultVisibility[j] = layer.Visible; layer.Visible = false; //Turning off all the layers. j++; } lock (_syncRoot) { LayerBase[] useLayers = null; int[] indexLayers = null; #region Checking layers of inquiry if (!string.IsNullOrEmpty(requestParams["LAYER"])) { #region Getting layers of inquiry string[] layers = requestParams["LAYER"].Split(new[] { ',' }); if (_description.LayerLimit > 0) { if (layers.Length == 0 && _map.Layers.Count > _description.LayerLimit || layers.Length > _description.LayerLimit) { WmtsException(WmtsExceptionCode.OperationNotSupported, "The number of layers in the query exceeds the limit of layers in the WMTS.", responseOutputStream, ref responseContentType); return; } } #endregion useLayers = new LayerBase[layers.Length]; indexLayers = new int[layers.Length]; for (int i = 0; i < layers.Length; i++) { var layer = layers[i]; var findLayer = false; for (int k = 0; k < _map.Layers.Count; k++) { if (string.Equals(_map.Layers[k].Alias, layer, StringComparison.InvariantCultureIgnoreCase)) { useLayers[i] = _map.Layers[k]; indexLayers[i] = k; findLayer = true; break; } } if (!findLayer) { WmtsException(WmtsExceptionCode.LayerNotDefined, "Layer \"" + layer + "\" not found.", responseOutputStream, ref responseContentType); return; } } Array.Sort(indexLayers, useLayers); } #endregion BoundingRectangle bboxWithGutters = (BoundingRectangle)originalBbox.Clone(); bboxWithGutters.Grow((double)GutterSize * originalBbox.Width / (double)width); try { using (Image bmp = GetImage(width, height, backColor, useLayers, bboxWithGutters)) { EncoderParameters encoderParams = new EncoderParameters(1); encoderParams.Param[0] = new EncoderParameter( System.Drawing.Imaging.Encoder.Quality, (long)_imageQuality); using (MemoryStream ms = new MemoryStream()) { bmp.Save(ms, imageEncoder, encoderParams); byte[] buffer = ms.ToArray(); responseContentType = imageEncoder.MimeType; responseOutputStream.Write(buffer, 0, buffer.Length); } } } catch (Exception except) { WmtsException(WmtsExceptionCode.NotApplicable, except.Message, responseOutputStream, ref responseContentType); return; } for (j = 0; j < _map.Layers.Count(); j++) //Restore it as it was. { _map.Layers[j].Visible = _defaultVisibility[j]; } } }