[mapguide-commits] r9123 - in trunk/Tools/Maestro: MgCooker OSGeo.MapGuide.MaestroAPI/Tile OSGeo.MapGuide.MaestroAPI.Tests

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Wed Jan 25 05:28:12 PST 2017


Author: jng
Date: 2017-01-25 05:28:11 -0800 (Wed, 25 Jan 2017)
New Revision: 9123

Added:
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/TileTests.cs
Modified:
   trunk/Tools/Maestro/MgCooker/SetupRun.cs
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/OSGeo.MapGuide.MaestroAPI.Tests.csproj
   trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Tile/BatchSettings.cs
Log:
#2745: Partial fix for tile total calculations when override extents are involved. The row/col recalculation when override extents are involved is clearly wrong, it should just re-evaluate map size in row/col against the override extents.

This fix is "partial" in that while I'm now confident about the row/col re-calculations, I am not yet confident about whether the row/col offsets portion is correct. I added some unit tests to at least ensure that smaller override extents gives smaller tile count (but not some absurd number like 10, as it was before)

Also change MapTilingConfiguration.SetGroups to take a (params string[]) instead of string[] for easier invocation.

Modified: trunk/Tools/Maestro/MgCooker/SetupRun.cs
===================================================================
--- trunk/Tools/Maestro/MgCooker/SetupRun.cs	2017-01-24 15:26:36 UTC (rev 9122)
+++ trunk/Tools/Maestro/MgCooker/SetupRun.cs	2017-01-25 13:28:11 UTC (rev 9123)
@@ -258,7 +258,7 @@
                 foreach (Config c in ReadTree())
                 {
                     MapTilingConfiguration bm = new MapTilingConfiguration(bx, c.MapDefinition);
-                    bm.SetGroups(new string[] { c.Group });
+                    bm.SetGroups(c.Group);
                     bm.SetScalesAndExtend(c.ScaleIndexes, c.ExtentOverride);
 
                     bx.Maps.Add(bm);

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Tile/BatchSettings.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Tile/BatchSettings.cs	2017-01-24 15:26:36 UTC (rev 9122)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI/Tile/BatchSettings.cs	2017-01-25 13:28:11 UTC (rev 9123)
@@ -652,7 +652,7 @@
                 return;
             }
 
-            IEnvelope extents = this.MaxExtent ?? m_tileSetExtents;
+            IEnvelope extents = m_tileSetExtents; //this.MaxExtent ?? m_tileSetExtents;
             double maxscale = m_maxscale;
 
             m_dimensions = new long[this.Resolutions][];
@@ -693,26 +693,23 @@
                 //Using this algorithm, yields a negative number of columns/rows, if the max scale is larger than the max extent of the map.
                 rows = Math.Max(1, (int)Math.Ceiling((height_in_meters / tileHeight)));
                 cols = Math.Max(1, (int)Math.Ceiling((width_in_meters / tileWidth)));
-
+                
                 if (m_maxExtent != null)
                 {
                     //The extent is overridden, so we need to adjust the start offsets
-                    double offsetX = MaxExtent.MinX - m_tileSetExtents.MinX;
-                    double offsetY = m_tileSetExtents.MaxY - MaxExtent.MaxY;
+                    //and re-compute row/col span against the overridden extents
+                    double offsetX = m_maxExtent.MinX - m_tileSetExtents.MinX;
+                    double offsetY = m_tileSetExtents.MaxY - m_maxExtent.MaxY;
                     rowTileOffset = (int)Math.Floor(offsetY / tileHeight);
                     colTileOffset = (int)Math.Floor(offsetX / tileWidth);
 
-                    double offsetMaxX = MaxExtent.MaxX - m_tileSetExtents.MinX;
-                    double offsetMinY = m_tileSetExtents.MaxY - MaxExtent.MinY;
-                    int rowMinTileOffset = (int)Math.Floor(offsetMinY / tileHeight);
-                    int colMaxTileOffset = (int)Math.Floor(offsetMaxX / tileWidth);
+                    //Re-compute rows/cols against override extent
+                    width_in_meters = Math.Abs(m_parent.Config.MetersPerUnit * (m_maxExtent.MaxX - m_maxExtent.MinX));
+                    height_in_meters = Math.Abs(m_parent.Config.MetersPerUnit * (m_maxExtent.MaxY - m_maxExtent.MinY));
 
-                    //GT 03/08/2014 - the right number of columns/rows it's the the end tile (maxtileoffset, ex 12) - the start tile (coltileoffset, ex 11) +1
-                    //i.e. 12-11+1=2 so 2 columns
-                    cols = (colMaxTileOffset - colTileOffset) + 1;
-                    rows = (rowMinTileOffset - rowTileOffset) + 1;
+                    rows = Math.Max(1, (int)Math.Ceiling((height_in_meters / tileHeight)));
+                    cols = Math.Max(1, (int)Math.Ceiling((width_in_meters / tileWidth)));
                 }
-
                 m_dimensions[i] = new long[] { rows, cols, rowTileOffset, colTileOffset };
             }
         }
@@ -721,7 +718,7 @@
         /// Sets the list of groups
         /// </summary>
         /// <param name="groups"></param>
-        public void SetGroups(string[] groups)
+        public void SetGroups(params string[] groups)
         {
             List<string> g = new List<string>();
             for (int i = 0; i < m_groups.Length; i++)

Modified: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/OSGeo.MapGuide.MaestroAPI.Tests.csproj
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/OSGeo.MapGuide.MaestroAPI.Tests.csproj	2017-01-24 15:26:36 UTC (rev 9122)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/OSGeo.MapGuide.MaestroAPI.Tests.csproj	2017-01-25 13:28:11 UTC (rev 9123)
@@ -85,6 +85,7 @@
     <Compile Include="Schema\DataPropertyDefinitionTests.cs" />
     <Compile Include="Schema\FeatureSchemaTests.cs" />
     <Compile Include="Schema\GeometricPropertyDefinitionTests.cs" />
+    <Compile Include="TileTests.cs" />
     <Compile Include="Utils.cs" />
     <Compile Include="ValidationTests.cs" />
   </ItemGroup>

Added: trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/TileTests.cs
===================================================================
--- trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/TileTests.cs	                        (rev 0)
+++ trunk/Tools/Maestro/OSGeo.MapGuide.MaestroAPI.Tests/TileTests.cs	2017-01-25 13:28:11 UTC (rev 9123)
@@ -0,0 +1,110 @@
+using Moq;
+using NUnit.Framework;
+using OSGeo.MapGuide.MaestroAPI.Services;
+using OSGeo.MapGuide.MaestroAPI.Tile;
+using OSGeo.MapGuide.ObjectModels;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace OSGeo.MapGuide.MaestroAPI.Tests
+{
+    public class TileTests
+    {
+        static readonly double[] SCALE_LIST = { 200000, 100000, 50000, 25000, 12500, 6250, 3125, 1562.5, 781.25, 390.625 };
+
+        [Test]
+        public void Test_MapTilingConfiguration_TotalCalculation()
+        {
+            var mdfId = "Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition";
+            var conn = new Mock<IServerConnection>();
+            var mockResSvc = new Mock<IResourceService>();
+
+            var mdf = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "Sheboygan");
+            mdf.ResourceID = mdfId;
+            mdf.InitBaseMap();
+            var group = mdf.BaseMap.AddBaseLayerGroup("Base Layer Group");
+            group.Visible = true;
+            foreach (double scale in SCALE_LIST.Reverse())
+            {
+                mdf.BaseMap.AddFiniteDisplayScale(scale);
+            }
+            mdf.SetExtents(-87.764986990962839, 43.691398128787782, -87.695521510899724, 43.797520000480347);
+
+            mockResSvc.Setup(r => r.GetResource(It.Is<string>(arg => arg == mdfId))).Returns(mdf);
+
+            conn.Setup(c => c.ResourceService).Returns(mockResSvc.Object);
+
+            var tileRuns = new TilingRunCollection(conn.Object);
+            tileRuns.Config.DPI = 96;
+            tileRuns.Config.MetersPerUnit = 111319.490793274;
+            tileRuns.Config.RandomizeTileSequence = false;
+            tileRuns.Config.RetryCount = 5;
+            tileRuns.Config.ThreadCount = 1;
+            tileRuns.Config.TileWidth = 300;
+            tileRuns.Config.TileHeight = 300;
+
+            var tileConf = new MapTilingConfiguration(tileRuns, mdfId);
+
+            tileConf.SetGroups("Base Layer Group");
+            tileConf.SetScalesAndExtend(Enumerable.Range(0, 10).ToArray(), null);
+
+            tileRuns.Maps.Add(tileConf);
+
+            Assert.AreEqual(127472, tileConf.TotalTiles);
+        }
+
+        [Test]
+        public void Test_MapTilingConfiguration_WithCustomBounds_TotalCalculation()
+        {
+            var mdfId = "Library://Samples/Sheboygan/MapsTiled/Sheboygan.MapDefinition";
+            var conn = new Mock<IServerConnection>();
+            var mockResSvc = new Mock<IResourceService>();
+
+            var mdf = ObjectFactory.CreateMapDefinition(new Version(1, 0, 0), "Sheboygan");
+            mdf.ResourceID = mdfId;
+            mdf.InitBaseMap();
+            var group = mdf.BaseMap.AddBaseLayerGroup("Base Layer Group");
+            group.Visible = true;
+            foreach (double scale in SCALE_LIST.Reverse())
+            {
+                mdf.BaseMap.AddFiniteDisplayScale(scale);
+            }
+            mdf.SetExtents(-87.764986990962839, 43.691398128787782, -87.695521510899724, 43.797520000480347);
+
+            mockResSvc.Setup(r => r.GetResource(It.Is<string>(arg => arg == mdfId))).Returns(mdf);
+
+            conn.Setup(c => c.ResourceService).Returns(mockResSvc.Object);
+
+            var tileRuns = new TilingRunCollection(conn.Object);
+            tileRuns.Config.DPI = 96;
+            tileRuns.Config.MetersPerUnit = 111319.490793274;
+            tileRuns.Config.RandomizeTileSequence = false;
+            tileRuns.Config.RetryCount = 5;
+            tileRuns.Config.ThreadCount = 1;
+            tileRuns.Config.TileWidth = 300;
+            tileRuns.Config.TileHeight = 300;
+
+            var tileConf = new MapTilingConfiguration(tileRuns, mdfId);
+
+            var customExtents = ObjectFactory.CreateEnvelope(-87.764986990962839, 43.691398128787782, -87.695521510899724, 43.797520000480347);
+
+            tileConf.SetGroups("Base Layer Group");
+            tileConf.SetScalesAndExtend(Enumerable.Range(0, 10).ToArray(), customExtents);
+
+            tileRuns.Maps.Add(tileConf);
+
+            Assert.AreEqual(127472, tileConf.TotalTiles);
+
+            customExtents = ObjectFactory.CreateEnvelope(-87.73, 43.71, -87.71, 43.75);
+            tileConf.SetScalesAndExtend(Enumerable.Range(0, 10).ToArray(), customExtents);
+
+            //I don't know the exact number here, but it should be less than the original and
+            //greater than the bogus amount of 10 tiles
+            Assert.Less(tileConf.TotalTiles, 127472);
+            Assert.Greater(tileConf.TotalTiles, 10);
+        }
+    }
+}



More information about the mapguide-commits mailing list