Пример #1
0
        public static Dictionary <int, KeyValuePair <string, IEnumInvalidObject> > TransferMapDataWithinExtents(IMap map, IFeatureWorkspace outputWorkspace, IFeatureDatasetName outputFeatureDatasetName, ESRI.ArcGIS.ADF.Web.Geometry.Envelope downloadDataExtent, ISpatialReference outputSpatialReference)
        {
            Dictionary <int, KeyValuePair <string, IEnumInvalidObject> > invalidObjects = new Dictionary <int, KeyValuePair <string, IEnumInvalidObject> >();
            IWorkspaceName outWorkspaceName = GeodatabaseUtil.GetWorkspaceName((IWorkspace)outputWorkspace);

            List <IFeatureLayer> featureLayers = GetFeatureLayers(map);

            int counter = 0;

            foreach (IFeatureLayer featureLayer in featureLayers)
            {
                IFeatureClass     inFeatureClass     = featureLayer.FeatureClass;
                IDataset          dataset            = (IDataset)inFeatureClass;
                IFeatureWorkspace inFeatureWorkspace = (IFeatureWorkspace)dataset.Workspace;

                IEnvelope env = new ESRI.ArcGIS.Geometry.EnvelopeClass();
                env.XMin = downloadDataExtent.XMin;
                env.YMin = downloadDataExtent.YMin;
                env.XMax = downloadDataExtent.XMax;
                env.YMax = downloadDataExtent.YMax;

                ISpatialFilter spatialFilter = new SpatialFilterClass();
                spatialFilter.Geometry      = env;
                spatialFilter.GeometryField = inFeatureClass.ShapeFieldName;
                spatialFilter.SpatialRel    = esriSpatialRelEnum.esriSpatialRelIntersects;

                IFeatureClassName outputFeatureClassName = GeodatabaseUtil.GetFeatureClassName(outWorkspaceName, dataset.Name);

                IEnumInvalidObject eInvalidObject = TransferData(inFeatureWorkspace, inFeatureClass, outputWorkspace, outputFeatureClassName, outputFeatureDatasetName, spatialFilter, outputSpatialReference);
                invalidObjects.Add(counter, new KeyValuePair <string, IEnumInvalidObject>(dataset.Name, eInvalidObject));
                counter++;
            }

            return(invalidObjects);
        }
Пример #2
0
        public static IFeatureClass CreateFeatureClass(object objectWorkspace, string name, ISpatialReference spatialReference, esriFeatureType featureType, esriGeometryType geometryType, IFields fields, UID uidCLSID, UID uidCLSEXT, string configWord)
        {
            // Check for invalid parameters.
            if (objectWorkspace == null)
            {
                throw new ArgumentNullException("[objectWorkspace] cannot be null");
            }

            if (!((objectWorkspace is IFeatureWorkspace) || (objectWorkspace is IFeatureDataset)))
            {
                throw (new ArgumentNullException("[objectWorkspace] must be IFeatureWorkspace or IFeatureDataset"));
            }

            if (string.IsNullOrEmpty(name))
            {
                throw (new ArgumentNullException("[name] cannot be empty"));
            }

            if ((objectWorkspace is IWorkspace) && (spatialReference == null))
            {
                throw (new ArgumentNullException("[spatialReference] cannot be null for StandAlong FeatureClasses"));
            }


            // Set ClassID (if Null)
            if (uidCLSID == null)
            {
                uidCLSID = new UIDClass();
                switch (featureType)
                {
                case (esriFeatureType.esriFTSimple):
                    uidCLSID.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}";
                    break;

                case (esriFeatureType.esriFTSimpleJunction):
                    geometryType   = esriGeometryType.esriGeometryPoint;
                    uidCLSID.Value = "{CEE8D6B8-55FE-11D1-AE55-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTComplexJunction):
                    uidCLSID.Value = "{DF9D71F4-DA32-11D1-AEBA-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTSimpleEdge):
                    geometryType   = esriGeometryType.esriGeometryPolyline;
                    uidCLSID.Value = "{E7031C90-55FE-11D1-AE55-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTComplexEdge):
                    geometryType   = esriGeometryType.esriGeometryPolyline;
                    uidCLSID.Value = "{A30E8A2A-C50B-11D1-AEA9-0000F80372B4}";
                    break;

                case (esriFeatureType.esriFTAnnotation):
                    geometryType   = esriGeometryType.esriGeometryPolygon;
                    uidCLSID.Value = "{E3676993-C682-11D2-8A2A-006097AFF44E}";
                    break;

                case (esriFeatureType.esriFTDimension):
                    geometryType   = esriGeometryType.esriGeometryPolygon;
                    uidCLSID.Value = "{496764FC-E0C9-11D3-80CE-00C04F601565}";
                    break;
                }
            }

            // Set uidCLSEXT (if Null)
            if (uidCLSEXT == null)
            {
                switch (featureType)
                {
                case (esriFeatureType.esriFTAnnotation):
                    uidCLSEXT       = new UIDClass();
                    uidCLSEXT.Value = "{24429589-D711-11D2-9F41-00C04F6BC6A5}";
                    break;

                case (esriFeatureType.esriFTDimension):
                    uidCLSEXT       = new UIDClass();
                    uidCLSEXT.Value = "{48F935E2-DA66-11D3-80CE-00C04F601565}";
                    break;
                }
            }

            // Add Fields
            if (fields == null)
            {
                // Create fields collection
                fields = new FieldsClass();
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

                // Create the geometry field
                IGeometryDef     geometryDef     = new GeometryDefClass();
                IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

                // Assign Geometry Definition
                geometryDefEdit.GeometryType_2 = geometryType;
                geometryDefEdit.GridCount_2    = 1;
                geometryDefEdit.set_GridSize(0, 0.5);
                geometryDefEdit.AvgNumPoints_2 = 2;
                geometryDefEdit.HasM_2         = false;
                geometryDefEdit.HasZ_2         = false;
                if (objectWorkspace is IWorkspace)
                {
                    // If this is a STANDALONE FeatureClass then add spatial reference.
                    geometryDefEdit.SpatialReference_2 = spatialReference;
                }

                // Create OID Field
                IField     fieldOID     = new FieldClass();
                IFieldEdit fieldEditOID = (IFieldEdit)fieldOID;
                fieldEditOID.Name_2      = "OBJECTID";
                fieldEditOID.AliasName_2 = "OBJECTID";
                fieldEditOID.Type_2      = esriFieldType.esriFieldTypeOID;
                fieldsEdit.AddField(fieldOID);

                // Create Geometry Field
                IField     fieldShape     = new FieldClass();
                IFieldEdit fieldEditShape = (IFieldEdit)fieldShape;
                fieldEditShape.Name_2        = "SHAPE";
                fieldEditShape.AliasName_2   = "SHAPE";
                fieldEditShape.Type_2        = esriFieldType.esriFieldTypeGeometry;
                fieldEditShape.GeometryDef_2 = geometryDef;
                fieldsEdit.AddField(fieldShape);
            }

            // Locate Shape Field
            string stringShapeFieldName = null;
            int    i = 0;

            while (i <= fields.FieldCount - 1)
            {
                if (fields.get_Field(i).Type == esriFieldType.esriFieldTypeGeometry)
                {
                    stringShapeFieldName = fields.get_Field(i).Name;
                    break;
                }
                i = i + 1;
            }
            if (stringShapeFieldName == null)
            {
                throw (new System.Data.ConstraintException("Cannot locate geometry field in FIELDS"));
            }

            IFeatureClass featureClass = null;

            if (objectWorkspace is IFeatureWorkspace)
            {
                // Create a STANDALONE FeatureClass
                IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)objectWorkspace;

                featureClass = featureWorkspace.CreateFeatureClass(name, fields, uidCLSID, uidCLSEXT, featureType, stringShapeFieldName, configWord);
            }
            else if (objectWorkspace is IFeatureDataset)
            {
                IFeatureDataset featureDataset = (IFeatureDataset)objectWorkspace;
                featureClass = featureDataset.CreateFeatureClass(name, fields, uidCLSID, uidCLSEXT, featureType, stringShapeFieldName, configWord);
            }

            // Set the alias
            IClassSchemaEdit classSchemaEdit = (IClassSchemaEdit)featureClass;

            classSchemaEdit.AlterAliasName(GeodatabaseUtil.GetUnQualifiedName(name));

            // Return FeatureClass
            return(featureClass);
        }