protected void CreateTestDataStore(IServerConnection conn, string fsId, ref FeatureSchema schema, ref ClassDefinition cls)
        {
            schema = new FeatureSchema("Default", "");
            cls    = new ClassDefinition("Class1", "");

            try
            {
                if (conn.ResourceService.ResourceExists(fsId))
                {
                    conn.ResourceService.DeleteResource(fsId);
                }

                cls.DefaultGeometryPropertyName = "GEOM";
                cls.AddProperty(new DataPropertyDefinition("KEY", "")
                {
                    DataType        = DataPropertyType.Int32,
                    IsAutoGenerated = true,
                    IsReadOnly      = true,
                    IsNullable      = false
                }, true);

                cls.AddProperty(new DataPropertyDefinition("NAME", "")
                {
                    DataType   = DataPropertyType.String,
                    Length     = 255,
                    IsNullable = true,
                    IsReadOnly = false
                });

                cls.AddProperty(new GeometricPropertyDefinition("GEOM", "")
                {
                    GeometricTypes            = FeatureGeometricType.Point,
                    SpatialContextAssociation = "Default"
                });

                schema.AddClass(cls);

                ICreateDataStore create = (ICreateDataStore)conn.CreateCommand((int)CommandType.CreateDataStore);
                CoordinateSystemDefinitionBase coordSys = conn.CoordinateSystemCatalog.FindCoordSys("LL84");
                create.FeatureSourceId     = fsId;
                create.CoordinateSystemWkt = coordSys.WKT;
                create.Name        = "Default";
                create.ExtentType  = OSGeo.MapGuide.ObjectModels.Common.FdoSpatialContextListSpatialContextExtentType.Dynamic;
                create.FileName    = "Test.sdf";
                create.Provider    = "OSGeo.SDF";
                create.Schema      = schema;
                create.XYTolerance = 0.001;
                create.ZTolerance  = 0.001;

                create.Execute();
            }
            catch
            {
                schema = null;
                cls    = null;
                throw;
            }
        }
        protected void PopulateTestDataStore(IServerConnection conn, string fsId, ref FeatureSchema schema, ref ClassDefinition cls)
        {
            CreateTestDataStore(conn, fsId, ref schema, ref cls);

            IInsertFeatures insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature);

            insert.ClassName       = cls.Name;
            insert.FeatureSourceId = fsId;
            var feat = new MutableRecord();

            var reader = new FixedWKTReader();

            //Initialize this record
            feat.PutValue("GEOM", new GeometryValue(reader.Read("POINT (0 0)")));
            feat.PutValue("NAME", new StringValue("Test1"));

            //Attach to command.
            insert.RecordToInsert = feat;

            var res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (0 1)"));
            feat.SetString("NAME", "Test2");

            res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (1 1)"));
            feat.SetString("NAME", "Test3");

            res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (1 0)"));
            feat.SetString("NAME", "Test4");

            res = insert.Execute();
        }
Ejemplo n.º 3
0
        private void TryCalcMpu(string mapDef)
        {
            BusyWaitDialog.Run(Strings.CalculatingMpu, () =>
            {
                var currentPath = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
                var mpuCalc     = Path.Combine(currentPath, "AddIns/Local/MpuCalc.exe"); //NOXLATE
                if (!File.Exists(mpuCalc) && mapDef.EndsWith(ResourceTypes.MapDefinition.ToString()))
                {
                    int[] cmdTypes = m_connection.Capabilities.SupportedCommands;
                    if (Array.IndexOf(cmdTypes, (int)OSGeo.MapGuide.MaestroAPI.Commands.CommandType.CreateRuntimeMap) < 0)
                    {
                        IMapDefinition mdf = (IMapDefinition)m_connection.ResourceService.GetResource(mapDef);
                        var calc           = m_connection.GetCalculator();
                        return(new MpuCalcResult()
                        {
                            Method = MpuMethod.BuiltIn,
                            Result = Convert.ToDecimal(calc.Calculate(mdf.CoordinateSystem, 1.0))
                        });
                    }
                    else
                    {
                        ICreateRuntimeMap create = (ICreateRuntimeMap)m_connection.CreateCommand((int)OSGeo.MapGuide.MaestroAPI.Commands.CommandType.CreateRuntimeMap);
                        create.MapDefinition     = mapDef;
                        create.RequestedFeatures = (int)RuntimeMapRequestedFeatures.None;
                        var info = create.Execute();
                        return(new MpuCalcResult()
                        {
                            Method = MpuMethod.CreateRuntimeMap,
                            Result = Convert.ToDecimal(info.CoordinateSystem.MetersPerUnit)
                        });
                    }
                }
                else
                {
                    IResource res          = m_connection.ResourceService.GetResource(mapDef);
                    ITileSetDefinition tsd = res as ITileSetDefinition;
                    IMapDefinition mdf     = res as IMapDefinition;

                    string coordSys = null;
                    if (mdf != null)
                    {
                        coordSys = mdf.CoordinateSystem;
                    }
                    else if (tsd != null)
                    {
                        coordSys = tsd.GetDefaultCoordinateSystem();
                    }

                    string output = string.Empty;
                    if (coordSys != null)
                    {
                        var proc = new Process
                        {
                            StartInfo = new ProcessStartInfo
                            {
                                FileName               = mpuCalc,
                                Arguments              = coordSys,
                                UseShellExecute        = false,
                                RedirectStandardOutput = true,
                                CreateNoWindow         = true
                            }
                        };
                        proc.Start();
                        StringBuilder sb = new StringBuilder();
                        while (!proc.StandardOutput.EndOfStream)
                        {
                            string line = proc.StandardOutput.ReadLine();
                            // do something with line
                            sb.AppendLine(line);
                        }
                        output = sb.ToString();
                    }
                    double mpu;
                    if (double.TryParse(output, out mpu))
                    {
                        return new MpuCalcResult()
                        {
                            Method = MpuMethod.MpuCalcExe, Result = Convert.ToDecimal(mpu)
                        }
                    }
                    ;
                    else
                    {
                        return(string.Format(Strings.FailedToCalculateMpu, output));
                    }
                }
            }, (res, ex) =>
            {
                if (ex != null)
                {
                    ErrorDialog.Show(ex);
                }
                else
                {
                    var mres = res as MpuCalcResult;
                    if (mres != null)
                    {
                        MetersPerUnit.Value = mres.Result;
                        if (mres.Method == MpuMethod.BuiltIn)
                        {
                            MessageBox.Show(Strings.ImperfectMpuCalculation);
                        }
                    }
                    else
                    {
                        MessageBox.Show(res.ToString());
                    }
                }
            });
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Initializes this instance
        /// </summary>
        /// <param name="conn"></param>
        protected internal RuntimeMap(IServerConnection conn)
        {
            this.StrictSelection = true;
            this.IsDirty = false;
            _disableChangeTracking = true;

            this.WatermarkUsage = (int)WatermarkUsageType.Viewer;
            this.SiteVersion = conn.SiteVersion;
            this.SessionId = conn.SessionID;
            this.ObjectId = Guid.NewGuid().ToString();
            m_changeList = new Dictionary<string, ChangeList>();
            _finiteDisplayScales = new double[0];
            this.CurrentConnection = conn;
            if (Array.IndexOf(conn.Capabilities.SupportedServices, (int)ServiceType.Mapping) >= 0)
            {
                _mapSvc = (IMappingService)conn.GetService((int)ServiceType.Mapping);
            }
            if (Array.IndexOf(conn.Capabilities.SupportedCommands, (int)CommandType.GetResourceContents) >= 0)
            {
                _getRes = (IGetResourceContents)conn.CreateCommand((int)CommandType.GetResourceContents);
            }
            this.Layers = new RuntimeMapLayerCollection(this);
            this.Groups = new RuntimeMapGroupCollection(this);
        }
Ejemplo n.º 5
0
        protected void PopulateTestDataStore(IServerConnection conn, string fsId, ref FeatureSchema schema, ref ClassDefinition cls)
        {
            CreateTestDataStore(conn, fsId, ref schema, ref cls);

            IInsertFeatures insert = (IInsertFeatures)conn.CreateCommand((int)CommandType.InsertFeature);
            insert.ClassName = cls.Name;
            insert.FeatureSourceId = fsId;
            var feat = new MutableRecord();

            var reader = new FixedWKTReader();

            //Initialize this record
            feat.PutValue("GEOM", new GeometryValue(reader.Read("POINT (0 0)")));
            feat.PutValue("NAME", new StringValue("Test1"));

            //Attach to command.
            insert.RecordToInsert = feat;

            var res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (0 1)"));
            feat.SetString("NAME", "Test2");

            res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (1 1)"));
            feat.SetString("NAME", "Test3");

            res = insert.Execute();

            feat.SetGeometry("GEOM", reader.Read("POINT (1 0)"));
            feat.SetString("NAME", "Test4");

            res = insert.Execute();
        }
Ejemplo n.º 6
0
        protected void CreateTestDataStore(IServerConnection conn, string fsId, ref FeatureSchema schema, ref ClassDefinition cls)
        {
            schema = new FeatureSchema("Default", "");
            cls = new ClassDefinition("Class1", "");

            try
            {
                if (conn.ResourceService.ResourceExists(fsId))
                    conn.ResourceService.DeleteResource(fsId);

                cls.DefaultGeometryPropertyName = "GEOM";
                cls.AddProperty(new DataPropertyDefinition("KEY", "")
                {
                    DataType = DataPropertyType.Int32,
                    IsAutoGenerated = true,
                    IsReadOnly = true,
                    IsNullable = false
                }, true);

                cls.AddProperty(new DataPropertyDefinition("NAME", "")
                {
                    DataType = DataPropertyType.String,
                    Length = 255,
                    IsNullable = true,
                    IsReadOnly = false
                });

                cls.AddProperty(new GeometricPropertyDefinition("GEOM", "")
                {
                    GeometricTypes = FeatureGeometricType.Point,
                    SpatialContextAssociation = "Default"
                });

                schema.AddClass(cls);

                ICreateDataStore create = (ICreateDataStore)conn.CreateCommand((int)CommandType.CreateDataStore);
                CoordinateSystemDefinitionBase coordSys = conn.CoordinateSystemCatalog.FindCoordSys("LL84");
                create.FeatureSourceId = fsId;
                create.CoordinateSystemWkt = coordSys.WKT;
                create.Name = "Default";
                create.ExtentType = OSGeo.MapGuide.ObjectModels.Common.FdoSpatialContextListSpatialContextExtentType.Dynamic;
                create.FileName = "Test.sdf";
                create.Provider = "OSGeo.SDF";
                create.Schema = schema;
                create.XYTolerance = 0.001;
                create.ZTolerance = 0.001;

                create.Execute();
            }
            catch
            {
                schema = null;
                cls = null;
                throw;
            }
        }