Пример #1
0
 /// <summary>
 /// Gets the FGF binary from the given text
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static byte[] GetFgf(string str)
 {
     byte[] fgf = null;
     using (FgfGeometryFactory factory = new FgfGeometryFactory())
     {
         using (IGeometry geom = factory.CreateGeometry(str))
         {
             fgf = factory.GetFgf(geom);
         }
     }
     return(fgf);
 }
        /// <summary>
        /// Saves this out to a FDO XML configuration document
        /// </summary>
        /// <param name="xmlFile"></param>
        public void Save(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
            using (var ws = new IoFileStream(xmlFile, "w"))
            {
                using (var writer = new XmlWriter(ws, true, XmlWriter.LineFormat.LineFormat_Indent))
                {
                    //Write spatial contexts
                    if (this.SpatialContexts != null && this.SpatialContexts.Length > 0)
                    {
                        var flags = new XmlSpatialContextFlags();
                        using (var scWriter = new XmlSpatialContextWriter(writer))
                        {
                            foreach (var sc in this.SpatialContexts)
                            {
                                //XmlSpatialContextWriter forbids writing dynamically calculated extents
                                if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Dynamic)
                                    continue;

                                scWriter.CoordinateSystem = sc.CoordinateSystem;
                                scWriter.CoordinateSystemWkt = sc.CoordinateSystemWkt;
                                scWriter.Description = sc.Description;
                                
                                scWriter.ExtentType = sc.ExtentType;

                                using (var geom = fact.CreateGeometry(sc.ExtentGeometryText))
                                {
                                    byte[] fgf = fact.GetFgf(geom);
                                    scWriter.Extent = fgf;
                                }

                                scWriter.Name = sc.Name;
                                scWriter.XYTolerance = sc.XYTolerance;
                                scWriter.ZTolerance = sc.ZTolerance;

                                scWriter.WriteSpatialContext();
                            }
                        }
                    }

                    

                    //Write logical schema
                    if (this.Schemas != null)
                    {
                        var schemas = CloneSchemas(this.Schemas);

                        schemas.WriteXml(writer);
                    }

                    //Write physical mappings
                    if (this.Mappings != null)
                    {
                        this.Mappings.WriteXml(writer);
                    }

                    writer.Close();
                }
                ws.Close();
            }
        }
Пример #3
0
        void RunExport(string fileName)
        {
            CadastralMapModel mapModel = CadastralMapModel.Current;

            using (ICreateDataStore cmd = m_Connection.CreateCommand(CommandType.CommandType_CreateDataStore) as ICreateDataStore)
            {
                try
                {
                    cmd.DataStoreProperties.SetProperty("File", fileName);
                    cmd.Execute();
                }
                catch (OSGeo.FDO.Common.Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

            // The connection after the created is ConnectionState_Closed, so open it!
            m_Connection.ConnectionInfo.ConnectionProperties.SetProperty("File", fileName);
            m_Connection.Open();

            // Define coordinate system
            using (ICreateSpatialContext cmd = m_Connection.CreateCommand(CommandType.CommandType_CreateSpatialContext) as ICreateSpatialContext)
            {
                ISpatialSystem ss = mapModel.SpatialSystem;
                cmd.CoordinateSystem = ss.Name; // CSMap key name
                cmd.ExtentType       = SpatialContextExtentType.SpatialContextExtentType_Static;
                IWindow         mapExtent = mapModel.Extent;
                IDirectPosition minxy     = m_Factory.CreatePositionXY(mapExtent.Min.X, mapExtent.Min.Y);
                IDirectPosition maxxy     = m_Factory.CreatePositionXY(mapExtent.Max.X, mapExtent.Max.Y);
                IEnvelope       extent    = m_Factory.CreateEnvelope(minxy, maxxy);
                IGeometry       gx        = m_Factory.CreateGeometry(extent);
                cmd.Extent              = m_Factory.GetFgf(gx);
                cmd.XYTolerance         = 0.000001; // resolution?
                cmd.CoordinateSystemWkt = EditingController.Current.GetCoordinateSystemText();
                cmd.Execute();
            }

            // Define feature schema
            FeatureSchema fs = new FeatureSchema("Steve", "This is a test");

            FeatureClass fc = new FeatureClass("FC", "Test feature class");

            fs.Classes.Add(fc);
            GeometricPropertyDefinition gp = new GeometricPropertyDefinition("Geometry", "Polygon property");

            // When you stick more than one geometric type into the output, you can't
            // convert to SHP (not with FDO Toolbox anyway).
            //gp.GeometryTypes = (int)GeometricType.GeometricType_Surface;
            gp.GeometryTypes = (int)GeometricType.GeometricType_All;
            fc.Properties.Add(gp);
            fc.GeometryProperty = gp;

            // c.f. FdoToolbox ExpressUtility
            DataPropertyDefinition dp = new DataPropertyDefinition("ID", "Test ID");

            dp.DataType        = DataType.DataType_Int32;
            dp.Nullable        = false;
            dp.ReadOnly        = true;
            dp.IsAutoGenerated = true;
            fc.Properties.Add(dp);

            // Feature class requires an identity column for the insert
            fc.IdentityProperties.Add(dp);

            using (IApplySchema cmd = m_Connection.CreateCommand(CommandType.CommandType_ApplySchema) as IApplySchema)
            {
                cmd.FeatureSchema = fs;
                cmd.Execute();
            }

            mapModel.Index.QueryWindow(null, SpatialType.Polygon | SpatialType.Point, ExportFeature);

            m_Connection.Flush();
            m_Connection.Close();
        }
Пример #4
0
        /// <summary>
        /// Saves this out to a FDO XML configuration document
        /// </summary>
        /// <param name="xmlFile"></param>
        public void Save(string xmlFile)
        {
            using (var fact = new FgfGeometryFactory())
                using (var ws = new IoFileStream(xmlFile, "w"))
                {
                    using (var writer = new XmlWriter(ws, true, XmlWriter.LineFormat.LineFormat_Indent))
                    {
                        //Write spatial contexts
                        if (this.SpatialContexts != null && this.SpatialContexts.Length > 0)
                        {
                            var flags = new XmlSpatialContextFlags();
                            using (var scWriter = new XmlSpatialContextWriter(writer))
                            {
                                foreach (var sc in this.SpatialContexts)
                                {
                                    //XmlSpatialContextWriter forbids writing dynamically calculated extents
                                    if (sc.ExtentType == OSGeo.FDO.Commands.SpatialContext.SpatialContextExtentType.SpatialContextExtentType_Dynamic)
                                    {
                                        continue;
                                    }

                                    scWriter.CoordinateSystem    = sc.CoordinateSystem;
                                    scWriter.CoordinateSystemWkt = sc.CoordinateSystemWkt;
                                    scWriter.Description         = sc.Description;

                                    scWriter.ExtentType = sc.ExtentType;

                                    using (var geom = fact.CreateGeometry(sc.ExtentGeometryText))
                                    {
                                        byte[] fgf = fact.GetFgf(geom);
                                        scWriter.Extent = fgf;
                                    }

                                    scWriter.Name        = sc.Name;
                                    scWriter.XYTolerance = sc.XYTolerance;
                                    scWriter.ZTolerance  = sc.ZTolerance;

                                    scWriter.WriteSpatialContext();
                                }
                            }
                        }



                        //Write logical schema
                        if (this.Schemas != null)
                        {
                            var schemas = CloneSchemas(this.Schemas);

                            schemas.WriteXml(writer);
                        }

                        //Write physical mappings
                        if (this.Mappings != null)
                        {
                            this.Mappings.WriteXml(writer);
                        }

                        writer.Close();
                    }
                    ws.Close();
                }
        }
Пример #5
0
 /// <summary>
 /// Gets the FGF binary from the given text
 /// </summary>
 /// <param name="str"></param>
 /// <returns></returns>
 public static byte[] GetFgf(string str)
 {
     byte[] fgf = null;
     using (FgfGeometryFactory factory = new FgfGeometryFactory())
     {
         using (IGeometry geom = factory.CreateGeometry(str))
         {
             fgf = factory.GetFgf(geom);
         }
     }
     return fgf;
 }