Data Transfer Object for Spatial Contexts
Пример #1
0
        /// <summary>
        /// Loads a FDO XML configuration document
        /// </summary>
        /// <param name="xmlFile"></param>
        /// <returns></returns>
        public static FdoDataStoreConfiguration FromFile(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
                using (var ios = new IoFileStream(xmlFile, "r"))
                {
                    using (var reader = new XmlReader(ios))
                    {
                        List <SpatialContextInfo> contexts = new List <SpatialContextInfo>();
                        using (var scReader = new XmlSpatialContextReader(reader))
                        {
                            while (scReader.ReadNext())
                            {
                                var sc = new SpatialContextInfo();
                                sc.CoordinateSystem    = scReader.GetCoordinateSystem();
                                sc.CoordinateSystemWkt = scReader.GetCoordinateSystemWkt();
                                sc.Description         = scReader.GetDescription();
                                sc.ExtentType          = scReader.GetExtentType();
                                if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Static)
                                {
                                    using (var geom = fact.CreateGeometryFromFgf(scReader.GetExtent()))
                                    {
                                        sc.ExtentGeometryText = geom.Text;
                                    }
                                }
                                sc.IsActive    = scReader.IsActive();
                                sc.Name        = scReader.GetName();
                                sc.XYTolerance = scReader.GetXYTolerance();
                                sc.ZTolerance  = scReader.GetZTolerance();

                                contexts.Add(sc);
                            }
                        }

                        ios.Reset();

                        var schemas = new FeatureSchemaCollection(null);
                        schemas.ReadXml(ios);

                        ios.Reset();

                        var mappings = new PhysicalSchemaMappingCollection();
                        mappings.ReadXml(ios);

                        ios.Close();

                        return(new FdoDataStoreConfiguration(schemas, contexts.ToArray(), mappings));
                    }
                }
        }
Пример #2
0
        internal SpatialContextInfo Clone()
        {
            var sc = new SpatialContextInfo();

            sc.CoordinateSystem    = this.CoordinateSystem;
            sc.CoordinateSystemWkt = this.CoordinateSystemWkt;
            sc.Description         = this.Description;
            sc.ExtentGeometryText  = this.ExtentGeometryText;
            sc.ExtentType          = this.ExtentType;
            sc.IsActive            = this.IsActive;
            sc.Name        = this.Name;
            sc.XYTolerance = this.XYTolerance;
            sc.ZTolerance  = this.ZTolerance;

            return(sc);
        }
Пример #3
0
        public virtual SpatialContextInfo CreateDefaultSpatialContext()
        {
            var sc = new SpatialContextInfo();
            sc.Name = "Default";
            sc.XYTolerance = sc.ZTolerance = this.Tolerance;
            sc.CoordinateSystem = this.CSName;
            if (_presenter.RequiresWKT)
                sc.CoordinateSystemWkt = this.CSWkt;

            sc.IsActive = true;
            sc.ExtentType = this.ExtentType;
            if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Static)
            {
                string wktfmt = "POLYGON (({0} {1}, {2} {3}, {4} {5}, {6} {7}, {0} {1}))";
                double llx = Convert.ToDouble(this.LowerLeftX);
                double lly = Convert.ToDouble(this.LowerLeftY);
                double urx = Convert.ToDouble(this.UpperRightX);
                double ury = Convert.ToDouble(this.UpperRightY);
                sc.ExtentGeometryText = string.Format(wktfmt,
                    llx, lly,
                    urx, lly,
                    urx, ury,
                    llx, ury,
                    llx, lly);
            }
            return sc;
        }
 public void SetSpatialContext(SpatialContextInfo sci)
 {
     _view.NameEnabled = false;
     _view.ContextName = sci.Name;
     _view.CoordinateSystem = sci.CoordinateSystem;
     _view.CoordinateSystemWkt = sci.CoordinateSystemWkt;
     _view.Description = sci.Description;
     if (!string.IsNullOrEmpty(sci.ExtentGeometryText))
     {
         using (FdoFeatureService service = _conn.CreateFeatureService())
         {
             using (IGeometry geom = service.GeometryFactory.CreateGeometry(sci.ExtentGeometryText))
             {
                 _view.LowerLeftX = geom.Envelope.MinX.ToString();
                 _view.UpperRightX = geom.Envelope.MaxX.ToString();
                 _view.LowerLeftY = geom.Envelope.MinY.ToString();
                 _view.UpperRightY = geom.Envelope.MaxY.ToString();
             }
         }
     }
     _view.XYTolerance = sci.XYTolerance.ToString();
     _view.ZTolerance = sci.ZTolerance.ToString();
 }
Пример #5
0
 /// <summary>
 /// Determines if the given spatial context in the list of spatial context names
 /// </summary>
 /// <param name="ctx">The spatial context</param>
 /// <param name="names">The spatial context name list</param>
 /// <returns></returns>
 protected bool SpatialContextInSpecifiedList(SpatialContextInfo ctx, string[] names)
 {
     return Array.Exists<string>(names, delegate(string s) { return s == ctx.Name; });
 }
Пример #6
0
 /// <summary>
 /// Determines if a given spatial context exists in the given collection (comparison is by name). 
 /// </summary>
 /// <param name="targetContexts">The target spatial context list</param>
 /// <param name="sc">The spatial context to look for</param>
 /// <returns></returns>
 protected static bool SpatialContextExists(ReadOnlyCollection<SpatialContextInfo> targetContexts, SpatialContextInfo sc)
 {
     bool found = false;
     foreach (SpatialContextInfo tsc in targetContexts)
     {
         if (tsc.Name == sc.Name)
         {
             found = true;
             break;
         }
     }
     return found;
 }
Пример #7
0
        internal void UpdateSpatialContext(SpatialContextInfo sc)
        {
            this.SpatialContextsChanged = true;
            SpatialContextInfo edit = null;
            foreach (var context in _spatialContexts)
            {
                if (context.Name == sc.Name)
                {
                    edit = context;
                }
            }

            if (edit != null)
            {
                edit.CoordinateSystem = sc.CoordinateSystem;
                edit.CoordinateSystemWkt = sc.CoordinateSystemWkt;
                edit.Description = sc.Description;
                edit.ExtentGeometryText = sc.ExtentGeometryText;
                edit.ExtentType = sc.ExtentType;
                edit.XYTolerance = sc.XYTolerance;
                edit.ZTolerance = sc.ZTolerance;
            }
            else
            {
                _spatialContexts.Add(sc);
            }
        }
Пример #8
0
 internal void RemoveSpatialContext(SpatialContextInfo sc)
 {
     _spatialContexts.Remove(sc);
     this.SpatialContextsChanged = true;
 }
Пример #9
0
 internal void AddSpatialContext(SpatialContextInfo sc)
 {
     _spatialContexts.Add(sc);
 }
Пример #10
0
        internal SpatialContextInfo Clone()
        {
            var sc = new SpatialContextInfo();
            sc.CoordinateSystem = this.CoordinateSystem;
            sc.CoordinateSystemWkt = this.CoordinateSystemWkt;
            sc.Description = this.Description;
            sc.ExtentGeometryText = this.ExtentGeometryText;
            sc.ExtentType = this.ExtentType;
            sc.IsActive = this.IsActive;
            sc.Name = this.Name;
            sc.XYTolerance = this.XYTolerance;
            sc.ZTolerance = this.ZTolerance;

            return sc;
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="schemas"></param>
 /// <param name="contexts"></param>
 /// <param name="mappings"></param>
 public FdoDataStoreConfiguration(FeatureSchemaCollection schemas, SpatialContextInfo[] contexts, PhysicalSchemaMappingCollection mappings)
 {
     this.Schemas = schemas;
     this.SpatialContexts = contexts;
     this.Mappings = mappings;
 }
        /// <summary>
        /// Loads a FDO XML configuration document
        /// </summary>
        /// <param name="xmlFile"></param>
        /// <returns></returns>
        public static FdoDataStoreConfiguration FromFile(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
            using (var ios = new IoFileStream(xmlFile, "r"))
            {
                using (var reader = new XmlReader(ios))
                {
                    List<SpatialContextInfo> contexts = new List<SpatialContextInfo>();
                    using (var scReader = new XmlSpatialContextReader(reader))
                    {
                        while (scReader.ReadNext())
                        {
                            var sc = new SpatialContextInfo();
                            sc.CoordinateSystem = scReader.GetCoordinateSystem();
                            sc.CoordinateSystemWkt = scReader.GetCoordinateSystemWkt();
                            sc.Description = scReader.GetDescription();
                            sc.ExtentType = scReader.GetExtentType();
                            if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Static)
                            {
                                using (var geom = fact.CreateGeometryFromFgf(scReader.GetExtent()))
                                {
                                    sc.ExtentGeometryText = geom.Text;
                                }
                            }
                            sc.IsActive = scReader.IsActive();
                            sc.Name = scReader.GetName();
                            sc.XYTolerance = scReader.GetXYTolerance();
                            sc.ZTolerance = scReader.GetZTolerance();

                            contexts.Add(sc);
                        }
                    }

                    ios.Reset();

                    var schemas = new FeatureSchemaCollection(null);
                    schemas.ReadXml(ios);

                    ios.Reset();

                    var mappings = new PhysicalSchemaMappingCollection();
                    mappings.ReadXml(ios);

                    ios.Close();

                    return new FdoDataStoreConfiguration(schemas, contexts.ToArray(), mappings);
                }
            }
        }
 public FdoSpatialContextDialog(FdoConnection conn, SpatialContextInfo sci)
     : this(conn)
 {
     _presenter.SetSpatialContext(sci);
 }
 public static SpatialContextInfo Edit(FdoConnection conn, SpatialContextInfo ctx)
 {
     FdoSpatialContextDialog diag = new FdoSpatialContextDialog(conn, ctx);
     if (diag.ShowDialog() == DialogResult.OK)
     {
         SpatialContextInfo sci = new SpatialContextInfo();
         sci.Name = diag.ContextName;
         sci.Description = diag.Description;
         sci.CoordinateSystem = diag.CoordinateSystem;
         sci.CoordinateSystemWkt = diag.CoordinateSystemWkt;
         sci.XYTolerance = Convert.ToDouble(diag.XYTolerance);
         sci.ZTolerance = Convert.ToDouble(diag.ZTolerance);
         sci.ExtentType = diag.SelectedExtentType;
         //Only consider extent if all 4 values are defined
         if (diag.IsExtentDefined)
         {
             string wktfmt = "POLYGON (({0} {1}, {2} {3}, {4} {5}, {6} {7}, {0} {1}))";
             double llx = Convert.ToDouble(diag.LowerLeftX);
             double lly = Convert.ToDouble(diag.LowerLeftY);
             double urx = Convert.ToDouble(diag.UpperRightX);
             double ury = Convert.ToDouble(diag.UpperRightY);
             sci.ExtentGeometryText = string.Format(wktfmt,
                 llx, lly,
                 urx, lly,
                 urx, ury,
                 llx, ury,
                 llx, lly);
         }
         return sci;
     }
     return null;
 }
Пример #15
0
 /// <summary>
 /// Adds a spatial context.
 /// </summary>
 /// <param name="ctx">The context.</param>
 public void AddSpatialContext(SpatialContextInfo ctx)
 {
     _spatialContexts.Add(ctx);
 }
Пример #16
0
 /// <summary>
 /// Adds a spatial context.
 /// </summary>
 /// <param name="ctx">The context.</param>
 public void AddSpatialContext(SpatialContextInfo ctx)
 {
     _spatialContexts.Add(ctx);
 }