Ejemplo n.º 1
0
        private IFeatureClass method_8(string string_0)
        {
            string       directoryName        = System.IO.Path.GetDirectoryName(string_0);
            IPropertySet connectionProperties = new PropertySetClass();

            connectionProperties.SetProperty("DATABASE", directoryName);
            IWorkspaceFactory factory   = new ShapefileWorkspaceFactoryClass();
            IWorkspace        workspace = factory.Open(connectionProperties, 0);
            string            fileName  = System.IO.Path.GetFileName(string_0);

            return(((IFeatureWorkspace)workspace).OpenFeatureClass(fileName));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the workspace reference to the shapefile directory.
        /// </summary>
        /// <param name="directoryPath">The directory path where the shapefile workspace will work against.</param>
        /// <returns>the workspace reference if directory exists else returns NULL</returns>
        public static IWorkspace GetShapefileWorkspace(string directoryPath)
        {
            if (System.IO.Directory.Exists(directoryPath))
            {
                IPropertySet      propSet          = new PropertySetClass();
                IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();

                propSet.SetProperty("DATABASE", directoryPath);

                IWorkspace workspace = workspaceFactory.Open(propSet, 0);
                return(workspace);
            }
            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 打开shape文件工作空间
        /// </summary>
        /// <param name="shapeFileFoderPath">shape文件所在的文件夹</param>
        /// <returns></returns>
        public static IWorkspace OpenShapeFileWorkspace(string shapeFileFoderPath)
        {
            IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();;
            IWorkspace        pWorkspace       = null;
            IPropertySet      pSet             = new PropertySetClass();

            pSet.SetProperty("DATABASE", shapeFileFoderPath);
            try
            {
                pWorkspace = workspaceFactory.Open(pSet, 0);
            }
            catch (Exception ex)
            {
                LOG.Error("shape文件打开错误,详情:" + ex.Message);
                // Console.WriteLine("空间数据库打开错误");
                return(null);
            }
            return(pWorkspace);
        }
Ejemplo n.º 4
0
        /********************************************************************************
         *   Function name   : makeMap
         *   Description     : makes the animal movement maps. One for each animal.
         *   Return type     : void
         *   Argument        : string shapePath
         *   Argument        : string shapeFileName
         * ********************************************************************************/


        public bool makeMap(string shapePath, string shapeFileName, IGeometryDef inGeoDef)
        {
            bool success = true;

            try
            {
                shapePath = System.IO.Path.Combine(shapePath, shapeFileName);



                if (!loadFromBackup)
                {
#if DEBUG
                    if (Directory.Exists(shapePath))
                    {
                        Directory.Delete(shapePath, true);
                    }
#endif
                    Directory.CreateDirectory(shapePath);
                    this.myPath = shapePath;
                }


                IWorkspaceFactory shpWkspFactory     = new ShapefileWorkspaceFactoryClass();
                IPropertySet      connectionProperty = new PropertySetClass();
                IGeometryDefEdit  geoDef             = new GeometryDefClass();
                IFields           fields             = new FieldsClass();
                IFieldsEdit       fieldsEdit         = (IFieldsEdit)fields;
                IField            field     = new FieldClass();
                IFieldEdit        fieldEdit = (IFieldEdit)field;

                connectionProperty.SetProperty("DATABASE", shapePath);
                shapeWksp = (IFeatureWorkspace)shpWkspFactory.Open(connectionProperty, 0);

                fieldEdit             = new FieldClass();
                fieldEdit.Name_2      = "OBJECTID";
                fieldEdit.AliasName_2 = "OBJECTID";
                fieldEdit.Type_2      = esriFieldType.esriFieldTypeOID;
                fieldsEdit.AddField(fieldEdit);

                fieldEdit               = new FieldClass();
                fieldEdit.Name_2        = "SHAPE";
                fieldEdit.IsNullable_2  = true;
                fieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
                fieldEdit.GeometryDef_2 = inGeoDef;
                fieldEdit.Required_2    = true;
                fieldsEdit.AddField(fieldEdit);

                fieldEdit        = new FieldClass();
                fieldEdit.Name_2 = "ID";
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                fieldsEdit.AddField(fieldEdit);

                fieldEdit                = new FieldClass();
                fieldEdit.Name_2         = "CurrTime";
                fieldEdit.Type_2         = esriFieldType.esriFieldTypeSmallInteger;
                fieldEdit.DefaultValue_2 = 0;
                fieldsEdit.AddField(fieldEdit);

                fieldEdit                = new FieldClass();
                fieldEdit.Name_2         = "Available";
                fieldEdit.Type_2         = esriFieldType.esriFieldTypeSmallInteger;
                fieldEdit.DefaultValue_2 = 0;
                fieldsEdit.AddField(fieldEdit);

                //If loading from backup open the feature class rather than create a new one
                //TODO refactor to check this in the beginning
                if (loadFromBackup)
                {
                    this.mySelf = this.getShapeFile(shapePath);
                    //this.mySelf = shapeWksp.OpenFeatureClass(shapePath);
                }
                else
                {
                    this.mySelf = shapeWksp.CreateFeatureClass(shapeFileName, fieldsEdit, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                }
                System.Runtime.InteropServices.Marshal.ReleaseComObject(shpWkspFactory);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(connectionProperty);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(geoDef);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(fields);
            }
            catch (System.Exception ex)
            {
                success = false;
                if (ex.Source == "ESRI.ArcGIS.Geodatabase")
                {
                    mErrMessage = "That Directory is full with maps already";
                    throw new System.Exception("That Directory is full with maps already");
                }

                eLog.Debug(ex);
            }
            return(success);
        }
Ejemplo n.º 5
0
        /********************************************************************************
         *   Function name   : makeMap
         *   Description     : makes the animal movement maps. One for each animal.
         *   Return type     : void
         *   Argument        : string shapePath
         *   Argument        : string shapeFileName
         * ********************************************************************************/
        public bool makeMap(string shapePath, string shapeFileName, IGeometryDef inGeoDef)
        {
            bool success = true;

            try
            {
                shapePath = shapePath + "\\" + shapeFileName;

                Directory.CreateDirectory(shapePath);
                this.myPath = shapePath;
                IWorkspaceFactory shpWkspFactory     = new ShapefileWorkspaceFactoryClass();
                IPropertySet      connectionProperty = new PropertySetClass();
                IGeometryDefEdit  geoDef             = new GeometryDefClass();
                IFields           fields             = new FieldsClass();
                IFieldsEdit       fieldsEdit         = (IFieldsEdit)fields;
                IField            field     = new FieldClass();
                IFieldEdit        fieldEdit = (IFieldEdit)field;

                connectionProperty.SetProperty("DATABASE", shapePath);
                shapeWksp = (IFeatureWorkspace)shpWkspFactory.Open(connectionProperty, 0);

                fieldEdit             = new FieldClass();
                fieldEdit.Name_2      = "OBJECTID";
                fieldEdit.AliasName_2 = "OBJECTID";
                fieldEdit.Type_2      = esriFieldType.esriFieldTypeOID;
                fieldsEdit.AddField(fieldEdit);

                fieldEdit               = new FieldClass();
                fieldEdit.Name_2        = "SHAPE";
                fieldEdit.IsNullable_2  = true;
                fieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
                fieldEdit.GeometryDef_2 = inGeoDef;
                fieldEdit.Required_2    = true;
                fieldsEdit.AddField(fieldEdit);

                fieldEdit        = new FieldClass();
                fieldEdit.Name_2 = "ID";
                fieldEdit.Type_2 = esriFieldType.esriFieldTypeSmallInteger;
                fieldsEdit.AddField(fieldEdit);

                fieldEdit                = new FieldClass();
                fieldEdit.Name_2         = "CurrTime";
                fieldEdit.Type_2         = esriFieldType.esriFieldTypeSmallInteger;
                fieldEdit.DefaultValue_2 = 0;
                fieldsEdit.AddField(fieldEdit);

                fieldEdit                = new FieldClass();
                fieldEdit.Name_2         = "Available";
                fieldEdit.Type_2         = esriFieldType.esriFieldTypeSmallInteger;
                fieldEdit.DefaultValue_2 = 0;
                fieldsEdit.AddField(fieldEdit);


                this.mySelf = shapeWksp.CreateFeatureClass(shapeFileName, fieldsEdit, null, null, esriFeatureType.esriFTSimple, "Shape", "");
                System.Runtime.InteropServices.Marshal.ReleaseComObject(shpWkspFactory);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(connectionProperty);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(geoDef);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(fields);
            }
            catch (System.Exception ex)
            {
                success = false;
                if (ex.Source == "ESRI.ArcGIS.Geodatabase")
                {
                    mErrMessage = "That Directory is full with maps already";
                    throw new System.Exception("That Directory is full with maps already");
                }

                eLog.Debug(ex);
            }
            return(success);
        }