[mapguide-commits] r5451 - in sandbox/maestro-3.0: Maestro.Base Maestro.Base/Editor Maestro.Base/UI Maestro.Editors/Common MaestroAPITests MaestroFsPreview OSGeo.MapGuide.MaestroAPI OSGeo.MapGuide.MaestroAPI/CoordinateSystem OSGeo.MapGuide.MaestroAPI/Services OSGeo.MapGuide.MaestroAPI.Http OSGeo.MapGuide.MaestroAPI.Native

svn_mapguide at osgeo.org svn_mapguide at osgeo.org
Thu Dec 9 02:21:20 EST 2010


Author: jng
Date: 2010-12-08 23:21:20 -0800 (Wed, 08 Dec 2010)
New Revision: 5451

Added:
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ArgumentParser.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ActualCoordinateSystem.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemBase.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/DegreeBasedCoordinateSystem.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/FeetBasedCoordinateSystem.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/MeterBasedCoordinateSystem.cs
Modified:
   sandbox/maestro-3.0/Maestro.Base/Editor/FsEditorOptionPanel.cs
   sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj
   sandbox/maestro-3.0/Maestro.Base/UI/ResourcePropertiesDialog.cs
   sandbox/maestro-3.0/Maestro.Editors/Common/CoordinateSystemPicker.cs
   sandbox/maestro-3.0/MaestroAPITests/MaestroAPITests.csproj
   sandbox/maestro-3.0/MaestroAPITests/ObjectTests.cs
   sandbox/maestro-3.0/MaestroAPITests/RuntimeMapTests.cs
   sandbox/maestro-3.0/MaestroFsPreview/
   sandbox/maestro-3.0/MaestroFsPreview/Program.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystem.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystemCatalog.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystem.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemCatalog.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemCategory.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ICoordinateSystemCatalog.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/IServerConnection.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
   sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs
Log:
3.0 sandbox changes:
 - Add overloads of IMappingService.CreateMap that do not require a meters-per-unit value. This value is derived from the Map Definition's WKT using:
	- TF.NET's Coordinate System APIs (http)
		- The computed values differ from the values produced by MgCoordinateSystem, but feeding this runtime map to the rendering APIs produces no discernible difference.
	- MgCoordinateSystem API (local)
 - Add an ArgumentParser class for processing arguments for command-line applications
 - Clean up and have a consistent naming scheme for custom connection properties and connection string parameters. Unit test provided.
 - Add new APIs to IServerConnection that provide enough information to recreate the same connection via the ConnectionProviderRegistry
 - Rename the existing CoordinateSystemBase class to CoordinateSystemDefinitionBase to avoid naming collision with the new CoordinateSystemBase class (with several derived versions) that provide the necessary logic for calculating meters-per-unit (adapted from the LittleSharpRenderEngine project)

Modified: sandbox/maestro-3.0/Maestro.Base/Editor/FsEditorOptionPanel.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Editor/FsEditorOptionPanel.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/Maestro.Base/Editor/FsEditorOptionPanel.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -30,6 +30,11 @@
 using OSGeo.MapGuide.ObjectModels.Capabilities;
 using OSGeo.MapGuide.MaestroAPI.Services;
 using Maestro.Editors;
+using Maestro.Base.UI.Preferences;
+using ICSharpCode.Core;
+using System.IO;
+using System.Diagnostics;
+using OSGeo.MapGuide.MaestroAPI;
 
 namespace Maestro.Base.Editor
 {
@@ -72,9 +77,42 @@
 
         private void btnLocalPreview_Click(object sender, EventArgs e)
         {
+            //TODO: We really want to do this as an external process
+
             var dlg = new MaestroFsPreview.MainForm(_fsvc, _rsvc);
             dlg.FeatureSourceID = _fs.ResourceID;
             dlg.ShowDialog();
+
+            /*
+            string exe = PropertyService.Get(ConfigProperties.LocalFsPreviewPath, "");
+
+            if (!File.Exists(exe))
+            {
+                using (var dlg = DialogFactory.OpenFile())
+                {
+                    dlg.Title = string.Format(Properties.Resources.LocateExecutable, "MaestroFsPreview.exe");
+                    dlg.Filter = Properties.Resources.FilterExecutables;
+                    if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+                    {
+                        exe = dlg.FileName;
+                        PropertyService.Set(ConfigProperties.LocalFsPreviewPath, exe);
+                    }
+                }
+            }
+
+            var procInfo = new ProcessStartInfo(exe);
+            procInfo.WorkingDirectory = Path.GetDirectoryName(exe);
+            var conn = _fs.CurrentConnection;
+            var clonep = conn.CloneParameters;
+
+            List<string> args = new List<string>();
+            foreach (string key in clonep.Keys)
+            {
+                args.Add("-" + key + ":" + clonep[key]);
+            }
+            procInfo.Arguments = string.Join(" ", args.ToArray());
+            var proc = Process.Start(procInfo);
+             */
         }
 
         private void btnEditConfiguration_Click(object sender, EventArgs e)

Modified: sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/Maestro.Base/Maestro.Base.csproj	2010-12-09 07:21:20 UTC (rev 5451)
@@ -507,7 +507,6 @@
     <ProjectReference Include="..\MaestroFsPreview\MaestroFsPreview.csproj">
       <Project>{59BE5E18-17B6-431D-836E-C0AABA6D69E8}</Project>
       <Name>MaestroFsPreview</Name>
-      <Private>False</Private>
     </ProjectReference>
     <ProjectReference Include="..\Thirdparty\SharpDevelop\ICSharpCode.Core.WinForms\ICSharpCode.Core.WinForms.csproj">
       <Project>{857CA1A3-FC88-4BE0-AB6A-D1EE772AB288}</Project>

Modified: sandbox/maestro-3.0/Maestro.Base/UI/ResourcePropertiesDialog.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Base/UI/ResourcePropertiesDialog.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/Maestro.Base/UI/ResourcePropertiesDialog.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -493,7 +493,7 @@
                 try
                 {
                     List<string> items = new List<string>();
-                    foreach (OSGeo.MapGuide.MaestroAPI.CoordinateSystem.CoordinateSystemBase c in m_connection.CoordinateSystemCatalog.Coordsys)
+                    foreach (OSGeo.MapGuide.MaestroAPI.CoordinateSystem.CoordinateSystemDefinitionBase c in m_connection.CoordinateSystemCatalog.Coordsys)
                     {
                         if (c.Code.StartsWith("EPSG:"))
                             items.Add(c.Code);
@@ -775,7 +775,7 @@
                 if (m_srslist == null)
                 {
                     List<string> items = new List<string>();
-                    foreach (OSGeo.MapGuide.MaestroAPI.CoordinateSystem.CoordinateSystemBase c in m_connection.CoordinateSystemCatalog.Coordsys)
+                    foreach (OSGeo.MapGuide.MaestroAPI.CoordinateSystem.CoordinateSystemDefinitionBase c in m_connection.CoordinateSystemCatalog.Coordsys)
                     {
                         if (c.Code.StartsWith("EPSG:"))
                             items.Add(c.Code);

Modified: sandbox/maestro-3.0/Maestro.Editors/Common/CoordinateSystemPicker.cs
===================================================================
--- sandbox/maestro-3.0/Maestro.Editors/Common/CoordinateSystemPicker.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/Maestro.Editors/Common/CoordinateSystemPicker.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -38,10 +38,10 @@
             InitializeComponent();
         }
 
-        private CoordinateSystemBase m_wktCoordSys = null;
-        private CoordinateSystemBase m_epsgCoordSys = null;
-        private CoordinateSystemBase m_coordsysCodeCoordSys = null;
-        private CoordinateSystemBase m_selectedCoordsys = null;
+        private CoordinateSystemDefinitionBase m_wktCoordSys = null;
+        private CoordinateSystemDefinitionBase m_epsgCoordSys = null;
+        private CoordinateSystemDefinitionBase m_coordsysCodeCoordSys = null;
+        private CoordinateSystemDefinitionBase m_selectedCoordsys = null;
 
         private bool m_isUpdating = false;
 
@@ -80,21 +80,21 @@
             this.Refresh();
             _cat.FindCoordSys("");
 
-            CoordinateSystemBase[] items = null;
+            CoordinateSystemDefinitionBase[] items = null;
             try
             {
                 items = _cat.Coordsys;
             }
             catch
             {
-                items = new CoordinateSystemBase[0];
+                items = new CoordinateSystemDefinitionBase[0];
             }
 
             EPSGCodeText.BeginUpdate();
             try
             {
                 EPSGCodeText.Items.Clear();
-                foreach (CoordinateSystemBase c in items)
+                foreach (CoordinateSystemDefinitionBase c in items)
                 {
                     if (c.Code.StartsWith("EPSG:"))
                         EPSGCodeText.Items.Add(c.EPSG);
@@ -109,7 +109,7 @@
             try
             {
                 CoordSysCodeText.Items.Clear();
-                foreach (CoordinateSystemBase c in items)
+                foreach (CoordinateSystemDefinitionBase c in items)
                 {
                     CoordSysCodeText.Items.Add(c.Code);
                 }
@@ -215,7 +215,7 @@
         private void OKBtn_Click(object sender, EventArgs e)
         {
             if (SelectByList.Checked)
-                m_selectedCoordsys = CoordinateSystem.SelectedItem as CoordinateSystemBase;
+                m_selectedCoordsys = CoordinateSystem.SelectedItem as CoordinateSystemDefinitionBase;
             else if (SelectByCoordSysCode.Checked)
                 m_selectedCoordsys = m_coordsysCodeCoordSys;
             else if (SelectByWKT.Checked && _cat == null)
@@ -237,7 +237,7 @@
         /// Gets the selected coord sys.
         /// </summary>
         /// <value>The selected coord sys.</value>
-        public CoordinateSystemBase SelectedCoordSys
+        public CoordinateSystemDefinitionBase SelectedCoordSys
         {
             get { return m_selectedCoordsys; }
         }
@@ -320,9 +320,9 @@
 
         private void UpdateOthers()
         {
-            CoordinateSystemBase selectedCoordsys;
+            CoordinateSystemDefinitionBase selectedCoordsys;
             if (SelectByList.Checked)
-                selectedCoordsys = CoordinateSystem.SelectedItem as CoordinateSystemBase;
+                selectedCoordsys = CoordinateSystem.SelectedItem as CoordinateSystemDefinitionBase;
             else if (SelectByCoordSysCode.Checked)
                 selectedCoordsys = m_coordsysCodeCoordSys;
             else if (SelectByWKT.Checked)

Modified: sandbox/maestro-3.0/MaestroAPITests/MaestroAPITests.csproj
===================================================================
--- sandbox/maestro-3.0/MaestroAPITests/MaestroAPITests.csproj	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/MaestroAPITests/MaestroAPITests.csproj	2010-12-09 07:21:20 UTC (rev 5451)
@@ -58,6 +58,10 @@
     <Reference Include="System.Data" />
     <Reference Include="System.Drawing" />
     <Reference Include="System.Xml" />
+    <Reference Include="Topology, Version=1.0.8.24721, Culture=neutral, PublicKeyToken=f526c48929fda856, processorArchitecture=MSIL">
+      <SpecificVersion>False</SpecificVersion>
+      <HintPath>..\Thirdparty\TF.NET\Topology.dll</HintPath>
+    </Reference>
   </ItemGroup>
   <ItemGroup>
     <Compile Include="CapabilityTests.cs" />

Modified: sandbox/maestro-3.0/MaestroAPITests/ObjectTests.cs
===================================================================
--- sandbox/maestro-3.0/MaestroAPITests/ObjectTests.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/MaestroAPITests/ObjectTests.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -22,17 +22,34 @@
 using System.Text;
 using NUnit.Framework;
 using OSGeo.MapGuide.ObjectModels;
+using OSGeo.MapGuide.MaestroAPI;
 
 namespace MaestroAPITests
 {
     /// <summary>
     /// This test fixture is to ensure all objects created by <see cref="ObjectFactory"/> have no
     /// null child object properties where there shouldn't be any.
+    /// 
+    /// Also tests for various classes (not belonging to any particular group) reside here
     /// </summary>
     [TestFixture]
     public class ObjectTests
     {
         [Test]
+        public void TestArgParser()
+        {
+            string[] args = new string[] { "-foo", "-bar:snafu", "-whatever:" };
+
+            var parser = new ArgumentParser(args);
+            Assert.IsFalse(parser.IsDefined("snafu"));
+            Assert.IsTrue(parser.IsDefined("foo"));
+            Assert.IsTrue(parser.IsDefined("bar"));
+            Assert.IsTrue(parser.IsDefined("whatever"));
+            Assert.AreEqual(string.Empty, parser.GetValue("whatever"));
+            Assert.AreEqual(parser.GetValue("bar"), "snafu");
+        }
+
+        [Test]
         public void TestEnvelope()
         {
             var env = ObjectFactory.CreateEnvelope(-.1, -.1, .1, .1);

Modified: sandbox/maestro-3.0/MaestroAPITests/RuntimeMapTests.cs
===================================================================
--- sandbox/maestro-3.0/MaestroAPITests/RuntimeMapTests.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/MaestroAPITests/RuntimeMapTests.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -42,6 +42,7 @@
     using OSGeo.MapGuide.MaestroAPI.Resource;
     using OSGeo.MapGuide.ObjectModels.LoadProcedure;
     using System.Diagnostics;
+    using OSGeo.MapGuide.MaestroAPI.CoordinateSystem;
 
     [SetUpFixture]
     public class TestBootstrap
@@ -310,6 +311,9 @@
             //The hard-coded value here was the output of MgCoordinateSystem.ConvertCoordinateSystemUnitsToMeters(1.0)
             //for this particular map.
             double metersPerUnit = 111319.490793274;
+            var cs = CoordinateSystemBase.Create(mdf.CoordinateSystem);
+            metersPerUnit = cs.MetersPerUnitX;
+            Trace.TraceInformation("Using MPU of: {0}", metersPerUnit);
 
             var mid = "Session:" + _conn.SessionID + "//TestRender75k.Map";
             var map = mapSvc.CreateMap(mid, mdf, metersPerUnit);
@@ -478,6 +482,9 @@
             //The hard-coded value here was the output of MgCoordinateSystem.ConvertCoordinateSystemUnitsToMeters(1.0)
             //for this particular map.
             double metersPerUnit = 111319.490793274;
+            var cs = CoordinateSystemBase.Create(mdf.CoordinateSystem);
+            metersPerUnit = cs.MetersPerUnitX;
+            Trace.TraceInformation("Using MPU of: {0}", metersPerUnit);
 
             var mid = "Session:" + _conn.SessionID + "//TestRender12k.Map";
             var map = mapSvc.CreateMap(mid, mdf, metersPerUnit);
@@ -608,7 +615,7 @@
         }
     }
 
-    [TestFixture(Ignore = true)]
+    [TestFixture]
     public class HttpRuntimeMapTests : RuntimeMapTests
     {
         protected override IServerConnection CreateTestConnection()
@@ -656,7 +663,7 @@
         }
     }
 
-    [TestFixture]
+    [TestFixture(Ignore = true)]
     public class LocalRuntimeMapTests : RuntimeMapTests
     {
         protected override IServerConnection CreateTestConnection()


Property changes on: sandbox/maestro-3.0/MaestroFsPreview
___________________________________________________________________
Modified: svn:ignore
   - obj
bin

   + obj
bin
*.user


Modified: sandbox/maestro-3.0/MaestroFsPreview/Program.cs
===================================================================
--- sandbox/maestro-3.0/MaestroFsPreview/Program.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/MaestroFsPreview/Program.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -31,19 +31,28 @@
         /// The main entry point for the application.
         /// </summary>
         [STAThread]
-        static void Main()
+        static void Main(string [] args)
         {
+            var parser = new ArgumentParser(args);
             Application.EnableVisualStyles();
             Application.SetCompatibleTextRenderingDefault(false);
             PreferredSiteList.InitCulture();
             IServerConnection conn = null;
-
-            var login = new LoginDialog();
-            if (login.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+            if (!parser.IsDefined(CommandLineArguments.Provider) || !parser.IsDefined(CommandLineArguments.Session))
             {
-                conn = login.Connection;
+                var login = new LoginDialog();
+                if (login.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+                {
+                    conn = login.Connection;
+                }
             }
+            else
+            {
+                string prov = parser.GetValue(CommandLineArguments.Provider);
 
+                conn = ConnectionProviderRegistry.CreateConnection(prov, parser.GetAllArgumentsWithValues());
+            }
+
             if (conn == null)
                 return;
 

Added: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ArgumentParser.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ArgumentParser.cs	                        (rev 0)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/ArgumentParser.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -0,0 +1,129 @@
+#region Disclaimer / License
+// Copyright (C) 2010, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Collections.Specialized;
+
+namespace OSGeo.MapGuide.MaestroAPI
+{
+    /// <summary>
+    /// A helper class to parse command-line arguments
+    /// </summary>
+    /// <remarks>
+    /// Command-line arguments use the following format:
+    /// 
+    /// -name1 -name2[:value2] -name3[:value3]
+    /// </remarks>
+    public class ArgumentParser
+    {
+        private Dictionary<string, string> _values;
+
+        /// <summary>
+        /// Constructs a new instance
+        /// </summary>
+        /// <param name="args"></param>
+        public ArgumentParser(string[] args)
+        {
+            _values = new Dictionary<string, string>();
+
+            foreach (var arg in args)
+            {
+                if (arg.Length > 0 && arg[0] == '-')
+                {
+                    string name = arg.Substring(1);
+                    string value = string.Empty;
+                    var cidx = arg.IndexOf(':');
+
+                    if (cidx >= 0)
+                    {
+                        name = arg.Substring(1, cidx - 1);
+                        value = arg.Substring(cidx + 1);
+                    }
+
+                    _values[name] = value;
+                }
+            }
+        }
+
+        /// <summary>
+        /// Gets a collection of name-value pairs of arguments with values
+        /// </summary>
+        /// <returns></returns>
+        public NameValueCollection GetAllArgumentsWithValues()
+        {
+            var nvc = new NameValueCollection();
+
+            foreach (var key in _values.Keys)
+            {
+                if (!string.IsNullOrEmpty(_values[key]))
+                    nvc[key] = _values[key];
+            }
+
+            return nvc;
+        }
+
+        /// <summary>
+        /// Gets whether the particular switch has been defined
+        /// </summary>
+        /// <param name="name"></param>
+        /// <returns></returns>
+        public bool IsDefined(string name)
+        {
+            return _values.ContainsKey(name);
+        }
+
+        /// <summary>
+        /// Gets the value of the specified switch
+        /// </summary>
+        /// <param name="name"></param>
+        /// <returns></returns>
+        public string GetValue(string name)
+        {
+            return _values[name];
+        }
+    }
+
+    /// <summary>
+    /// A set of common command-line arguments
+    /// </summary>
+    public static class CommandLineArguments
+    {
+        /// <summary>
+        /// The name of the API provider
+        /// </summary>
+        public const string Provider = "Provider";
+
+        /// <summary>
+        /// The session id
+        /// </summary>
+        public const string Session = "SessionId";
+
+        /// <summary>
+        /// The username
+        /// </summary>
+        public const string Username = "Username";
+
+        /// <summary>
+        /// The password
+        /// </summary>
+        public const string Password = "Password";
+    }
+}

Added: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ActualCoordinateSystem.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ActualCoordinateSystem.cs	                        (rev 0)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ActualCoordinateSystem.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -0,0 +1,61 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Topology.CoordinateSystems;
+using Topology.CoordinateSystems.Transformations;
+
+namespace OSGeo.MapGuide.MaestroAPI.CoordinateSystem
+{
+    public class ActualCoordinateSystem : MeterBasedCoordinateSystem
+    {
+        private Topology.CoordinateSystems.Transformations.ICoordinateTransformation m_transform;
+        private const string XY_M = "LOCAL_CS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]";
+
+        internal ActualCoordinateSystem(Topology.CoordinateSystems.ICoordinateSystem coordinateSystem)
+        {
+            if (coordinateSystem == null)
+                throw new ArgumentNullException("coordinateSystem");
+
+            CoordinateTransformationFactory f = new CoordinateTransformationFactory();
+            CoordinateSystemFactory cf = new CoordinateSystemFactory();
+
+            /*Topology.CoordinateSystems.ICoordinateSystem local = cf.CreateLocalCoordinateSystem(
+                "Non-Earth (Meter)",
+                cf.CreateLocalDatum("Local Datum", Topology.CoordinateSystems.DatumType.VD_Normal),
+                new Topology.CoordinateSystems.LinearUnit(1.0, "Meter", "", 0, "", "", ""),
+                new List<Topology.CoordinateSystems.AxisInfo>(new Topology.CoordinateSystems.AxisInfo[] {
+                    new Topology.CoordinateSystems.AxisInfo("X", Topology.CoordinateSystems.AxisOrientationEnum.East),
+                    new Topology.CoordinateSystems.AxisInfo("Y", Topology.CoordinateSystems.AxisOrientationEnum.North)
+                })
+            );
+
+            string s = cf.ToString();*/
+
+            m_transform = f.CreateFromCoordinateSystems(coordinateSystem, cf.CreateFromWkt(XY_M));
+        }
+
+        protected override double CalculateScale(Topology.Geometries.IEnvelope bbox, System.Drawing.Size size)
+        {
+            double[] points = m_transform.MathTransform.Transform(new double[] { bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY });
+            Topology.Geometries.IEnvelope localEnv = new Topology.Geometries.Envelope(points[0], points[2], points[1], points[3]);
+            return base.CalculateScale(localEnv, size);
+        }
+
+        protected override Topology.Geometries.IEnvelope AdjustBoundingBox(Topology.Geometries.IEnvelope bbox, double scale, System.Drawing.Size size)
+        {
+            double[] points = m_transform.MathTransform.Transform(new double[] { bbox.MinX, bbox.MinY, bbox.MaxX, bbox.MaxY });
+            Topology.Geometries.IEnvelope localEnv = new Topology.Geometries.Envelope(points[0], points[2], points[1], points[3]);
+            localEnv = base.AdjustBoundingBox(localEnv, scale, size);
+            points = m_transform.MathTransform.Inverse().Transform(new double[] { localEnv.MinX, localEnv.MinY, localEnv.MaxX, localEnv.MaxY });
+            return new Topology.Geometries.Envelope(points[0], points[2], points[1], points[3]);
+        }
+
+        protected override double DistanceInMeters(Topology.Geometries.IPoint p1, Topology.Geometries.IPoint p2)
+        {
+            double[] points = m_transform.MathTransform.Transform(new double[] { p1.X, p1.Y, p2.X, p2.Y });
+            return base.DistanceInMeters(new Topology.Geometries.Point(points[0], points[1]), new Topology.Geometries.Point(points[2], points[3]));
+        }
+
+        //public override Topology.CoordinateSystems.ICoordinateSystem CoordinateSystem { get { return m_transform.SourceCS; } }
+    }
+}

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystem.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystem.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystem.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -27,7 +27,7 @@
     /// <summary>
     /// Represents a coordinate system definition
     /// </summary>
-    public abstract class CoordinateSystemBase
+    public abstract class CoordinateSystemDefinitionBase
     {
         /// <summary>
         /// The parent category
@@ -78,17 +78,26 @@
         /// <summary>
         /// Initializes a new instance of the <see cref="CoordinateSystemBase"/> class.
         /// </summary>
-        protected CoordinateSystemBase() { }
+        protected CoordinateSystemDefinitionBase() { }
 
         /// <summary>
         /// Initializes a new instance of the <see cref="CoordinateSystemBase"/> class.
         /// </summary>
         /// <param name="parent">The parent.</param>
-        protected CoordinateSystemBase(CoordinateSystemCategory parent)
+        protected CoordinateSystemDefinitionBase(CoordinateSystemCategory parent)
         {
             m_parent = parent;
         }
 
+        internal CoordinateSystemCategory Parent
+        {
+            get { return m_parent; }
+            set
+            {
+                m_parent = value;
+            }
+        }
+
         /// <summary>
         /// Gets or sets the code.
         /// </summary>

Added: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemBase.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemBase.cs	                        (rev 0)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemBase.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -0,0 +1,152 @@
+#region Disclaimer / License
+// Copyright (C) 2010, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Topology.Geometries;
+using System.Drawing;
+using Topology.CoordinateSystems;
+
+namespace OSGeo.MapGuide.MaestroAPI.CoordinateSystem
+{
+    /// <summary>
+    /// Represents a coordinate system instance
+    /// </summary>
+    public abstract class CoordinateSystemBase
+    {
+        static ICoordinateSystemFactory _csFact;
+
+        static CoordinateSystemBase()
+        {
+            _csFact = new CoordinateSystemFactory();
+        }
+
+        public static CoordinateSystemBase Create(CoordinateSystemDefinitionBase csDef)
+        {
+            Check.NotNull(csDef, "csDef");
+            return Create(csDef.WKT);
+        }
+        
+        public static CoordinateSystemBase Create(string csWkt)
+        {
+            Check.NotEmpty(csWkt, "csWkt");
+            return Create(_csFact.CreateFromWkt(csWkt));
+        }
+
+        internal static CoordinateSystemBase Create(ICoordinateSystem coordSys)
+        {
+            CoordinateSystemBase csb = null;
+            try
+            {
+                //This fails because the XY-M projection is not supported
+                csb = new ActualCoordinateSystem(coordSys);
+            }
+            catch { }
+
+            if (csb == null && coordSys != null)
+            {
+                Topology.CoordinateSystems.IUnit unit = coordSys.GetUnits(0);
+                if (unit is Topology.CoordinateSystems.IAngularUnit)
+                {
+                    double radians = (unit as Topology.CoordinateSystems.IAngularUnit).RadiansPerUnit;
+                    csb = new DegreeBasedCoordinateSystem();
+                }
+                else if (unit is Topology.CoordinateSystems.ILinearUnit)
+                    csb = new MeterBasedCoordinateSystem(((Topology.CoordinateSystems.ILinearUnit)unit).MetersPerUnit, ((Topology.CoordinateSystems.ILinearUnit)unit).MetersPerUnit);
+            }
+            return csb;
+
+
+            if (csb == null)
+                csb = new MeterBasedCoordinateSystem();
+
+        }
+
+        public abstract double MetersPerUnitX { get; }
+
+        public abstract double MetersPerUnitY { get; }
+
+        /// <summary>
+        /// Calculates the scale of the map, given the bounding box and image size
+        /// </summary>
+        /// <param name="bbox">The map bounding box</param>
+        /// <param name="size">The size of the image</param>
+        /// <returns>The scale</returns>
+        public double CalculateScale(ObjectModels.Common.IEnvelope bbox, Size size)
+        {
+            Check.NotNull(bbox, "bbox");
+            return CalculateScale(new Envelope(bbox.MinX, bbox.MaxX, bbox.MinY, bbox.MaxY), size);
+        }
+
+        /// <summary>
+        /// Calculates the scale of the map, given the bounding box and image size
+        /// </summary>
+        /// <param name="bbox">The map bounding box</param>
+        /// <param name="size">The size of the image</param>
+        /// <returns>The scale</returns>
+        protected abstract double CalculateScale(IEnvelope bbox, Size size);
+
+        /// <summary>
+        /// Adjusts the boundingbox to equal proportions 
+        /// </summary>
+        /// <param name="bbox">The actual bounding box</param>
+        /// <param name="scale">The scale to fit</param>
+        /// <param name="size">The size to fit to</param>
+        /// <returns>A bounding box with the correct ratio</returns>
+        public ObjectModels.Common.IEnvelope AdjustBoundingBox(ObjectModels.Common.IEnvelope bbox, double scale, Size size)
+        {
+            Check.NotNull(bbox, "bbox");
+            var env = AdjustBoundingBox(new Envelope(bbox.MinX, bbox.MaxX, bbox.MinY, bbox.MaxY), scale, size);
+            return OSGeo.MapGuide.ObjectModels.ObjectFactory.CreateEnvelope(env.MinX, env.MinY, env.MaxX, env.MaxY);
+        }
+
+        /// <summary>
+        /// Adjusts the boundingbox to equal proportions 
+        /// </summary>
+        /// <param name="bbox">The actual bounding box</param>
+        /// <param name="scale">The scale to fit</param>
+        /// <param name="size">The size to fit to</param>
+        /// <returns>A bounding box with the correct ratio</returns>
+        protected abstract IEnvelope AdjustBoundingBox(IEnvelope bbox, double scale, Size size);
+
+        /// <summary>
+        /// Calculates the distance from one point to another, in meters
+        /// </summary>
+        /// <param name="x1"></param>
+        /// <param name="y1"></param>
+        /// <param name="x2"></param>
+        /// <param name="y2"></param>
+        /// <returns></returns>
+        public double DistanceInMeters(double x1, double y1, double x2, double y2)
+        {
+            return DistanceInMeters(
+                new Topology.Geometries.Point(x1, y1),
+                new Topology.Geometries.Point(x2, y2));
+        }
+
+        /// <summary>
+        /// Calculates the distance from one point to another, in meters
+        /// </summary>
+        /// <param name="p1">One point</param>
+        /// <param name="p2">Another point</param>
+        /// <returns>The distance in meters</returns>
+        protected abstract double DistanceInMeters(IPoint p1, IPoint p2);
+    }
+}

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemCatalog.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemCatalog.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemCatalog.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -32,14 +32,14 @@
         /// Gets an array of all coordinate systems in this catalog
         /// </summary>
         /// <value></value>
-        public virtual CoordinateSystemBase[] Coordsys
+        public virtual CoordinateSystemDefinitionBase[] Coordsys
         {
             get
             {
-                List<CoordinateSystemBase> items = new List<CoordinateSystemBase>();
+                List<CoordinateSystemDefinitionBase> items = new List<CoordinateSystemDefinitionBase>();
                 foreach (CoordinateSystemCategory cat in this.Categories)
                 {
-                    foreach (CoordinateSystemBase coord in cat.Items)
+                    foreach (CoordinateSystemDefinitionBase coord in cat.Items)
                     {
                         items.Add(coord);
                     }
@@ -53,13 +53,13 @@
         /// </summary>
         /// <param name="coordcode"></param>
         /// <returns></returns>
-        public virtual CoordinateSystemBase FindCoordSys(string coordcode)
+        public virtual CoordinateSystemDefinitionBase FindCoordSys(string coordcode)
         {
             try
             {
                 foreach (CoordinateSystemCategory cat in this.Categories)
                 {
-                    foreach (CoordinateSystemBase coord in cat.Items)
+                    foreach (CoordinateSystemDefinitionBase coord in cat.Items)
                     {
                         if (coord.Code == coordcode)
                             return coord;
@@ -77,7 +77,7 @@
         /// Gets an empty coordinate system
         /// </summary>
         /// <returns></returns>
-        public abstract CoordinateSystemBase CreateEmptyCoordinateSystem();
+        public abstract CoordinateSystemDefinitionBase CreateEmptyCoordinateSystem();
 
         /// <summary>
         /// Gets an array of coordinate system categories
@@ -124,7 +124,7 @@
         /// </summary>
         /// <param name="category"></param>
         /// <returns></returns>
-        public abstract CoordinateSystemBase[] EnumerateCoordinateSystems(string category);
+        public abstract CoordinateSystemDefinitionBase[] EnumerateCoordinateSystems(string category);
 
         /// <summary>
         /// Checks if the specified WKT is valid

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemCategory.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemCategory.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/CoordinateSystemCategory.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -30,7 +30,7 @@
     {
         private ICoordinateSystemCatalog _parent;
 		private string m_name;
-        private CoordinateSystemBase[] m_items;
+        private CoordinateSystemDefinitionBase[] m_items;
 
         /// <summary>
         /// Initializes a new instance of the <see cref="CoordinateSystemCategory"/> class.
@@ -54,7 +54,7 @@
         /// <summary>
         /// Gets an array of all coordinate systems in this category
         /// </summary>
-		public CoordinateSystemBase[] Items
+		public CoordinateSystemDefinitionBase[] Items
 		{
 			get
 			{

Added: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/DegreeBasedCoordinateSystem.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/DegreeBasedCoordinateSystem.cs	                        (rev 0)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/DegreeBasedCoordinateSystem.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -0,0 +1,33 @@
+#region Disclaimer / License
+// Copyright (C) 2010, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OSGeo.MapGuide.MaestroAPI.CoordinateSystem
+{
+    public class DegreeBasedCoordinateSystem : MeterBasedCoordinateSystem
+    {
+        internal DegreeBasedCoordinateSystem()
+            : base(10000000 / 90, 10000000 / 90)
+        {
+        }
+    }
+}

Added: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/FeetBasedCoordinateSystem.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/FeetBasedCoordinateSystem.cs	                        (rev 0)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/FeetBasedCoordinateSystem.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -0,0 +1,34 @@
+#region Disclaimer / License
+// Copyright (C) 2010, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OSGeo.MapGuide.MaestroAPI.CoordinateSystem
+{
+    public class FeetBasedCoordinateSystem : MeterBasedCoordinateSystem
+    {
+        internal FeetBasedCoordinateSystem()
+            : base(0.3048, 0.3048)
+        {
+
+        }
+    }
+}

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ICoordinateSystemCatalog.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ICoordinateSystemCatalog.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/ICoordinateSystemCatalog.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -61,27 +61,27 @@
         /// <summary>
         /// Gets an array of all coordinate systems in this catalog
         /// </summary>
-        CoordinateSystemBase[] Coordsys { get; }
+        CoordinateSystemDefinitionBase[] Coordsys { get; }
         
         /// <summary>
         /// Gets an array of all coordinate systems in the specified category
         /// </summary>
         /// <param name="category"></param>
         /// <returns></returns>
-        CoordinateSystemBase[] EnumerateCoordinateSystems(string category);
+        CoordinateSystemDefinitionBase[] EnumerateCoordinateSystems(string category);
 
         /// <summary>
         /// Gets the coordinate system that matches the specified code
         /// </summary>
         /// <param name="coordcode"></param>
         /// <returns></returns>
-        CoordinateSystemBase FindCoordSys(string coordcode);
+        CoordinateSystemDefinitionBase FindCoordSys(string coordcode);
         
         /// <summary>
         /// Gets an empty coordinate system
         /// </summary>
         /// <returns></returns>
-        CoordinateSystemBase CreateEmptyCoordinateSystem();
+        CoordinateSystemDefinitionBase CreateEmptyCoordinateSystem();
 
         /// <summary>
         /// Checks if the specified WKT is valid

Added: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/MeterBasedCoordinateSystem.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/MeterBasedCoordinateSystem.cs	                        (rev 0)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/CoordinateSystem/MeterBasedCoordinateSystem.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -0,0 +1,86 @@
+#region Disclaimer / License
+// Copyright (C) 2010, Jackie Ng
+// http://trac.osgeo.org/mapguide/wiki/maestro, jumpinjackie at gmail.com
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// 
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+// 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+// 
+#endregion
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Topology.Geometries;
+using System.Drawing;
+
+namespace OSGeo.MapGuide.MaestroAPI.CoordinateSystem
+{
+    public class MeterBasedCoordinateSystem : CoordinateSystemBase
+    {
+        //Dots pr inch
+        protected const double DPI = 96;
+
+        //Inches pr meter
+        protected const double IPM = 39.3700787;
+
+        //Coordsys distance pr unit in meters, X/Y axis
+        protected readonly double UDM_X = 1;
+        protected readonly double UDM_Y = 1;
+
+        internal MeterBasedCoordinateSystem() { }
+
+        internal MeterBasedCoordinateSystem(double meters_pr_x_unit, double meters_pr_y_unit)
+            : this()
+        {
+            UDM_X = meters_pr_x_unit;
+            UDM_Y = meters_pr_y_unit;
+        }
+
+        public override double MetersPerUnitX { get { return UDM_X; } }
+
+        public override double MetersPerUnitY { get { return UDM_Y; } }
+
+        protected override double CalculateScale(IEnvelope bbox, Size size)
+        {
+            double picture_width_in_meters = (size.Width / DPI) / IPM;
+            double picture_height_in_meters = (size.Height / DPI) / IPM;
+
+            double map_width_in_meters = bbox.Width * UDM_X;
+            double map_height_in_meters = bbox.Height * UDM_Y;
+
+            double width_scale = map_width_in_meters / picture_width_in_meters;
+            double height_scale = map_height_in_meters / picture_height_in_meters;
+
+            return Math.Max(width_scale, height_scale);
+        }
+
+        protected override Topology.Geometries.IEnvelope AdjustBoundingBox(IEnvelope bbox, double scale, Size size)
+        {
+            double picture_width_in_meters = ((size.Width / DPI) / IPM) * scale; 
+            double picture_height_in_meters = ((size.Height / DPI) / IPM) * scale;
+
+            double width_extent = picture_width_in_meters / UDM_X;
+            double height_extent = picture_height_in_meters / UDM_Y;
+
+            return new Envelope(bbox.Centre.X - (width_extent / 2), bbox.Centre.X + (width_extent / 2), bbox.Centre.Y - (height_extent / 2), bbox.Centre.Y + (height_extent / 2));
+        }
+
+        protected override double DistanceInMeters(Topology.Geometries.IPoint p1, Topology.Geometries.IPoint p2)
+        {
+            double xdist = Math.Abs(p1.X - p2.X);
+            double ydist = Math.Abs(p1.Y - p2.Y);
+
+            return Math.Sqrt((xdist * xdist) + (ydist * ydist));            
+        }
+    }
+}

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/IServerConnection.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/IServerConnection.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/IServerConnection.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -24,6 +24,7 @@
 using OSGeo.MapGuide.MaestroAPI.Commands;
 using OSGeo.MapGuide.MaestroAPI.CoordinateSystem;
 using OSGeo.MapGuide.ObjectModels.LoadProcedure;
+using System.Collections.Specialized;
 
 namespace OSGeo.MapGuide.MaestroAPI
 {
@@ -46,6 +47,18 @@
     public interface IServerConnection
     {
         /// <summary>
+        /// Gets the name of the provider of this implementation
+        /// </summary>
+        string ProviderName { get; }
+
+        /// <summary>
+        /// Gets a collection of name-value parameters required to create another copy
+        /// of this connection via the <see cref="T:OSGeo.MapGuide.MaestroAPI.ConnectionProviderRegistry"/>
+        /// </summary>
+        /// <returns></returns>
+        NameValueCollection CloneParameters { get; }
+
+        /// <summary>
         /// Returns a clone copy of this connection
         /// </summary>
         /// <returns></returns>

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/OSGeo.MapGuide.MaestroAPI.csproj	2010-12-09 07:21:20 UTC (rev 5451)
@@ -166,6 +166,7 @@
     <Compile Include="..\Properties\GlobalAssemblyInfo.cs">
       <Link>GlobalAssemblyInfo.cs</Link>
     </Compile>
+    <Compile Include="ArgumentParser.cs" />
     <Compile Include="BindingListExtensions.cs" />
     <Compile Include="Commands\IGetResourceContents.cs" />
     <Compile Include="Capability\ConnectionCapabilities.cs" />
@@ -173,6 +174,11 @@
     <Compile Include="Commands\CommandType.cs" />
     <Compile Include="Commands\ExecuteLoadProcedure.cs" />
     <Compile Include="Commands\ICommand.cs" />
+    <Compile Include="CoordinateSystem\ActualCoordinateSystem.cs" />
+    <Compile Include="CoordinateSystem\DegreeBasedCoordinateSystem.cs" />
+    <Compile Include="CoordinateSystem\CoordinateSystemBase.cs" />
+    <Compile Include="CoordinateSystem\FeetBasedCoordinateSystem.cs" />
+    <Compile Include="CoordinateSystem\MeterBasedCoordinateSystem.cs" />
     <Compile Include="Exceptions\CustomPropertyNotFoundException.cs" />
     <Compile Include="Exceptions\ExpressionException.cs" />
     <Compile Include="Exceptions\MaestroException.cs" />

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/PlatformConnectionBase.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -29,10 +29,11 @@
 using OSGeo.MapGuide.MaestroAPI.Resource;
 using OSGeo.MapGuide.MaestroAPI.Commands;
 using OSGeo.MapGuide.MaestroAPI.Mapping;
+using OSGeo.MapGuide.MaestroAPI.Serialization;
+using OSGeo.MapGuide.MaestroAPI.CoordinateSystem;
 using OSGeo.MapGuide.ObjectModels.MapDefinition;
-using OSGeo.MapGuide.MaestroAPI.Serialization;
 using OSGeo.MapGuide.ObjectModels.Common;
-using CS = Topology.CoordinateSystems;
+using System.Collections.Specialized;
 
 namespace OSGeo.MapGuide.MaestroAPI
 {
@@ -234,6 +235,18 @@
         #endregion
 
         /// <summary>
+        /// Gets the name of the provider of this implementation
+        /// </summary>
+        public abstract string ProviderName { get; }
+
+        /// <summary>
+        /// Gets a collection of name-value parameters required to create another copy
+        /// of this connection via the <see cref="T:OSGeo.MapGuide.MaestroAPI.ConnectionProviderRegistry"/>
+        /// </summary>
+        /// <returns></returns>
+        public abstract NameValueCollection CloneParameters { get; }
+
+        /// <summary>
         /// Gets the current SessionID.
         /// </summary>
         abstract public string SessionID { get; }
@@ -1679,27 +1692,32 @@
         #endregion
 
         #region runtime map
-        
-        private static string ParseUnit(string wkt)
+
+        protected virtual double InferMPU(string csWkt, double units)
         {
-            if (string.IsNullOrEmpty(wkt))
-                return null;
-            
-            int index = wkt.IndexOf("UNIT[\"");
-            if (index >= 0)
-            {
-                int end = wkt.IndexOf("\"", index);
-                return wkt.Substring(index, end - index).ToUpper();
-            }
-            return null;
+            var cs = CoordinateSystemBase.Create(csWkt);
+            return cs.MetersPerUnitX * units;
         }
 
+        public RuntimeMap CreateMap(string runtimeMapResourceId, string baseMapDefinitionId)
+        {
+            var mdf = (IMapDefinition)GetResource(baseMapDefinitionId);
+            var mpu = InferMPU(mdf.CoordinateSystem, 1.0);
+            return CreateMap(runtimeMapResourceId, mdf, mpu);
+        }
+
         public virtual RuntimeMap CreateMap(string runtimeMapResourceId, string baseMapDefinitionId, double metersPerUnit)
         {
             var mdf = (IMapDefinition)GetResource(baseMapDefinitionId);
             return CreateMap(runtimeMapResourceId, mdf, metersPerUnit);
         }
 
+        public RuntimeMap CreateMap(string runtimeMapResourceId, IMapDefinition mdf)
+        {
+            var mpu = InferMPU(mdf.CoordinateSystem, 1.0);
+            return CreateMap(runtimeMapResourceId, mdf, mpu);
+        }
+
         public virtual RuntimeMap CreateMap(string runtimeMapResourceId, IMapDefinition mdf, double metersPerUnit)
         {
             var map = new RuntimeMap(mdf, metersPerUnit);

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI/Services/IMappingService.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -31,6 +31,22 @@
     public interface IMappingService : IService
     {
         /// <summary>
+        /// Creates a new runtime map instance from an existing map definition. Meters per unit
+        /// is calculated from the Coordinate System WKT of the map definition.
+        /// </summary>
+        /// <remarks>
+        /// Calculation of meters-per-unit may differ between implementations. This may have an adverse
+        /// effect on things such as rendering and measuring depending on the underlying implementation
+        /// 
+        /// If you are certain of the meters-per-unit value required, use the overloaded method that 
+        /// accepts a metersPerUnit parameter.
+        /// </remarks>
+        /// <param name="runtimeMapResourceId"></param>
+        /// <param name="baseMapDefinitionId"></param>
+        /// <returns></returns>
+        RuntimeMap CreateMap(string runtimeMapResourceId, string baseMapDefinitionId);
+
+        /// <summary>
         /// Creates a new runtime map instance from an existing map definition
         /// </summary>
         /// <param name="runtimeMapResourceId"></param>
@@ -40,6 +56,22 @@
         RuntimeMap CreateMap(string runtimeMapResourceId, string baseMapDefinitionId, double metersPerUnit);
 
         /// <summary>
+        /// Creates a new runtime map instance from an existing map definition. Meters per unit
+        /// is calculated from the Coordinate System WKT of the map definition.
+        /// </summary>
+        /// <remarks>
+        /// Calculation of meters-per-unit may differ between implementations. This may have an adverse
+        /// effect on things such as rendering and measuring depending on the underlying implementation
+        /// 
+        /// If you are certain of the meters-per-unit value required, use the overloaded method that 
+        /// accepts a metersPerUnit parameter.
+        /// </remarks>
+        /// <param name="runtimeMapResourceId"></param>
+        /// <param name="mdf"></param>
+        /// <returns></returns>
+        RuntimeMap CreateMap(string runtimeMapResourceId, IMapDefinition mdf);
+
+        /// <summary>
         /// Creates a new runtime map instance from an existing map definition
         /// </summary>
         /// <param name="runtimeMapResourceId"></param>

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystem.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystem.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystem.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -29,11 +29,11 @@
 	/// Interface to MapGuide coordinate system functions.
 	/// Only works with server > 1.2, since the coordinate mapping is not avalible through Http on older versions
 	/// </summary>
-    public class HttpCoordinateSystem : CoordinateSystem.CoordinateSystemBase
+    public class HttpCoordinateSystemDefinition : CoordinateSystem.CoordinateSystemDefinitionBase
 	{
-        internal HttpCoordinateSystem() : base() { }
+        internal HttpCoordinateSystemDefinition() : base() { }
 
-        internal HttpCoordinateSystem(CoordinateSystemCategory parent, XmlNode topnode) : base(parent)
+        internal HttpCoordinateSystemDefinition(CoordinateSystemCategory parent, XmlNode topnode) : base(parent)
 		{
             foreach (XmlNode node in topnode.ChildNodes)
             {

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystemCatalog.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystemCatalog.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpCoordinateSystemCatalog.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -106,7 +106,7 @@
 
         public override bool IsLoaded { get { return m_categories != null; } }
 
-        public override CoordinateSystem.CoordinateSystemBase[] EnumerateCoordinateSystems(string category)
+        public override CoordinateSystem.CoordinateSystemDefinitionBase[] EnumerateCoordinateSystems(string category)
         {
             CoordinateSystemCategory cat = null;
             foreach (CoordinateSystemCategory csc in this.Categories)
@@ -119,22 +119,22 @@
             }
 
             if (cat == null)
-                return new CoordinateSystemBase[0];
+                return new CoordinateSystemDefinitionBase[0];
 
             string req = this.RequestBuilder.EnumerateCoordinateSystems(category);
             XmlDocument doc = new XmlDocument();
             doc.Load(m_con.OpenRead(req));
             XmlNodeList lst = doc.SelectNodes("BatchPropertyCollection/PropertyCollection");
-            CoordinateSystemBase[] data = new CoordinateSystemBase[lst.Count];
+            CoordinateSystemDefinitionBase[] data = new CoordinateSystemDefinitionBase[lst.Count];
             for (int i = 0; i < lst.Count; i++)
-                data[i] = new HttpCoordinateSystem(cat, lst[i]);
+                data[i] = new HttpCoordinateSystemDefinition(cat, lst[i]);
 
             return data;
         }
 
-        public override CoordinateSystem.CoordinateSystemBase CreateEmptyCoordinateSystem()
+        public override CoordinateSystem.CoordinateSystemDefinitionBase CreateEmptyCoordinateSystem()
         {
-            return new HttpCoordinateSystem();
+            return new HttpCoordinateSystemDefinition();
         }
     }
 }

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Http/HttpServerConnection.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -78,6 +78,23 @@
             m_reqBuilder = builder;
         }
 
+        public override NameValueCollection CloneParameters
+        {
+            get
+            {
+                var nvc = new NameValueCollection();
+                nvc["Url"] = this.BaseURL;
+                nvc[CommandLineArguments.Provider] = this.ProviderName;
+                nvc[CommandLineArguments.Session] = this.SessionID;
+                return nvc;
+            }
+        }
+
+        public override string ProviderName
+        {
+            get { return "Maestro.Http"; }
+        }
+
         /// <summary>
         /// Gets whether this connection was initialised with an Anonymous login. If it was, it will return true. 
         /// If this was not, or it was initialised from an existing session id, then it will return false.

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeConnection.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -99,6 +99,23 @@
             }
         }
 
+        public override string ProviderName
+        {
+            get { return "Maestro.LocalNative"; }
+        }
+
+        public override NameValueCollection CloneParameters
+        {
+            get
+            {
+                var nvc = new NameValueCollection();
+                nvc[PARAM_CONFIG] = m_webconfig;
+                nvc[CommandLineArguments.Provider] = this.ProviderName;
+                nvc[CommandLineArguments.Session] = this.SessionID;
+                return nvc;
+            }
+        }
+
         private void InitConnection(string sessionid)
         {
             MgUserInformation mgui = new MgUserInformation(sessionid);
@@ -141,6 +158,25 @@
 			}
 		}
 
+        protected override double InferMPU(string csWkt, double units)
+        {
+            try
+            {
+                MgCoordinateSystemFactory csFact = new MgCoordinateSystemFactory();
+                MgCoordinateSystem cs = csFact.Create(csWkt);
+                return cs.ConvertMetersToCoordinateSystemUnits(units);
+            }
+            catch (MgException ex) //Not implemented due to wrapping Proj.4?
+            {
+                ex.Dispose();
+                return base.InferMPU(csWkt, units);
+            }
+            catch (Exception ex) //Binding to assembly with pre-refactored CS API?
+            {
+                return base.InferMPU(csWkt, units);
+            }
+        }
+
 		public override ResourceList GetRepositoryResources(string startingpoint, string type, int depth, bool computeChildren)
 		{
 			if (type == null)

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystem.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -25,11 +25,11 @@
 
 namespace OSGeo.MapGuide.MaestroAPI.Native
 {
-    public class LocalNativeCoordinateSystem : CoordinateSystemBase
+    public class LocalNativeCoordinateSystemDefinition : CoordinateSystemDefinitionBase
     {
-        internal LocalNativeCoordinateSystem() : base() { }
+        internal LocalNativeCoordinateSystemDefinition() : base() { }
 
-        internal LocalNativeCoordinateSystem(CoordinateSystemCategory parent, MgPropertyCollection props)
+        internal LocalNativeCoordinateSystemDefinition(CoordinateSystemCategory parent, MgPropertyCollection props)
             : base(parent)
         {
             for (int i = 0; i < props.Count; i++)

Modified: sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs
===================================================================
--- sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs	2010-12-09 01:19:32 UTC (rev 5450)
+++ sandbox/maestro-3.0/OSGeo.MapGuide.MaestroAPI.Native/LocalNativeCoordinateSystemCatalog.cs	2010-12-09 07:21:20 UTC (rev 5451)
@@ -92,7 +92,7 @@
 
         public override bool IsLoaded { get { return m_categories != null; } }
 
-        public override CoordinateSystemBase[] EnumerateCoordinateSystems(string category)
+        public override CoordinateSystemDefinitionBase[] EnumerateCoordinateSystems(string category)
         {
             CoordinateSystemCategory cat = null;
             foreach (CoordinateSystemCategory csc in this.Categories)
@@ -105,19 +105,19 @@
             }
 
             if (cat == null)
-                return new CoordinateSystemBase[0];
+                return new CoordinateSystemDefinitionBase[0];
 
             MgBatchPropertyCollection bp = m_cf.EnumerateCoordinateSystems(category);
-            List<CoordinateSystemBase> lst = new List<CoordinateSystemBase>();
+            List<CoordinateSystemDefinitionBase> lst = new List<CoordinateSystemDefinitionBase>();
             for (int i = 0; i < bp.Count; i++)
-                lst.Add(new LocalNativeCoordinateSystem(cat, bp[i]));
+                lst.Add(new LocalNativeCoordinateSystemDefinition(cat, bp[i]));
 
             return lst.ToArray();
         }
 
-        public override CoordinateSystemBase CreateEmptyCoordinateSystem()
+        public override CoordinateSystemDefinitionBase CreateEmptyCoordinateSystem()
         {
-            return new LocalNativeCoordinateSystem();
+            return new LocalNativeCoordinateSystemDefinition();
         }
     }
 }



More information about the mapguide-commits mailing list