Пример #1
0
        public static string createSDFFile(string SDFFile)
        {
            try
            {
                //check if files exists - if so delete it
                if (File.Exists(SDFFile))
                {
                    File.Delete(SDFFile);
                }
                IConnection      con       = SDFConnection(SDFFile);
                ICreateDataStore datastore = con.CreateCommand(osgeo_command.CommandType.CommandType_CreateDataStore) as ICreateDataStore;

                datastore.DataStoreProperties.SetProperty("File", SDFFile);
                datastore.Execute();
                con.Close();
                if (File.Exists(SDFFile))
                {
                    result = "Successfully Created SDF File";
                }
                else
                {
                    result = "Failed Creating SDF File";
                }
            }
            catch (System.Runtime.InteropServices.SEHException sehex)
            {
                System.Diagnostics.Debug.WriteLine("Error SEHEX Helper>>" + sehex);
            }
            catch (SystemException ex)
            {
                System.Diagnostics.Debug.WriteLine("Error SDF Helper>>" + ex);
            }
            return(result);
        }
        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;
            }
        }
 public void CreateDataStore(NameValueCollection props)
 {
     using (FdoFeatureService service = _conn.CreateFeatureService())
     {
         using (ICreateDataStore create = service.CreateCommand <ICreateDataStore>(CommandType.CommandType_CreateDataStore))
         {
             foreach (string key in props.AllKeys)
             {
                 create.DataStoreProperties.SetProperty(key, props[key]);
             }
             create.Execute();
         }
     }
 }
Пример #4
0
        /// <summary>
        /// Creates a FDO data source. The provider must be a flat-file provider
        /// </summary>
        /// <param name="provider">The provider.</param>
        /// <param name="path">The path.</param>
        /// <param name="deleteIfExists">if set to <c>true</c> deletes the specified file if it exists.</param>
        /// <returns></returns>
        public static bool CreateFlatFileDataSource(string provider, string path, bool deleteIfExists)
        {
            bool result = false;
            bool sdf    = provider.StartsWith("OSGeo.SDF");
            bool sqlite = provider.StartsWith("OSGeo.SQLite");

            IConnection conn = FeatureAccessManager.GetConnectionManager().CreateConnection(provider);

            if (conn.ConnectionInfo.ProviderDatastoreType != ProviderDatastoreType.ProviderDatastoreType_File)
            {
                return(false); //ERR_NOT_FLAT_FILE
            }
            string pName = GetFileParameter(provider);

            if (string.IsNullOrEmpty(pName))
            {
                return(false); //ERR_FILE_PARAMETER_UNKNOWN
            }
            if (deleteIfExists && File.Exists(path))
            {
                File.Delete(path);
            }

            using (conn)
            {
                using (ICreateDataStore cmd = conn.CreateCommand(OSGeo.FDO.Commands.CommandType.CommandType_CreateDataStore) as ICreateDataStore)
                {
                    try
                    {
                        var dsprops = cmd.DataStoreProperties;
                        dsprops.SetProperty(pName, path);
                        //Ensures that FDO logical schemas being applied to SQLite are mostly intact.
                        //See FDO trac ticket #739 for details.
                        if (sqlite)
                        {
                            dsprops.SetProperty("UseFdoMetadata", "TRUE");
                        }
                        cmd.Execute();
                        result = true;
                    }
                    catch (OSGeo.FDO.Common.Exception)
                    {
                        result = false;
                    }
                }
            }
            return(result);
        }
Пример #5
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();
        }