Пример #1
0
        static public SqlBytes GeometryToSqlBytes(IGeometry geometry)
        {
            GeometryDef geomDef = new GeometryDef();

            geomDef.HasZ = geomDef.HasM = false;

            serializeDelegate serialize = null;

            if (geometry != null && geometry.GeometryType != geometryType.Unknown)
            {
                geomDef.GeometryType = geometry.GeometryType;
                serialize            = geometry.Serialize;
            }

            if (serialize != null)
            {
                using (BinaryWriter writer = new BinaryWriter(new MemoryStream()))
                {
                    writer.Write((int)geomDef.GeometryType);
                    serialize(writer, geomDef);

                    byte[] bytes = new byte[writer.BaseStream.Length];
                    writer.BaseStream.Position = 0;
                    writer.BaseStream.Read(bytes, (int)0, (int)writer.BaseStream.Length);
                    writer.Close();

                    return(new SqlBytes(bytes));
                }
            }
            return(null);
        }
Пример #2
0
        internal static IFields CreateBaseStationFields(ISpatialReference spatialReference)
        {
            //Set up a simple fields collection
            IFields     pFields     = new FieldsClass();
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;

            //Make the shape field
            //it will need a geometry definition, with a spatial reference
            IField     pField     = new FieldClass();
            IFieldEdit pFieldEdit = pField as IFieldEdit;

            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            IGeometryDef     pGeometryDef     = new GeometryDef();
            IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;

            pGeometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint;
            pGeometryDefEdit.SpatialReference_2 = spatialReference;

            pFieldEdit.GeometryDef_2 = pGeometryDef;
            pFieldsEdit.AddField(pField);

            //Add OID field
            pField              = new FieldClass();
            pFieldEdit          = pField as IFieldEdit;
            pFieldEdit.Length_2 = 30;
            pFieldEdit.Name_2   = "OID";
            //pFieldEdit.AliasName_2 = "AliasName";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(pField);

            return(pFields);
        }
Пример #3
0
        private IFields CreateFeatureField(ITable pTable)
        {
            IFields     pFields     = new Fields();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

            IField     pField     = new Field();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;

            pFieldEdit.Name_2 = "SHAPE";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDefEdit pGeoDef = new GeometryDef() as IGeometryDefEdit;

            pGeoDef.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            //TODO 坐标系问题
            //pGeoDef.SpatialReference_2 = pFeatureLayer.SpatialReference;
            pFieldEdit.GeometryDef_2 = pGeoDef;
            pFieldsEdit.AddField(pField);

            for (int i = 0; i < pTable.Fields.FieldCount; i++)
            {
                IField field = pTable.Fields.Field[i];
                if (field.Type == esriFieldType.esriFieldTypeOID || field.Type == esriFieldType.esriFieldTypeGeometry)
                {
                    continue;
                }

                pField            = new Field();
                pFieldEdit        = (IFieldEdit)pField;
                pFieldEdit.Name_2 = field.Name; //"YSDM";
                pFieldEdit.Type_2 = field.Type; //esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(pField);
            }

            return(pFields);
        }
Пример #4
0
        public static void AddDefaultField(IFieldsEdit ifieldsEdit_0, esriGeometryType esriGeometryType_0,
                                           ISpatialReference ispatialReference_0, bool bool_0, bool bool_1, int int_0)
        {
            IFieldEdit fieldClass = new ESRI.ArcGIS.Geodatabase.Field() as IFieldEdit;

            fieldClass.Name_2       = "OBJECTID";
            fieldClass.AliasName_2  = "OBJECTID";
            fieldClass.IsNullable_2 = false;
            fieldClass.Type_2       = esriFieldType.esriFieldTypeOID;
            ifieldsEdit_0.AddField(fieldClass);
            fieldClass              = new ESRI.ArcGIS.Geodatabase.Field() as IFieldEdit;
            fieldClass.Name_2       = "SHAPE";
            fieldClass.AliasName_2  = "SHAPE";
            fieldClass.IsNullable_2 = true;
            fieldClass.Type_2       = esriFieldType.esriFieldTypeGeometry;
            IGeometryDefEdit geometryDefClass = new GeometryDef() as IGeometryDefEdit;

            geometryDefClass.SpatialReference_2 = ispatialReference_0;
            geometryDefClass.GridCount_2        = 1;
            geometryDefClass.GridSize_2[0]      = (double)int_0;
            geometryDefClass.GeometryType_2     = esriGeometryType_0;
            geometryDefClass.HasZ_2             = bool_1;
            geometryDefClass.HasM_2             = bool_0;
            fieldClass.GeometryDef_2            = geometryDefClass;
            ifieldsEdit_0.AddField(fieldClass);
        }
Пример #5
0
        //private QueryResult _queryResult=null;

        public AccessFDBFeatureClass(AccessFDB fdb, IDataset dataset, GeometryDef geomDef)
        {
            _fdb     = fdb;
            _dataset = dataset;
            _geomDef = (geomDef != null) ? geomDef : new GeometryDef();
            m_fields = new Fields();
        }
Пример #6
0
        private static IField GetShapeField(esriGeometryType geometryType, ISpatialReference spatialReference)
        {
            var spatialReferenceResolution = (ISpatialReferenceResolution)spatialReference;

            spatialReferenceResolution.ConstructFromHorizon();
            spatialReferenceResolution.SetDefaultXYResolution();

            var spatialReferenceTolerance = (ISpatialReferenceTolerance)spatialReference;

            spatialReferenceTolerance.SetDefaultXYTolerance();

            IGeometryDef geometryDef     = new GeometryDef();
            var          geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2     = geometryType;
            geometryDefEdit.SpatialReference_2 = spatialReference;

            IField field = new Field();

            var fieldEdit = (IFieldEdit)field;

            fieldEdit.Name_2        = "Shape";
            fieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
            fieldEdit.GeometryDef_2 = geometryDef;

            return(field);
        }
Пример #7
0
        static public IGeometry SqlBytesToGeometry(SqlBytes sqlbytes)
        {
            try
            {
                GeometryDef geomDef = new GeometryDef();
                geomDef.HasZ = geomDef.HasM = false;


                using (BinaryReader r = new BinaryReader(new MemoryStream()))
                {
                    r.BaseStream.Write(sqlbytes.Buffer, 0, sqlbytes.Buffer.Length);
                    r.BaseStream.Position = 0;

                    switch ((geometryType)r.ReadInt32())
                    {
                    case geometryType.Aggregate:
                        AggregateGeometry ageom = new AggregateGeometry();
                        ageom.Deserialize(r, geomDef);
                        return(ageom);

                    case geometryType.Envelope:
                        Envelope env = new Envelope();
                        env.Deserialize(r, geomDef);
                        return(env);

                    case geometryType.Multipoint:
                        MultiPoint mp = new MultiPoint();
                        mp.Deserialize(r, geomDef);
                        return(mp);

                    case geometryType.Point:
                        Point p = new Point();
                        p.Deserialize(r, geomDef);
                        return(p);

                    case geometryType.Polygon:
                        Polygon polygon = new Polygon();
                        polygon.Deserialize(r, geomDef);
                        return(polygon);

                    case geometryType.Polyline:
                        Polyline line = new Polyline();
                        line.Deserialize(r, geomDef);
                        return(line);

                    default:
                        return(null);
                    }
                }
            }
            catch
            {
                return(null);
            }
        }
Пример #8
0
        public ShapeFeatureClass(SHPFile file, IDataset dataset, IIndexTree tree)
        {
            if (file == null)
            {
                return;
            }

            _file    = file;
            _dataset = dataset;
            _tree    = tree;

            _envelope = new Envelope(_file.Header.Xmin, _file.Header.Ymin, _file.Header.Xmax, _file.Header.Ymax);

            ISpatialReference sRef = null;

            if (file.PRJ_Exists)
            {
                StreamReader sr      = new StreamReader(file.PRJ_Filename);
                string       esriWKT = sr.ReadToEnd();
                sRef = gView.Framework.Geometry.SpatialReference.FromWKT(esriWKT);
                sr.Close();
            }

            switch (_file.Header.ShapeType)
            {
            case ShapeType.Point:
            case ShapeType.PointM:
            case ShapeType.PointZ:
            case ShapeType.MultiPoint:
            case ShapeType.MultiPointM:
            case ShapeType.MultiPointZ:
                _geomDef = new GeometryDef(geometryType.Point, sRef);
                break;

            case ShapeType.PolyLine:
            case ShapeType.PolyLineM:
            case ShapeType.PolyLineZ:
                _geomDef = new GeometryDef(geometryType.Polyline, sRef);
                break;

            case ShapeType.Polygon:
            case ShapeType.PolygonM:
            case ShapeType.PolygonZ:
                _geomDef = new GeometryDef(geometryType.Polygon, sRef);
                break;

            case ShapeType.MultiPatch:
                _geomDef = new GeometryDef(geometryType.Aggregate, sRef);
                break;

            default:
                _geomDef = new GeometryDef(geometryType.Unknown, sRef);
                break;
            }
        }
        public IFeatureClass CreatePointFile(String strFolder, String filename, IEnvelope pEnvBorder, ISpatialReference pSR)
        {
            // Open the folder to contain the shapefile as a workspace
            IWorkspaceFactory pWF = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pfws = (IFeatureWorkspace)pWF.OpenFromFile(strFolder, 0);

            //Set up a simple fields collection
            IField pField = new FieldClass();
            IFieldEdit pFieldEdit = (IFieldEdit)pField;
            IFields pFields = new FieldsClass();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

            // Make the shape field
            //it will need a geometry definition, with a spatial reference

            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            IGeometryDef pGeomDef = new GeometryDef();
            IGeometryDefEdit pGeomDefEdit = (IGeometryDefEdit)pGeomDef;

            pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;

            pGeomDefEdit.SpatialReference_2 = pSR;

            pFieldEdit.GeometryDef_2 = pGeomDef;
            pFieldsEdit.AddField(pField);

            // Add ID field
            IField pFieldOID = new Field();
            pFieldEdit = (IFieldEdit)pFieldOID;
            pFieldEdit.Name_2 = "OBJECTID";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            pFieldEdit.IsNullable_2 = false;

            pFieldsEdit.AddField(pFieldOID);

            if (File.Exists(strFolder + filename + ".shp") == true)
            {
                DialogResult result = MessageBox.Show("There is a shapefile have the same name in this foler, do you want to overwrite it?", "", MessageBoxButtons.OKCancel);
                if (result == DialogResult.OK)
                {
                    File.Delete(strFolder + filename);

                }
                else
                {
                    return null;
                }
            }
            IFeatureClass pFeatclass = pfws.CreateFeatureClass(filename, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
            return pFeatclass;
        }
Пример #10
0
        public static IGeometryDef CreateGeometryDef(ISpatialReference ispatialReference_0)
        {
            IGeometryDefEdit geometryDefEdit = new GeometryDef() as IGeometryDefEdit;

            geometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            geometryDefEdit.AvgNumPoints_2 = 4;
            if (ispatialReference_0 == null)
            {
                ispatialReference_0 = new UnknownCoordinateSystem() as ISpatialReference;
            }
            geometryDefEdit.SpatialReference_2 = ispatialReference_0;
            return(geometryDefEdit);
        }
Пример #11
0
        public SQLiteFDBFeatureClass(SQLiteFDB fdb, IDataset dataset, GeometryDef geomDef)
        {
            _fdb = fdb;

            _dataset = dataset;
            _geomDef = (geomDef != null) ? geomDef : new GeometryDef();

            if (_geomDef != null && _geomDef.SpatialReference == null && dataset is IFeatureDataset)
            {
                _geomDef.SpatialReference = ((IFeatureDataset)dataset).SpatialReference;
            }

            m_fields = new Fields();
        }
Пример #12
0
        public IRasterLayerCursor ChildLayers(gView.Framework.Carto.IDisplay display, string filterClause)
        {
            List <IRasterLayer> layers = new List <IRasterLayer>();

            double dpm = Math.Max(display.GraphicsContext.DpiX, display.GraphicsContext.DpiY) / 0.0254;
            double pix = display.mapScale / dpm; /*display.dpm;*/  // [m]

            // Level bestimmen
            int level = 1;

            foreach (PyramidLevelHeader levHeader in _levelHeader)
            {
                if (levHeader.cellX <= pix && levHeader.cellY <= pix)
                {
                    level = levHeader.level;
                }
            }

            IEnvelope dispEnvelope = display.Envelope;

            if (display.GeometricTransformer != null)
            {
                dispEnvelope = (IEnvelope)((IGeometry)display.GeometricTransformer.InvTransform2D(dispEnvelope)).Envelope;
            }
            IGeometryDef geomDef = new GeometryDef(geometryType.Polygon, null, true);

            foreach (PyramidPictureHeader picHeader in _picHeader)
            {
                if (picHeader.level != level)
                {
                    continue;
                }

                IPolygon polygon = picHeader.CreatePolygon();
                if (gView.Framework.SpatialAlgorithms.Algorithm.IntersectBox(polygon, dispEnvelope))
                {
                    PyramidFileImageClass pClass = new PyramidFileImageClass(_stream, picHeader, polygon);
                    RasterLayer           rLayer = new RasterLayer(pClass);
                    rLayer.InterpolationMethod = this.InterpolationMethod;
                    if (pClass.SpatialReference == null)
                    {
                        pClass.SpatialReference = _sRef;
                    }
                    layers.Add(rLayer);
                }
            }
            return(new SimpleRasterlayerCursor(layers));
        }
Пример #13
0
        private static IGeometryDef createGeometryDef(ISpatialReference ispatialReference_0)
        {
            IGeometryDefEdit edit = new GeometryDef() as IGeometryDefEdit;

            edit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            edit.AvgNumPoints_2 = 4;
            edit.GridCount_2    = 1;
            edit.set_GridSize(0, 1000.0);
            if (ispatialReference_0 == null)
            {
                ispatialReference_0 = new UnknownCoordinateSystem() as ISpatialReference;
            }
            (ispatialReference_0 as ISpatialReferenceResolution).set_XYResolution(true, 0.001);
            (ispatialReference_0 as ISpatialReferenceResolution).SetDefaultXYResolution();
            edit.SpatialReference_2 = ispatialReference_0;
            return(edit);
        }
Пример #14
0
        private IGeometryDef method_2(ISpatialReference ispatialReference_0)
        {
            IGeometryDefEdit @class = new GeometryDef() as IGeometryDefEdit;

            @class.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
            @class.AvgNumPoints_2 = 4;
            @class.GridCount_2    = 1;
            IGeometryDefEdit geometryDefClass = @class as IGeometryDefEdit;

            geometryDefClass.GridSize_2[0] = 1000;
            if (ispatialReference_0 == null)
            {
                ispatialReference_0 = new UnknownCoordinateSystem() as ISpatialReference;
            }
            geometryDefClass.SpatialReference_2 = ispatialReference_0;
            return(geometryDefClass);
        }
Пример #15
0
        /// <summary>
        /// 向字段组中添加一个几何字段
        /// </summary>
        /// <param name="name">几何字段名</param>
        /// <param name="geoType">几何类型</param>
        /// <param name="spRef">空间参考</param>
        public void AddShapeFields(string name, esriGeometryType geoType, ISpatialReference spRef = null)
        {
            IField     field_Shape      = new Field();
            IFieldEdit field_Shape_Edit = field_Shape as IFieldEdit;

            field_Shape_Edit.Name_2 = name;
            field_Shape_Edit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            IGeometryDef     geometrydef     = new GeometryDef();
            IGeometryDefEdit geometrydeiEdit = geometrydef as IGeometryDef as IGeometryDefEdit;

            geometrydeiEdit.GeometryType_2     = geoType;
            geometrydeiEdit.SpatialReference_2 = spRef;
            field_Shape_Edit.GeometryDef_2     = geometrydef;

            (m_Fields as IFieldsEdit).AddField(field_Shape);
        }
Пример #16
0
        public static void CreateShpFile(string filePath, string fileName, Field[] fields, ISpatialReference spatialReference, Func <IFeatureClass, bool> featureCreationCallback)
        {
            fileName = fileName.Replace("/", "");
            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
            IFields           pFields           = new Fields();
            IFieldsEdit       pFieldsEdit       = pFields as IFieldsEdit;
            IField            pField            = new Field();
            IFieldEdit        pFieldEdit        = pField as IFieldEdit;

            pFieldEdit.Name_2 = "Shape";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef     pGeometryDef     = new GeometryDef();
            IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;

            pGeometryDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint;
            pGeometryDefEdit.SpatialReference_2 = spatialReference;
            pFieldEdit.GeometryDef_2            = pGeometryDef;
            pFieldsEdit.AddField(pField);

            foreach (Field f in fields)
            {
                pFieldsEdit.AddField(f);
            }

            IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(filePath, 0) as IFeatureWorkspace;
            int i = fileName.IndexOf(".shp");

            if (i == -1)
            {
                pFeatureWorkspace.CreateFeatureClass(fileName + ".shp", pFields, null, null,
                                                     esriFeatureType.esriFTSimple, "Shape", "");
            }
            else
            {
                pFeatureWorkspace.CreateFeatureClass(fileName, pFields,
                                                     null, null, esriFeatureType.esriFTSimple, "Shape", "");
            }

            //if (featureCreationCallback == null)
            //{
            IFeatureClass featureClass = pFeatureWorkspace.OpenFeatureClass(fileName);

            featureCreationCallback(featureClass);
            //}
        }
Пример #17
0
        public static IField CreateGeometryField(esriGeometryType pGT, ISpatialReference pSR, bool pHasZ)
        {
            Field      class2 = new Field();
            IFieldEdit edit   = class2 as IFieldEdit;

            edit.Name_2      = "SHAPE";
            edit.AliasName_2 = "图形对象";
            edit.Type_2      = esriFieldType.esriFieldTypeGeometry;
            IGeometryDef     pGeoDef = new GeometryDef();
            IGeometryDefEdit class3  = (IGeometryDefEdit)pGeoDef;

            class3.GeometryType_2 = pGT;
            class3.HasM_2         = false;
            class3.HasZ_2         = pHasZ;
            class3.GridCount_2    = 1;
            class3.set_GridSize(0, 1000.0);
            class3.SpatialReference_2 = pSR;
            edit.GeometryDef_2        = class3;
            return(class2);
        }
Пример #18
0
        public static void Project(IFeatureDataset ifeatureDataset_0, ISpatialReference ispatialReference_0,
                                   IWorkspace iworkspace_0, string string_0)
        {
            IGeometryDef      geometryDefClass = new GeometryDef();
            ISpatialReference spatialReference = ((IGeoDataset)ifeatureDataset_0).SpatialReference;

            ((IGeometryDefEdit)geometryDefClass).SpatialReference_2 = ispatialReference_0;
            IWorkspace            workspace = ifeatureDataset_0.Workspace;
            IFeatureDataConverter featureDataConverterClass = new FeatureDataConverter();
            IWorkspaceName        workspaceNameClass        = new WorkspaceName() as IWorkspaceName as IWorkspaceName;


            workspaceNameClass.ConnectionProperties   = workspace.ConnectionProperties;
            workspaceNameClass.WorkspaceFactoryProgID = workspace.WorkspaceFactory.GetClassID().Value.ToString();

            IWorkspaceName connectionProperties = new WorkspaceName() as IWorkspaceName as IWorkspaceName;
            PropertySet    propertySetClass     = new PropertySet();

            connectionProperties.ConnectionProperties   = iworkspace_0.ConnectionProperties;
            connectionProperties.WorkspaceFactoryProgID = iworkspace_0.WorkspaceFactory.GetClassID().Value.ToString();
            IDatasetName featureDatasetNameClass = new FeatureDatasetName() as IDatasetName;
            string       name = ifeatureDataset_0.Name;
            int          num  = name.LastIndexOf(".");

            if (num != -1)
            {
                name = name.Substring(num + 1);
            }
            featureDatasetNameClass.Name          = name;
            featureDatasetNameClass.WorkspaceName = workspaceNameClass;
            IDatasetName datasetName = new FeatureDatasetName() as IDatasetName;

            {
                datasetName.WorkspaceName = connectionProperties;
                datasetName.Name          = string_0;
            }
            ;
            featureDataConverterClass.ConvertFeatureDataset((IFeatureDatasetName)featureDatasetNameClass,
                                                            (IFeatureDatasetName)datasetName, geometryDefClass, "", 1000, 0);
        }
Пример #19
0
        async public Task <bool> ImportToNewFeatureclass(IFeatureDatabase fdb, string dsname, string fcname, IFeatureClass sourceFC, FieldTranslation fieldTranslation, bool project, List <IQueryFilter> filters, ISpatialIndexDef sIndexDef, geometryType?sourceGeometryType = null)
        {
            if (!_cancelTracker.Continue)
            {
                return(true);
            }

            if (fdb is AccessFDB)
            {
                ISpatialIndexDef dsSpatialIndexDef = await((AccessFDB)fdb).SpatialIndexDef(dsname);
                if (sIndexDef == null)
                {
                    sIndexDef = dsSpatialIndexDef;
                }
                else if (sIndexDef.GeometryType != dsSpatialIndexDef.GeometryType)
                {
                    _errMsg = "Spatial-Index-Definition-GeometryTypes are not compatible!";
                    return(false);
                }
            }
            if (sIndexDef == null)
            {
                sIndexDef = new gViewSpatialIndexDef();
            }

            bool msSpatial = false;

            if (fdb is SqlFDB &&
                (sIndexDef.GeometryType == GeometryFieldType.MsGeography ||
                 sIndexDef.GeometryType == GeometryFieldType.MsGeometry))
            {
                msSpatial = true;
            }
            else
            {
                int maxAllowedLevel = ((fdb is SqlFDB || fdb is pgFDB) ? 62 : 30);
                if (sIndexDef.Levels > maxAllowedLevel)
                {
                    ISpatialReference defSRef = sIndexDef.SpatialReference;
                    sIndexDef = new gViewSpatialIndexDef(
                        sIndexDef.SpatialIndexBounds,
                        Math.Min(sIndexDef.Levels, maxAllowedLevel),
                        sIndexDef.MaxPerNode,
                        sIndexDef.SplitRatio);
                    ((gViewSpatialIndexDef)sIndexDef).SpatialReference = defSRef;
                }
            }

            try
            {
                fcname = fcname.Replace(".", "_");

                IFeatureDataset destDS = await fdb.GetDataset(dsname);

                if (destDS == null)
                {
                    _errMsg = fdb.LastErrorMessage;
                    return(false);
                }

                IDatasetElement destLayer = await destDS.Element(fcname);

                if (destLayer != null)
                {
                    if (ReportRequest != null)
                    {
                        RequestArgs args = new RequestArgs(
                            "Featureclass " + fcname + " already exists in " + dsname + "\nDo want to replace it?",
                            MessageBoxButtons.YesNoCancel,
                            DialogResult.Cancel);
                        ReportRequest(this, args);
                        switch (args.Result)
                        {
                        case DialogResult.No:
                            return(true);

                        case DialogResult.Cancel:
                            _errMsg = "Import is canceled by the user...";
                            return(false);
                        }
                    }
                }

                GeometryDef geomDef = new GeometryDef(sourceFC);
                if (geomDef.GeometryType == geometryType.Unknown && sourceGeometryType != null)
                {
                    geomDef.GeometryType = sourceGeometryType.Value;
                }

                int fcID = -1;
                if (destLayer != null)
                {
                    if (fdb is AccessFDB)
                    {
                        fcID = await((AccessFDB)fdb).ReplaceFeatureClass(destDS.DatasetName,
                                                                         fcname,
                                                                         geomDef,
                                                                         (fieldTranslation == null) ?
                                                                         ((sourceFC.Fields != null) ? (IFields)sourceFC.Fields.Clone() : new Fields()) :
                                                                         fieldTranslation.DestinationFields);
                        if (fcID < 0)
                        {
                            _errMsg = "Can't replace featureclass " + fcname + "...\r\n" + fdb.LastErrorMessage;
                            destDS.Dispose();
                            return(false);
                        }
                    }
                    else
                    {
                        await fdb.DeleteFeatureClass(fcname);
                    }
                }
                if (fcID < 0)
                {
                    fcID = await fdb.CreateFeatureClass(destDS.DatasetName,
                                                        fcname,
                                                        geomDef,
                                                        (fieldTranslation == null)?
                                                        ((sourceFC.Fields != null) ? (IFields)sourceFC.Fields.Clone() : new Fields()) :
                                                        fieldTranslation.DestinationFields);
                }
                if (fcID < 0)
                {
                    _errMsg = "Can't create featureclass " + fcname + "...\r\n" + fdb.LastErrorMessage;
                    destDS.Dispose();
                    return(false);
                }

                destLayer = await destDS.Element(fcname);

                if (destLayer == null || !(destLayer.Class is IFeatureClass))
                {
                    _errMsg = "Can't load featureclass " + fcname + "...\r\n" + destDS.LastErrorMessage;
                    destDS.Dispose();
                    return(false);
                }
                IFeatureClass destFC = destLayer.Class as IFeatureClass;

                if (project && destFC.SpatialReference != null && !destFC.SpatialReference.Equals(sourceFC.SpatialReference))
                {
                    _transformer = GeometricTransformerFactory.Create();
                    //_transformer.FromSpatialReference = sourceFC.SpatialReference;
                    //_transformer.ToSpatialReference = destFC.SpatialReference;
                    _transformer.SetSpatialReferences(sourceFC.SpatialReference, destFC.SpatialReference);
                }

                if (!Envelope.IsNull(sIndexDef.SpatialIndexBounds) &&
                    sIndexDef.SpatialReference != null && !sIndexDef.SpatialReference.Equals(destFC.SpatialReference))
                {
                    if (!sIndexDef.ProjectTo(destFC.SpatialReference))
                    {
                        _errMsg = "Can't project SpatialIndex Boundaries...";
                        destDS.Dispose();
                        return(false);
                    }
                }

                DualTree           tree  = null;
                BinaryTree2Builder tree2 = null;

                if (msSpatial)
                {
                    ((SqlFDB)fdb).SetMSSpatialIndex((MSSpatialIndex)sIndexDef, destFC.Name);
                    await((SqlFDB)fdb).SetFeatureclassExtent(destFC.Name, sIndexDef.SpatialIndexBounds);
                }
                else
                {
                    if (_treeVersion == TreeVersion.BinaryTree)
                    {
                        tree = await SpatialIndex(sourceFC, sIndexDef.MaxPerNode, filters);

                        if (tree == null)
                        {
                            return(false);
                        }
                    }
                    else if (_treeVersion == TreeVersion.BinaryTree2)
                    {
                        if (_schemaOnly && sourceFC.Dataset.Database is IImplementsBinarayTreeDef)
                        {
                            BinaryTreeDef tDef = await((IImplementsBinarayTreeDef)sourceFC.Dataset.Database).BinaryTreeDef(sourceFC.Name);
                            tree2 = new BinaryTree2Builder(tDef.Bounds, tDef.MaxLevel, tDef.MaxPerNode, tDef.SplitRatio);
                        }
                        else
                        {
                            tree2 = await SpatialIndex2(fdb, sourceFC, sIndexDef, filters);

                            if (tree2 == null)
                            {
                                return(false);
                            }
                        }
                    }

                    // Vorab einmal alle "Bounds" festlegen, damit auch
                    // ein aufzubauender Layer geviewt werden kann
                    if (_treeVersion == TreeVersion.BinaryTree2 && fdb is AccessFDB)
                    {
                        if (ReportAction != null)
                        {
                            ReportAction(this, "Insert spatial index nodes");
                        }
                        List <long> nids = new List <long>();
                        foreach (BinaryTree2BuilderNode node in tree2.Nodes)
                        {
                            nids.Add(node.Number);
                        }
                        await((AccessFDB)fdb).ShrinkSpatialIndex(fcname, nids);

                        if (ReportAction != null)
                        {
                            ReportAction(this, "Set spatial index bounds");
                        }
                        //((AccessFDB)fdb).SetSpatialIndexBounds(fcname, "BinaryTree2", tree2.Bounds, sIndexDef.SplitRatio, sIndexDef.MaxPerNode, tree2.maxLevels);
                        await((AccessFDB)fdb).SetSpatialIndexBounds(fcname, "BinaryTree2", tree2.Bounds, tree2.SplitRatio, tree2.MaxPerNode, tree2.maxLevels);
                        await((AccessFDB)fdb).SetFeatureclassExtent(fcname, tree2.Bounds);
                    }
                }
                if (_cancelTracker.Continue)
                {
                    bool result = true;
                    if (!_schemaOnly)
                    {
                        if (msSpatial)
                        {
                            result = await CopyFeatures(sourceFC, fdb, destFC, fieldTranslation, filters);
                        }
                        else if (_treeVersion == TreeVersion.BinaryTree)
                        {
                            if (String.IsNullOrEmpty(sourceFC.IDFieldName)) // SDE Views haben keine ID -> Tree enthält keine Features
                            {
                                result = await CopyFeatures(sourceFC, fdb, destFC, fieldTranslation, filters);
                            }
                            else
                            {
                                result = await CopyFeatures(sourceFC, fdb, destFC, fieldTranslation, tree);
                            }
                        }
                        else if (_treeVersion == TreeVersion.BinaryTree2)
                        {
                            if (String.IsNullOrEmpty(sourceFC.IDFieldName)) // SDE Views haben keine ID -> Tree enthält keine Features
                            {
                                result = await CopyFeatures(sourceFC, fdb, destFC, fieldTranslation, filters);
                            }
                            else
                            {
                                result = await CopyFeatures2(sourceFC, fdb, destFC, fieldTranslation, tree2);
                            }
                        }
                        if (!result)
                        {
                            await fdb.DeleteFeatureClass(fcname);

                            destDS.Dispose();
                            return(false);
                        }
                    }
                }

                destDS.Dispose();

                if (_cancelTracker.Continue && fdb is AccessFDB)
                {
                    if (ReportAction != null)
                    {
                        ReportAction(this, "Calculate extent");
                    }
                    await((AccessFDB)fdb).CalculateExtent(destFC);

                    if (msSpatial == false)
                    {
                        if (_treeVersion == TreeVersion.BinaryTree)
                        {
                            if (ReportAction != null)
                            {
                                ReportAction(this, "Set spatial index bounds");
                            }
                            await((AccessFDB)fdb).SetSpatialIndexBounds(fcname, "BinaryTree", tree.Bounds, sIndexDef.SplitRatio, sIndexDef.MaxPerNode, 0);

                            if (ReportAction != null)
                            {
                                ReportAction(this, "Insert spatial index nodes");
                            }
                            await((AccessFDB)fdb).__intInsertSpatialIndexNodes2(fcname, tree.Nodes);
                        }
                    }
                    return(true);
                }
                else
                {
                    await fdb.DeleteFeatureClass(fcname);

                    _errMsg = "Import is canceled by the user...";
                    return(false);
                }
            }
            finally
            {
                if (_transformer != null)
                {
                    _transformer.Release();
                    _transformer = null;
                }
            }
        }
Пример #20
0
        private IFeatureClass CreateFeatureClassFromGeometry(IGeometry pGeometry, IFeatureWorkspace pOutFeatWorkspace, int wkid)
        {
            // thanks to http://bcdcspatial.blogspot.co.uk/2011/12/some-random-arcobjects-that-make.html
            // which was the only place i could find an answer to the problem I was having - the last
            // argument to createfeatureclass is null NOT an empty string
            try
            {
                IFields tFields = new FieldsClass() as IFields;
                IFieldsEdit tFieldsEdit = (IFieldsEdit)tFields;
                IField tShpFld = new Field();
                IFieldEdit tShpEd = (IFieldEdit)tShpFld;
                tShpEd.Type_2 = esriFieldType.esriFieldTypeGeometry;
                tShpEd.Name_2 = "Shape";

                IGeometryDef tGeomDef = new GeometryDef();
                IGeometryDefEdit tGdEdit = (IGeometryDefEdit)tGeomDef;
                tGdEdit.GeometryType_2 = pGeometry.GeometryType;

                ISpatialReferenceFactory2 tSRFac = new SpatialReferenceEnvironment() as ISpatialReferenceFactory2;
                ISpatialReference tSpatRef = tSRFac.CreateSpatialReference(wkid);
                ISpatialReferenceResolution tSpatRefRes = (ISpatialReferenceResolution)tSpatRef;
                tSpatRefRes.ConstructFromHorizon();

                tGdEdit.SpatialReference_2 = tSpatRef;
                tShpEd.GeometryDef_2 = tGeomDef;
                tFieldsEdit.AddField(tShpFld);

                IObjectClassDescription tOCDesc = new FeatureClassDescription();
                for (int i = 0; i < tOCDesc.RequiredFields.FieldCount; i++)
                {
                    IField tField = tOCDesc.RequiredFields.get_Field(i);
                    if (tFieldsEdit.FindField(tField.Name) == -1)
                    {
                        tFieldsEdit.AddField(tField);
                    }
                }
                string tFCName = "tmp" + Guid.NewGuid().ToString("N");
                IFeatureClass tFC = pOutFeatWorkspace.CreateFeatureClass(
                    tFCName, tFields, null, null, esriFeatureType.esriFTSimple, "Shape", null);
                IFeature tGeomAsFeature = tFC.CreateFeature();
                tGeomAsFeature.Shape = pGeometry;
                tGeomAsFeature.Store();
                return tFC;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                logger.LogMessage(ServerLogger.msgType.error, "CreateFeatureClassFromGeometry", 99,
                              "Could not create feature class " + e.Message + e.Source + e.StackTrace);
                throw e;

            }
        }
Пример #21
0
        private void Create_Click(object sender, EventArgs e)
        {
            try
            {
                IWorkspaceFactory pShpWksFact = new ShapefileWorkspaceFactory();
                IFeatureWorkspace pFeatWks;
                pFeatWks = (IFeatureWorkspace)pShpWksFact.OpenFromFile(filePath, 0);
                const string strShapeFieldName = "Shape";
                //定义属性字段
                IFields pFields = new Fields();
                IFieldsEdit pFieldsEdit;
                pFieldsEdit = pFields as IFieldsEdit;
                IField pField = new Field();
                IFieldEdit pFieldEdit = new Field() as IFieldEdit;
                pFieldEdit.Name_2 = strShapeFieldName;
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                pField = pFieldEdit as IField;
                //定义几何属性
                IGeometryDef pGeomDef = new GeometryDef();
                IGeometryDefEdit pGeomDefEdit = new GeometryDef() as IGeometryDefEdit;
                pGeomDefEdit = pGeomDef as IGeometryDefEdit;
                switch (shpTypeComboBox.Text)
                {
                    case "Point":
                        pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                        break;
                    case "Polyline":
                        pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
                        break;
                    case "Polygon":
                        pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                        break;
                }

                pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                pGeomDefEdit.SpatialReference_2 = new UnknownCoordinateSystem() as ISpatialReference;
                pFieldEdit.GeometryDef_2 = pGeomDef;
                pFieldsEdit.AddField(pField);
                pFields = pFieldsEdit as IFields;
                IFeatureClass pFeatureClass;
                pFeatureClass = pFeatWks.CreateFeatureClass(fileName, pFields, null, null,
                    esriFeatureType.esriFTSimple, strShapeFieldName, "");
                //添加属性字段
                for (int i = 0; i < addFieldListBox.Items.Count; i++)
                {
                    IField pfield = new Field();
                    IFieldEdit pfieldEdit = new Field() as IFieldEdit;
                    pfieldEdit.Name_2 = addFieldListBox.Items[i].ToString();
                    pfieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    pfield = pfieldEdit as IField;
                    pFeatureClass.AddField(pfield);
                }
                //绘制点
                for (int i = 0; i < excelDataGridViewX.Rows.Count - 1; i++)
                {
                    DataGridViewRow dataRow = excelDataGridViewX.Rows[i];
                    double pointX, pointY;
                    pointX = double.Parse(dataRow.Cells[xComboBoxEx.Text].Value.ToString());
                    pointY = double.Parse(dataRow.Cells[yComboBoxEx.Text].Value.ToString());

                    IPoint pPoint = new ESRI.ArcGIS.Geometry.Point() as IPoint;
                    pPoint.PutCoords(pointX, pointY);
                    IFeature pFeature = pFeatureClass.CreateFeature();
                    pFeature.Shape = pPoint;
                    //为该点添加属性值
                    for (int j = 0; j < addFieldListBox.Items.Count; j++)
                    {
                        string fieldName = addFieldListBox.Items[j].ToString();
                        pFeature.set_Value(pFeature.Fields.FindField(fieldName),
                            dataRow.Cells[fieldName].Value.ToString());
                    }
                    pFeature.Store();
                }
                //添加新建的数据至Map中
                axMapControl.AddShapeFile(filePath, fileName);
                this.Hide();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #22
0
 public SQLiteFDBFeatureClass(SQLiteFDB fdb, IDataset dataset, GeometryDef geomDef, BinarySearchTree tree)
     : this(fdb, dataset, geomDef)
 {
     _searchTree = tree;
 }
Пример #23
0
        public static IFeatureClass CreateFeatureClass(object object_0, string string_0,
                                                       ISpatialReference ispatialReference_0, esriFeatureType esriFeatureType_0,
                                                       esriGeometryType esriGeometryType_0, IFields ifields_0, UID uid_0, UID uid_1, string string_1)
        {
            if (object_0 == null)
            {
                throw new Exception("[objectWorkspace] 不能为空");
            }
            if ((object_0 is IWorkspace ? false : !(object_0 is IFeatureDataset)))
            {
                throw new Exception("[objectWorkspace] 必须是IWorkspace或IFeatureDataset");
            }
            if (string_0 == "")
            {
                throw new Exception("[name] cannot be empty");
            }
            if ((!(object_0 is IWorkspace) ? false : ispatialReference_0 == null))
            {
                throw new Exception("[spatialReference] cannot be null for StandAlong FeatureClasses");
            }
            if (uid_0 == null)
            {
                uid_0 = new UID();
                switch (esriFeatureType_0)
                {
                case esriFeatureType.esriFTSimple:
                {
                    uid_0.Value = "{52353152-891A-11D0-BEC6-00805F7C4268}";
                    break;
                }

                case esriFeatureType.esriFTSimpleJunction:
                {
                    esriGeometryType_0 = esriGeometryType.esriGeometryPoint;
                    uid_0.Value        = "{CEE8D6B8-55FE-11D1-AE55-0000F80372B4}";
                    break;
                }

                case esriFeatureType.esriFTSimpleEdge:
                {
                    esriGeometryType_0 = esriGeometryType.esriGeometryPolyline;
                    uid_0.Value        = "{E7031C90-55FE-11D1-AE55-0000F80372B4}";
                    break;
                }

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

                case esriFeatureType.esriFTComplexEdge:
                {
                    esriGeometryType_0 = esriGeometryType.esriGeometryPolyline;
                    uid_0.Value        = "{A30E8A2A-C50B-11D1-AEA9-0000F80372B4}";
                    break;
                }

                case esriFeatureType.esriFTAnnotation:
                {
                    esriGeometryType_0 = esriGeometryType.esriGeometryPolygon;
                    uid_0.Value        = "{E3676993-C682-11D2-8A2A-006097AFF44E}";
                    break;
                }

                case esriFeatureType.esriFTDimension:
                {
                    esriGeometryType_0 = esriGeometryType.esriGeometryPolygon;
                    uid_0.Value        = "{496764FC-E0C9-11D3-80CE-00C04F601565}";
                    break;
                }
                }
            }
            if (uid_1 == null)
            {
                switch (esriFeatureType_0)
                {
                case esriFeatureType.esriFTAnnotation:
                {
                    uid_1 = new UID()
                    {
                        Value = "{24429589-D711-11D2-9F41-00C04F6BC6A5}"
                    };
                    break;
                }

                case esriFeatureType.esriFTDimension:
                {
                    uid_1 = new UID()
                    {
                        Value = "{48F935E2-DA66-11D3-80CE-00C04F601565}"
                    };
                    break;
                }
                }
            }
            if (ifields_0 == null)
            {
                ifields_0 = new ESRI.ArcGIS.Geodatabase.Fields();
                IFieldsEdit      ifields0          = (IFieldsEdit)ifields_0;
                IGeometryDef     geometryDefClass  = new GeometryDef();
                IGeometryDefEdit esriGeometryType0 = (IGeometryDefEdit)geometryDefClass;
                esriGeometryType0.GeometryType_2 = esriGeometryType_0;
                esriGeometryType0.GridCount_2    = 1;
                esriGeometryType0.GridSize_2[0]  = 0.5;
                esriGeometryType0.AvgNumPoints_2 = 2;
                esriGeometryType0.HasM_2         = false;
                esriGeometryType0.HasZ_2         = true;
                if (object_0 is IWorkspace)
                {
                    esriGeometryType0.SpatialReference_2 = ispatialReference_0;
                }
                IField     fieldClass = new ESRI.ArcGIS.Geodatabase.Field();
                IFieldEdit fieldEdit  = (IFieldEdit)fieldClass;
                fieldEdit.Name_2      = "OBJECTID";
                fieldEdit.AliasName_2 = "OBJECTID";
                fieldEdit.Type_2      = esriFieldType.esriFieldTypeOID;
                ifields0.AddField(fieldClass);
                IField     field      = new ESRI.ArcGIS.Geodatabase.Field();
                IFieldEdit fieldEdit1 = (IFieldEdit)field;
                fieldEdit1.Name_2        = "SHAPE";
                fieldEdit1.AliasName_2   = "SHAPE";
                fieldEdit1.Type_2        = esriFieldType.esriFieldTypeGeometry;
                fieldEdit1.GeometryDef_2 = geometryDefClass;
                ifields0.AddField(field);
            }
            string name = "";
            int    num  = 0;

            while (true)
            {
                if (num > ifields_0.FieldCount - 1)
                {
                    break;
                }
                else if (ifields_0.Field[num].Type == esriFieldType.esriFieldTypeGeometry)
                {
                    name = ifields_0.Field[num].Name;
                    break;
                }
                else
                {
                    num++;
                }
            }
            if (name == "")
            {
                throw new Exception("Cannot locate geometry field in FIELDS");
            }
            IFeatureClass featureClass = null;

            if (object_0 is IWorkspace)
            {
                IFeatureWorkspace object0 = (IFeatureWorkspace)((IWorkspace)object_0);
                featureClass = object0.CreateFeatureClass(string_0, ifields_0, uid_0, uid_1, esriFeatureType_0, name,
                                                          string_1);
            }
            else if (object_0 is IFeatureDataset)
            {
                IFeatureDataset featureDataset = (IFeatureDataset)object_0;
                featureClass = featureDataset.CreateFeatureClass(string_0, ifields_0, uid_0, uid_1, esriFeatureType_0,
                                                                 name, string_1);
            }
            return(featureClass);
        }
Пример #24
0
        async static public Task <pgFeatureClass> Create(pgFDB fdb, IDataset dataset, GeometryDef geomDef, BinarySearchTree tree)
        {
            var fc = await pgFeatureClass.Create(fdb, dataset, geomDef);

            fc._searchTree = tree;

            return(fc);
        }
Пример #25
0
        override public List <IActivityData> Process()
        {
            IDatasetElement sElement = base.SourceDatasetElement;
            IFeatureClass   sFc      = base.SourceFeatureClass;

            TargetDatasetElement tElement = base.TargetDatasetElement;
            IDataset             tDs      = base.TargetDataset;
            //IFeatureDatabase tDatabase = base.TargetFeatureDatabase;

            GeometryDef geomDef = new GeometryDef(
                geometryType.Polygon,
                null,
                false);

            IFeatureClass    tFc       = base.CreateTargetFeatureclass(geomDef, sFc.Fields);
            IFeatureDatabase tDatabase = FeatureDatabase(tFc);

            Report.featureMax = sFc.CountFeatures;
            Report.featurePos = 0;
            ReportProgess("Query Filter: " + SourceData.FilterClause);

            using (IFeatureCursor cursor = SourceData.GetFeatures(String.Empty))
            {
                IFeature        feature;
                List <IFeature> features = new List <IFeature>();

                ReportProgess("Read/Write Features...");
                while ((feature = cursor.NextFeature) != null)
                {
                    if (feature.Shape is ITopologicalOperation)
                    {
                        feature.Shape = ((ITopologicalOperation)feature.Shape).Buffer(_bufferDistance);
                    }
                    else
                    {
                        continue;
                    }

                    if (feature.Shape == null)
                    {
                        continue;
                    }

                    features.Add(feature);

                    Report.featurePos++;
                    ReportProgess();
                    if (!CancelTracker.Continue)
                    {
                        break;
                    }

                    if (features.Count > 100)
                    {
                        if (!tDatabase.Insert(tFc, features))
                        {
                            throw new Exception(tDatabase.lastErrorMsg);
                        }
                        features.Clear();
                    }
                }

                if (features.Count > 0)
                {
                    ReportProgess();
                    if (!tDatabase.Insert(tFc, features))
                    {
                        throw new Exception(tDatabase.lastErrorMsg);
                    }
                }

                ReportProgess("Flush Features");
                base.FlushFeatureClass(tFc);

                return(base.ToProcessResult(tFc));
            }
        }
Пример #26
0
        private IFeatureClass MakePointFC()
        {
            string strFCName;

            try
            {
                IGxCatalogDefaultDatabase Defaultgdb = ArcMap.Application as IGxCatalogDefaultDatabase;
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                IWorkspace        pWorkspace       = workspaceFactory.OpenFromFile(Defaultgdb.DefaultDatabaseName.PathName, 0);



                IFeatureWorkspace workspace = pWorkspace as IFeatureWorkspace;
                UID CLSID = new UID();
                CLSID.Value = "esriGeodatabase.Feature";

                IFields     pFields     = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                pFieldsEdit.FieldCount_2 = 6;


                IGeoDataset geoDataset = ArcMap.Document.ActiveView.FocusMap.get_Layer(0) as IGeoDataset;


                IGeometryDef     pGeomDef     = new GeometryDef();
                IGeometryDefEdit pGeomDefEdit = pGeomDef as IGeometryDefEdit;
                pGeomDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint;
                pGeomDefEdit.SpatialReference_2 = geoDataset.SpatialReference;



                IField     pField;
                IFieldEdit pFieldEdit;

                //pField = new FieldClass();
                //pFieldEdit = pField as IFieldEdit;
                //pFieldEdit.AliasName_2 = "ObjectID";
                //pFieldEdit.Name_2 = "ObjectID";
                //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
                //pFieldsEdit.set_Field(0, pFieldEdit);

                pField                   = new FieldClass();
                pFieldEdit               = pField as IFieldEdit;
                pFieldEdit.AliasName_2   = "SHAPE";
                pFieldEdit.Name_2        = "SHAPE";
                pFieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
                pFieldEdit.GeometryDef_2 = pGeomDef;
                pFieldsEdit.set_Field(0, pFieldEdit);


                pField                 = new FieldClass();
                pFieldEdit             = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "LineOID";
                pFieldEdit.Name_2      = "LineOID";
                pFieldEdit.Type_2      = esriFieldType.esriFieldTypeInteger;
                pFieldsEdit.set_Field(1, pFieldEdit);

                pField                 = new FieldClass();
                pFieldEdit             = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "Distance";
                pFieldEdit.Name_2      = "Distance";
                pFieldEdit.Type_2      = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.set_Field(2, pFieldEdit);

                pField                 = new FieldClass();
                pFieldEdit             = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "Elevation";
                pFieldEdit.Name_2      = "Elevation";
                pFieldEdit.Type_2      = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.set_Field(3, pFieldEdit);

                pField                 = new FieldClass();
                pFieldEdit             = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "X";
                pFieldEdit.Name_2      = "X";
                pFieldEdit.Type_2      = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.set_Field(4, pFieldEdit);

                pField                 = new FieldClass();
                pFieldEdit             = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "Y";
                pFieldEdit.Name_2      = "Y";
                pFieldEdit.Type_2      = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.set_Field(5, pFieldEdit);


                strFCName = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName());
                char[] chars = strFCName.ToCharArray();
                if (Char.IsDigit(chars[0]))
                {
                    strFCName = strFCName.Remove(0, 1);
                }
                KillExistingFeatureclass(strFCName);


                IFeatureClass pFeatureClass = workspace.CreateFeatureClass(strFCName, pFieldsEdit, CLSID, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                return(pFeatureClass);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
                return(null);
            }
        }
Пример #27
0
        async static public Task <pgFeatureClass> Create(pgFDB fdb, IDataset dataset, GeometryDef geomDef)
        {
            var fc = new pgFeatureClass();

            fc._fdb = fdb;

            fc._dataset = dataset;
            fc._geomDef = (geomDef != null) ? geomDef : new GeometryDef();

            if (fc._geomDef != null && fc._geomDef.SpatialReference == null && dataset is IFeatureDataset)
            {
                fc._geomDef.SpatialReference = await((IFeatureDataset)dataset).GetSpatialReference();
            }

            fc.m_fields = new Fields();

            return(fc);
        }
Пример #28
0
        async static public Task <SqlFDBNetworkFeatureclass> Create(SqlFDB fdb, IDataset dataset, string name, GeometryDef geomDef)
        {
            var fc = new SqlFDBNetworkFeatureclass();

            fc._fdb  = fdb;
            fc._fcid = await fc._fdb.FeatureClassID(await fc._fdb.DatasetID(dataset.DatasetName), name);

            fc._dataset = dataset;
            fc._geomDef = (geomDef != null) ? geomDef : new GeometryDef();

            if (fc._geomDef != null && fc._geomDef.SpatialReference == null && dataset is IFeatureDataset)
            {
                fc._geomDef.SpatialReference = await((IFeatureDataset)dataset).GetSpatialReference();
            }

            fc._fields = new Fields();

            fc._name = fc._aliasname = name;

            IDatasetElement element = await fc._dataset.Element(fc._name + "_Nodes");

            if (element != null)
            {
                fc._nodeFc = element.Class as IFeatureClass;
            }

            element = await fc._dataset.Element(fc._name + "_ComplexEdges");

            if (element != null && element.Class is IFeatureClass)
            {
                fc._edgeFcs.Add(-1, (IFeatureClass)element.Class);
            }

            DataTable tab = await fc._fdb.Select("FCID", "FDB_NetworkClasses", "NetworkId=" + fc._fcid);

            if (tab != null && tab.Rows.Count > 0)
            {
                StringBuilder where = new StringBuilder();
                where.Append("GeometryType=" + ((int)geometryType.Polyline).ToString() + " AND ID in(");
                for (int i = 0; i < tab.Rows.Count; i++)
                {
                    if (i > 0)
                    {
                        where.Append(",");
                    }
                    where.Append(tab.Rows[i]["FCID"].ToString());
                }
                where.Append(")");

                tab = await fc._fdb.Select("ID,Name", "FDB_FeatureClasses", where.ToString());

                if (tab != null)
                {
                    foreach (DataRow row in tab.Rows)
                    {
                        element = await fc._dataset.Element(row["Name"].ToString());

                        if (element != null && element.Class is IFeatureClass)
                        {
                            fc._edgeFcs.Add((int)row["ID"], element.Class as IFeatureClass);
                        }
                    }
                }
            }

            fc._weights = await fc._fdb.GraphWeights(name);

            Dictionary <Guid, string> weightTableNames             = null;
            Dictionary <Guid, GraphWeightDataType> weightDataTypes = null;

            if (fc._weights != null && fc._weights.Count > 0)
            {
                weightTableNames = new Dictionary <Guid, string>();
                weightDataTypes  = new Dictionary <Guid, GraphWeightDataType>();
                foreach (IGraphWeight weight in fc._weights)
                {
                    if (weight == null)
                    {
                        continue;
                    }

                    weightTableNames.Add(weight.Guid, fc._fdb.TableName(fc._name + "_Weights_" + weight.Guid.ToString("N").ToLower()));
                    weightDataTypes.Add(weight.Guid, weight.DataType);
                }
            }
            fc._pageManager = new NetworkObjectSerializer.PageManager(
                System.Data.SqlClient.SqlClientFactory.Instance,
                fc._fdb.ConnectionString, fc._name,
                fc._fdb.TableName("FC_" + fc._name),
                fc._fdb.TableName(fc._name + "_Edges"),
                fc._fdb.TableName("FC_" + name + "_Nodes"),
                weightTableNames, weightDataTypes, fc._fdb
                );

            return(fc);
        }
Пример #29
0
        public static IFields createBasicFields(esriGeometryType shapeType, ISpatialReference pSpaRef, bool hasM = false, bool hasZ = false)
        {
            // Error Handling
            const string functionName = "createBasicFields";

            IFields pFlds;
            IFieldsEdit pFldsEdt;

            IField pFld;
            IFieldEdit pFldEdt;

            IGeometryDefEdit pGeoDef;

            try
            {
                pFlds = new ESRI.ArcGIS.Geodatabase.Fields();
                pFldsEdt = (IFieldsEdit)pFlds;

                pFld = new ESRI.ArcGIS.Geodatabase.Field();
                pFldEdt = (IFieldEdit)pFld;

                pGeoDef = new GeometryDef() as IGeometryDefEdit;

                pGeoDef.GeometryType_2 = shapeType;
                pGeoDef.HasM_2 = hasM;
                pGeoDef.HasZ_2 = hasZ;
                pGeoDef.SpatialReference_2 = pSpaRef;

                // add Geometry field
                pFldEdt = new ESRI.ArcGIS.Geodatabase.Field() as IFieldEdit;
                pFldEdt.Name_2 = "Shape";
                pFldEdt.IsNullable_2 = true;
                pFldEdt.Type_2 = esriFieldType.esriFieldTypeGeometry;
                pFldEdt.GeometryDef_2 = pGeoDef;

                pFldsEdt.AddField(pFldEdt);

                if (shapeType == esriGeometryType.esriGeometryPolygon)
                {
                    pFldEdt = new ESRI.ArcGIS.Geodatabase.Field() as IFieldEdit;

                    pFldEdt.Name_2 = "shape_area";
                    pFldEdt.Type_2 = esriFieldType.esriFieldTypeDouble;
                    pFldEdt.Precision_2 = 19;
                    pFldEdt.Scale_2 = 3;

                    pFldsEdt.AddField(pFldEdt);
                }

                pFldEdt = new ESRI.ArcGIS.Geodatabase.Field() as IFieldEdit;

                pFldEdt.Name_2 = "area";
                pFldEdt.Type_2 = esriFieldType.esriFieldTypeDouble;
                pFldEdt.Precision_2 = 19;
                pFldEdt.Scale_2 = 3;

                pFldsEdt.AddField(pFldEdt);
            }
            catch (Exception e)
            {
                MessageBox.Show(functionName + " :: " + e.Message, "SF10", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return null;
            }

            return pFldsEdt;
        }
Пример #30
0
        public static IFeatureClass createNewEmptyShapefilePoint(string sP, string sN, int sPj)
        {
            String strFolder;
            String strName;
            const string strShapeFieldName = "Shape";

            try
            {
                strFolder = sP;
                strName = sN;

                // Open the folder to contain the shapefile as a workspace
                IFeatureWorkspace pFWS;
                IWorkspaceFactory pWorkspaceFactory;
                pWorkspaceFactory = new ShapefileWorkspaceFactory();
                pFWS = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(strFolder, 0);

                // Set up a simple fields collection
                IFields pFields;
                IFieldsEdit pFieldsEdit;
                pFields = new Fields();
                pFieldsEdit = (IFieldsEdit)pFields;

                IField pField;
                IFieldEdit pFieldEdit;

                // Make the shape field
                // it will need a geometry definition, with a spatial reference

                pField = new Field();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Name_2 = strShapeFieldName;
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

                IGeometryDef pGeomDef;
                IGeometryDefEdit pGeomDefEdit;
                pGeomDef = new GeometryDef();
                pGeomDefEdit = (IGeometryDefEdit)pGeomDef;

                pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint; //Creates point shapefile

                if (sPj == 0)
                {
                    pGeomDefEdit.SpatialReference_2 = new UnknownCoordinateSystemClass();
                }
                else
                {
                    ISpatialReferenceFactory2 pSpatRefFact;
                    pSpatRefFact = new SpatialReferenceEnvironment() as ISpatialReferenceFactory2;
                    IProjectedCoordinateSystem pGeoCoordSys;
                    pGeoCoordSys = pSpatRefFact.CreateProjectedCoordinateSystem(sPj);
                    pGeomDefEdit.SpatialReference_2 = pGeoCoordSys;
                }

                pFieldEdit.GeometryDef_2 = pGeomDef;
                pFieldsEdit.AddField(pField);

                // Add another miscellaneous text field
                pField = new Field();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Length_2 = 25;
                pFieldEdit.Name_2 = "TextField";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                pFieldsEdit.AddField(pField);

                // Create the shapefile
                return pFWS.CreateFeatureClass(strName, pFields, null, null, esriFeatureType.esriFTSimple, strShapeFieldName, "");
            }
            catch
            { return null; }
        }
Пример #31
0
        static public IFeatureLayer CreateShapefileLayer(IMap mapCtrl, string strFolder, string strName, int app)//app表示 0-点要素,1-线要素
        {
            const string strShapeFieldName = "Shape";
            //Open the folder to contain the shapefile as a workspace
            IFeatureWorkspace pFWS;
            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();

            pFWS = pWorkspaceFactory.OpenFromFile(strFolder, 0) as IFeatureWorkspace;
            //Set up a simple fields collection
            IFields     pFields     = new FieldsClass();
            IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
            //Make the shape field
            //it will need a geometry definition, with a spatial reference
            IField     pField     = new FieldClass();
            IFieldEdit pFieldEdit = pField as IFieldEdit;

            pFieldEdit.Name_2 = strShapeFieldName;
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            IGeometryDef     pGeometryDef     = new GeometryDef();
            IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;

            if (app == 0)
            {
                pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
            }
            else
            {
                pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolyline;
            }
            pGeometryDefEdit.SpatialReference_2 = mapCtrl.SpatialReference;
            pGeometryDefEdit.HasZ_2             = true;
            pFieldEdit.GeometryDef_2            = pGeometryDef;
            pFieldsEdit.AddField(pField);
            //Add another field
            pField                 = new FieldClass();
            pFieldEdit             = pField as IFieldEdit;
            pFieldEdit.Length_2    = 30;
            pFieldEdit.Name_2      = "Name";
            pFieldEdit.AliasName_2 = "AliasName";
            pFieldEdit.Type_2      = esriFieldType.esriFieldTypeString;
            pFieldsEdit.AddField(pField);
            //Add another field
            pField                 = new FieldClass();
            pFieldEdit             = pField as IFieldEdit;
            pFieldEdit.Length_2    = 30;
            pFieldEdit.Name_2      = "Elev";
            pFieldEdit.AliasName_2 = "Elev";
            pFieldEdit.Type_2      = esriFieldType.esriFieldTypeDouble;
            pFieldsEdit.AddField(pField);
            //Add another field
            pField                 = new FieldClass();
            pFieldEdit             = pField as IFieldEdit;
            pFieldEdit.Length_2    = 30;
            pFieldEdit.Name_2      = "TerlkFID";
            pFieldEdit.AliasName_2 = "TerlkFID";
            pFieldEdit.Type_2      = esriFieldType.esriFieldTypeInteger;
            pFieldsEdit.AddField(pField);
            //Add another field
            pField                 = new FieldClass();
            pFieldEdit             = pField as IFieldEdit;
            pFieldEdit.Length_2    = 30;
            pFieldEdit.Name_2      = "WhereAtcou";
            pFieldEdit.AliasName_2 = "WhereAtcou";
            pFieldEdit.Type_2      = esriFieldType.esriFieldTypeInteger;
            pFieldsEdit.AddField(pField);
            //Add another field
            pField                 = new FieldClass();
            pFieldEdit             = pField as IFieldEdit;
            pFieldEdit.Length_2    = 30;
            pFieldEdit.Name_2      = "Mark";
            pFieldEdit.AliasName_2 = "Mark";
            pFieldEdit.Type_2      = esriFieldType.esriFieldTypeInteger;
            pFieldsEdit.AddField(pField);
            //Add another field
            pField                 = new FieldClass();
            pFieldEdit             = pField as IFieldEdit;
            pFieldEdit.Length_2    = 30;
            pFieldEdit.Name_2      = "Curve";
            pFieldEdit.AliasName_2 = "Curve";
            pFieldEdit.Type_2      = esriFieldType.esriFieldTypeDouble;
            pFieldsEdit.AddField(pField);
            //Add another field
            if (app == 1)
            {
                pField                 = new FieldClass();
                pFieldEdit             = pField as IFieldEdit;
                pFieldEdit.Length_2    = 30;
                pFieldEdit.Name_2      = "Code";
                pFieldEdit.AliasName_2 = "Code";
                pFieldEdit.Type_2      = esriFieldType.esriFieldTypeInteger;
                pFieldsEdit.AddField(pField);
            }
            //Create the shapefile
            IFeatureClass featureClass = pFWS.CreateFeatureClass(strName, pFields, null, null, esriFeatureType.esriFTSimple, "Shape", "");
            IFeatureLayer featurelayer = new FeatureLayerClass();

            featurelayer.Name         = strName;
            featurelayer.FeatureClass = featureClass;
            //ILayer layer = featurelayer as ILayer;
            return(featurelayer);
            //mapCtrl.AddLayer((ILayer)featurelayer);
        }
Пример #32
0
        public OperateFieldInfoForm(IFieldInfo fieldInfo)
        {
            InitializeComponent();

            // 新建字段
            if (fieldInfo == null)
            {
                fieldInfo = new FieldInfo();
                isCreate  = true;
            }

            {
                string[] row1 = new string[] { "Name", fieldInfo.Name };
                string[] row2 = new string[] { "FieldType", fieldInfo.FieldType.ToString() };
                string[] row3 = new string[] { "IsSystemField", fieldInfo.IsSystemField.ToString() };
                string[] row4 = new string[] { "Alias", fieldInfo.Alias };
                string[] row5 = null;
                if (fieldInfo.DefaultValue != null)
                {
                    row5 = new string[] { "DefaultValue", fieldInfo.DefaultValue.ToString() }
                }
                ;
                else
                {
                    row5 = new string[] { "DefaultValue", "null" }
                };
                string[] row6  = new string[] { "Editable", fieldInfo.Editable.ToString() };
                string[] row7  = new string[] { "Length", fieldInfo.Length.ToString() };
                string[] row8  = new string[] { "Nullable", fieldInfo.Nullable.ToString() };
                string[] row9  = new string[] { "RegisteredRenderIndex", fieldInfo.RegisteredRenderIndex.ToString() };
                string[] row10 = new string[] { "Precision", fieldInfo.Precision.ToString() };
                string[] row11 = new string[] { "Scale", fieldInfo.Scale.ToString() };
                string[] row12 = new string[] { "DomainFixed", fieldInfo.DomainFixed.ToString() };
                object[] rows  = new object[] { row1, row2, row3, row4, row5, row6, row7, row8, row9, row10, row11, row12 };
                foreach (string[] rowArray in rows)
                {
                    this.dataGridView1.Rows.Add(rowArray);
                }
            }

            if (fieldInfo.GeometryDef != null)
            {
                string[] row1  = new string[] { "GeometryDef.GeometryColumnType", fieldInfo.GeometryDef.GeometryColumnType.ToString() };
                string[] row2  = new string[] { "GeometryDef.HasSpatialIndex", fieldInfo.GeometryDef.HasSpatialIndex.ToString() };
                string[] row3  = new string[] { "GeometryDef.HasM", fieldInfo.GeometryDef.HasM.ToString() };
                string[] row4  = new string[] { "GeometryDef.HasZ", fieldInfo.GeometryDef.HasZ.ToString() };
                string[] row5  = new string[] { "GeometryDef.MaxM", fieldInfo.GeometryDef.MaxM.ToString() };
                string[] row6  = new string[] { "GeometryDef.MinM", fieldInfo.GeometryDef.MinM.ToString() };
                string[] row7  = new string[] { "GeometryDef.AvgNumPoints", fieldInfo.GeometryDef.AvgNumPoints.ToString() };
                string[] row8  = new string[] { "GeometryDef.Envelope.Width", fieldInfo.GeometryDef.Envelope.Width.ToString() };
                string[] row9  = new string[] { "GeometryDef.Envelope.Height", fieldInfo.GeometryDef.Envelope.Height.ToString() };
                string[] row10 = new string[] { "GeometryDef.Envelope.Depth", fieldInfo.GeometryDef.Envelope.Depth.ToString() };
                string[] row11 = new string[] { "GeometryDef.Envelope.MinX", fieldInfo.GeometryDef.Envelope.MinX.ToString() };
                string[] row12 = new string[] { "GeometryDef.Envelope.MaxX", fieldInfo.GeometryDef.Envelope.MaxX.ToString() };
                string[] row13 = new string[] { "GeometryDef.Envelope.MinY", fieldInfo.GeometryDef.Envelope.MinY.ToString() };
                string[] row14 = new string[] { "GeometryDef.Envelope.MaxY", fieldInfo.GeometryDef.Envelope.MaxY.ToString() };
                string[] row15 = new string[] { "GeometryDef.Envelope.MinZ", fieldInfo.GeometryDef.Envelope.MinZ.ToString() };
                string[] row16 = new string[] { "GeometryDef.Envelope.MaxZ", fieldInfo.GeometryDef.Envelope.MaxZ.ToString() };
                object[] rows  = new object[] { row1, row2, row3, row4, row5, row6, row7, row8, row9, row10, row11, row12, row13, row14, row15, row16 };
                foreach (string[] rowArray in rows)
                {
                    this.dataGridView1.Rows.Add(rowArray);
                }
            }

            if (isCreate)
            {
                IGeometryDef geoDefine = new GeometryDef();
                string[]     row1      = new string[] { "GeometryDef.GeometryColumnType", geoDefine.GeometryColumnType.ToString() };
                string[]     row2      = new string[] { "GeometryDef.HasSpatialIndex", geoDefine.HasSpatialIndex.ToString() };
                string[]     row3      = new string[] { "GeometryDef.HasM", geoDefine.HasM.ToString() };
                string[]     row4      = new string[] { "GeometryDef.HasZ", geoDefine.HasZ.ToString() };
                string[]     row5      = new string[] { "GeometryDef.MaxM", geoDefine.MaxM.ToString() };
                string[]     row6      = new string[] { "GeometryDef.MinM", geoDefine.MinM.ToString() };
                string[]     row7      = new string[] { "GeometryDef.AvgNumPoints", geoDefine.AvgNumPoints.ToString() };
                string[]     row8      = new string[] { "GeometryDef.Envelope.Width", null };
                string[]     row9      = new string[] { "GeometryDef.Envelope.Height", null };
                string[]     row10     = new string[] { "GeometryDef.Envelope.Depth", null };
                string[]     row11     = new string[] { "GeometryDef.Envelope.MinX", null };
                string[]     row12     = new string[] { "GeometryDef.Envelope.MaxX", null };
                string[]     row13     = new string[] { "GeometryDef.Envelope.MinY", null };
                string[]     row14     = new string[] { "GeometryDef.Envelope.MaxY", null };
                string[]     row15     = new string[] { "GeometryDef.Envelope.MinZ", null };
                string[]     row16     = new string[] { "GeometryDef.Envelope.MaxZ", null };
                object[]     rows      = new object[] { row1, row2, row3, row4, row5, row6, row7, row8, row9, row10, row11, row12, row13, row14, row15, row16 };
                foreach (string[] rowArray in rows)
                {
                    this.dataGridView1.Rows.Add(rowArray);
                }
            }

            if (fieldInfo.Domain != null)
            {
                string[] row1 = new string[] { "Domain.Name", fieldInfo.Domain.Name };
                string[] row2 = new string[] { "Domain.Description", fieldInfo.Domain.Description };
                string[] row3 = new string[] { "Domain.DomainType", fieldInfo.Domain.DomainType.ToString() };
                string[] row4 = new string[] { "Domain.FieldType", fieldInfo.Domain.FieldType.ToString() };
                string[] row5 = new string[] { "Domain.Owner", fieldInfo.Domain.Owner };
                object[] rows = new object[] { row1, row2, row3, row4, row5 };
                foreach (string[] rowArray in rows)
                {
                    this.dataGridView1.Rows.Add(rowArray);
                }
            }

            this.dataGridView1.Rows[2].ReadOnly  = true; //IsSystemField只读
            this.dataGridView1.Rows[11].ReadOnly = true; //DomainFixed只读

            if (this.dataGridView1.Rows.Count > 12)
            {
                this.dataGridView1.Rows[13].ReadOnly = true; //HasSpatialIndex属性只读
                this.dataGridView1.Rows[19].ReadOnly = true; //envelope属性都是只读
                this.dataGridView1.Rows[20].ReadOnly = true;
                this.dataGridView1.Rows[21].ReadOnly = true;
                this.dataGridView1.Rows[22].ReadOnly = true;
                this.dataGridView1.Rows[23].ReadOnly = true;
                this.dataGridView1.Rows[24].ReadOnly = true;
                this.dataGridView1.Rows[25].ReadOnly = true;
                this.dataGridView1.Rows[26].ReadOnly = true;
                this.dataGridView1.Rows[27].ReadOnly = true;
            }

            if (this.dataGridView1.Rows.Count > 28)
            {
                this.dataGridView1.Rows[30].ReadOnly = true; //Domain.DomainType只读
                this.dataGridView1.Rows[31].ReadOnly = true; //Domain.FieldType只读
            }
        }
Пример #33
0
        private IFeatureClass MakeInMemoryFeatureClass(FusionTable ft, esriGeometryType geomType)
        {
            try
            {

                ISpatialReferenceFactory pSpatialRefFactory = new SpatialReferenceEnvironmentClass();
                IGeographicCoordinateSystem pGeographicCoordSys = pSpatialRefFactory.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                ISpatialReference pSpaRef = pGeographicCoordSys;
                pSpaRef.SetDomain(-180, 180, -90, 90);

                // Create an in-memory workspace factory.
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.InMemoryWorkspaceFactory");
                IWorkspaceFactory workspaceFactory = Activator.CreateInstance(factoryType) as IWorkspaceFactory;

                // Create an in-memory workspace.
                IWorkspaceName workspaceName = workspaceFactory.Create("", "FusionTable", null, 0);

                // Cast for IName and open a reference to the in-memory workspace through the name object.
                IName name = workspaceName as IName;
                IWorkspace pWorkspace = name.Open() as IWorkspace;

                IFeatureWorkspace workspace = pWorkspace as IFeatureWorkspace;
                UID CLSID = new UID();
                CLSID.Value = "esriGeodatabase.Feature";

                IFields pFields = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                pFieldsEdit.FieldCount_2 = ft.columns.Count + 1;

                IGeometryDef pGeomDef = new GeometryDef();
                IGeometryDefEdit pGeomDefEdit = pGeomDef as IGeometryDefEdit;
                pGeomDefEdit.GeometryType_2 = geomType;
                pGeomDefEdit.SpatialReference_2 = pSpaRef;

                IField pField;
                IFieldEdit pFieldEdit;

                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "SHAPE";
                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                pFieldEdit.GeometryDef_2 = pGeomDef;
                pFieldsEdit.set_Field(0, pFieldEdit);

                int k = 1;
                int i = 0;
                foreach(string col in ft.columns)
                {
                    pField = new FieldClass();
                    pFieldEdit = pField as IFieldEdit;
                    pFieldEdit.AliasName_2 = ft.columns[i];
                    pFieldEdit.Name_2 = ft.columns[i];
                    pFieldEdit.Type_2 = esriFieldType.esriFieldTypeString;
                    pFieldsEdit.set_Field(k, pFieldEdit);
                    k++;
                    i++;
                }

                string strFCName = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName());
                char[] chars = strFCName.ToCharArray();
                if (Char.IsDigit(chars[0]))
                {
                    strFCName = strFCName.Remove(0, 1);
                }

                IFeatureClass pFeatureClass = workspace.CreateFeatureClass(strFCName, pFieldsEdit, CLSID, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                return pFeatureClass;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
                return null;
            }
        }
Пример #34
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            newFieldInfo = new FieldInfo();

            if (this.dataGridView1.Rows[0].Cells[1].Value.ToString() != "")
            {
                newFieldInfo.Name = this.dataGridView1.Rows[0].Cells[1].Value.ToString();
            }
            if (this.dataGridView1.Rows[1].Cells[1].Value.ToString() != "")
            {
                newFieldInfo.FieldType = StringToGviFieldType(this.dataGridView1.Rows[1].Cells[1].Value.ToString());
                if (newFieldInfo.FieldType == gviFieldType.gviFieldUnknown)
                {
                    MessageBox.Show("字段类型不能设置为gviFieldUnknown");
                    this.DialogResult = DialogResult.No;
                    this.dataGridView1.Rows[1].Cells[1].Selected = true;
                    return;
                }
            }
            //if (this.dataGridView1.Rows[2].Cells[1].Value.ToString() != "")
            //    newFieldInfo.IsSystemField = this.dataGridView1.Rows[2].Cells[1].Value.ToString().ToLower() == "true" ? true : false;
            if (this.dataGridView1.Rows[3].Cells[1].Value.ToString() != "")
            {
                newFieldInfo.Alias = this.dataGridView1.Rows[3].Cells[1].Value.ToString();
            }
            if (this.dataGridView1.Rows[4].Cells[1].Value.ToString() != "")
            {
                newFieldInfo.DefaultValue = this.dataGridView1.Rows[4].Cells[1].Value;
            }
            if (this.dataGridView1.Rows[5].Cells[1].Value.ToString() != "")
            {
                newFieldInfo.Editable = this.dataGridView1.Rows[5].Cells[1].Value.ToString().ToLower() == "true" ? true : false;
            }
            if (this.dataGridView1.Rows[6].Cells[1].Value.ToString() != "")
            {
                newFieldInfo.Length = int.Parse(this.dataGridView1.Rows[6].Cells[1].Value.ToString());
            }
            if (this.dataGridView1.Rows[7].Cells[1].Value.ToString() != "")
            {
                newFieldInfo.Nullable = this.dataGridView1.Rows[7].Cells[1].Value.ToString().ToLower() == "true" ? true : false;
            }
            if (this.dataGridView1.Rows[8].Cells[1].Value.ToString() != "")
            {
                newFieldInfo.RegisteredRenderIndex = this.dataGridView1.Rows[8].Cells[1].Value.ToString().ToLower() == "true" ? true : false;
            }
            if (this.dataGridView1.Rows[9].Cells[1].Value.ToString() != "")
            {
                newFieldInfo.Precision = int.Parse(this.dataGridView1.Rows[9].Cells[1].Value.ToString());
            }
            if (this.dataGridView1.Rows[10].Cells[1].Value.ToString() != "")
            {
                newFieldInfo.Scale = int.Parse(this.dataGridView1.Rows[10].Cells[1].Value.ToString());
            }
            //if (this.dataGridView1.Rows[11].Cells[1].Value.ToString() != "")
            //    newFieldInfo.DomainFixed = this.dataGridView1.Rows[11].Cells[1].Value.ToString().ToLower() == "true" ? true : false;

            if (newFieldInfo.FieldType == gviFieldType.gviFieldGeometry)
            {
                IGeometryDef newGeometryDefine = new GeometryDef();
                if (this.dataGridView1.Rows[12].Cells[1].Value.ToString() != "")
                {
                    newGeometryDefine.GeometryColumnType = StringToGviGeometryColumnType(this.dataGridView1.Rows[12].Cells[1].Value.ToString());
                }
                //if (this.dataGridView1.Rows[13].Cells[1].Value.ToString() != "")
                //    newGeometryDefine.HasSpatialIndex = this.dataGridView1.Rows[13].Cells[1].Value.ToString().ToLower() == "true" ? true : false;
                if (this.dataGridView1.Rows[14].Cells[1].Value.ToString() != "")
                {
                    newGeometryDefine.HasM = this.dataGridView1.Rows[14].Cells[1].Value.ToString().ToLower() == "true" ? true : false;
                }
                if (this.dataGridView1.Rows[15].Cells[1].Value.ToString() != "")
                {
                    newGeometryDefine.HasZ = this.dataGridView1.Rows[15].Cells[1].Value.ToString().ToLower() == "true" ? true : false;
                }
                if (this.dataGridView1.Rows[16].Cells[1].Value.ToString() != "")
                {
                    newGeometryDefine.MaxM = double.Parse(this.dataGridView1.Rows[16].Cells[1].Value.ToString());
                }
                if (this.dataGridView1.Rows[17].Cells[1].Value.ToString() != "")
                {
                    newGeometryDefine.MinM = double.Parse(this.dataGridView1.Rows[17].Cells[1].Value.ToString());
                }
                //if (this.dataGridView1.Rows[18].Cells[1].Value.ToString() != "")
                //    newGeometryDefine.AvgNumPoints = int.Parse(this.dataGridView1.Rows[18].Cells[1].Value.ToString());

                newFieldInfo.GeometryDef = newGeometryDefine;
            }

            if (this.dataGridView1.Rows.Count > 28)
            {
                if (this.dataGridView1.Rows[28].Cells[1].Value.ToString() != "")
                {
                    newFieldInfo.Domain.Name = this.dataGridView1.Rows[28].Cells[1].Value.ToString();
                }
                if (this.dataGridView1.Rows[29].Cells[1].Value.ToString() != "")
                {
                    newFieldInfo.Domain.Description = this.dataGridView1.Rows[29].Cells[1].Value.ToString();
                }
                //if (this.dataGridView1.Rows[30].Cells[1].Value.ToString() != "")
                //    newFieldInfo.Domain.DomainType = StringToGviDomainType(this.dataGridView1.Rows[30].Cells[1].Value.ToString());
                //if (this.dataGridView1.Rows[31].Cells[1].Value.ToString() != "")
                //    newFieldInfo.Domain.FieldType = StringToGviFieldType(this.dataGridView1.Rows[31].Cells[1].Value.ToString());
                if (this.dataGridView1.Rows[32].Cells[1].Value.ToString() != "")
                {
                    newFieldInfo.Domain.Owner = this.dataGridView1.Rows[32].Cells[1].Value.ToString();
                }
            }

            this.DialogResult = DialogResult.OK;
            this.Dispose();
        }
Пример #35
0
        public SQLiteFDBNetworkFeatureClass(SQLiteFDB fdb, IDataset dataset, string name, GeometryDef geomDef)
        {
            _fdb  = fdb;
            _fcid = _fdb.FeatureClassID(_fdb.DatasetID(dataset.DatasetName), name);

            _dataset = dataset;
            _geomDef = (geomDef != null) ? geomDef : new GeometryDef();

            if (_geomDef != null && _geomDef.SpatialReference == null && dataset is IFeatureDataset)
            {
                _geomDef.SpatialReference = ((IFeatureDataset)dataset).SpatialReference;
            }

            _fields = new Fields();

            _name = _aliasname = name;

            IDatasetElement element = _dataset[_name + "_Nodes"];

            if (element != null)
            {
                _nodeFc = element.Class as IFeatureClass;
            }

            element = _dataset[_name + "_ComplexEdges"];
            if (element != null && element.Class is IFeatureClass)
            {
                _edgeFcs.Add(-1, (IFeatureClass)element.Class);
            }

            DataTable tab = _fdb.Select("FCID", "FDB_NetworkClasses", "NetworkId=" + _fcid);

            if (tab != null && tab.Rows.Count > 0)
            {
                StringBuilder where = new StringBuilder();
                where.Append("\"GeometryType\"=" + ((int)geometryType.Polyline).ToString() + " AND \"ID\" in(");
                for (int i = 0; i < tab.Rows.Count; i++)
                {
                    if (i > 0)
                    {
                        where.Append(",");
                    }
                    where.Append(tab.Rows[i]["FCID"].ToString());
                }
                where.Append(")");

                tab = _fdb.Select("ID,Name", "FDB_FeatureClasses", where.ToString());
                if (tab != null)
                {
                    foreach (DataRow row in tab.Rows)
                    {
                        element = _dataset[row["name"].ToString()];
                        if (element != null && element.Class is IFeatureClass)
                        {
                            _edgeFcs.Add(Convert.ToInt32(row["id"]), element.Class as IFeatureClass);
                        }
                    }
                }
            }

            _weights = _fdb.GraphWeights(name);
            Dictionary <Guid, string> weightTableNames             = null;
            Dictionary <Guid, GraphWeightDataType> weightDataTypes = null;

            if (_weights != null && _weights.Count > 0)
            {
                weightTableNames = new Dictionary <Guid, string>();
                weightDataTypes  = new Dictionary <Guid, GraphWeightDataType>();
                foreach (IGraphWeight weight in _weights)
                {
                    if (weight == null)
                    {
                        continue;
                    }

                    weightTableNames.Add(weight.Guid, _fdb.TableName(_name + "_Weights_" + weight.Guid.ToString("N").ToLower()));
                    weightDataTypes.Add(weight.Guid, weight.DataType);
                }
            }
            _pageManager = new NetworkObjectSerializer.PageManager(
                gView.Framework.Db.DataProvider.SQLiteProviderFactory,
                _fdb.ConnectionString, _name,
                _fdb.TableName("FC_" + _name),
                _fdb.TableName(_name + "_Edges"),
                _fdb.TableName("FC_" + name + "_Nodes"),
                weightTableNames, weightDataTypes, _fdb
                );
        }
        //public void GeneratePoints2(string sLineLayer, string sDepthPointsLayer,  double dblInterval, string strDepthField)
        //{
        //    try{
        //            IMxDocument pmxdoc = ArcMap.Document as IMxDocument;
        //            IMap pmap = pmxdoc.FocusMap;
        //            IFeatureLayer pDepthSoundings = FindLayer(pmap, sDepthPointsLayer) as IFeatureLayer;
        //            IFeatureLayer pLineLayer = FindLayer(pmap, sLineLayer) as IFeatureLayer;
        //            IFeatureLayer pOutpoints = new FeatureLayerClass();
        //            pOutpoints.FeatureClass = MakePointFC();
        //            pOutpoints.Name = "Output Points";
        //            ArcMap.Document.ActiveView.FocusMap.AddLayer(pOutpoints);
        //            //IFeatureLayer pOutpoints = FindLayer(pmap, sOutpoints) as IFeatureLayer;
        //            //AddField(pOutpoints, "Distance");
        //            //AddField(pOutpoints, "Elevation");
        //            //get the Workspace from the IDataset interface on the feature class
        //            IDataset dataset = (IDataset)pLineLayer.FeatureClass;
        //            IWorkspace workspace = dataset.Workspace;
        //            //Cast for an IWorkspaceEdit
        //            IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
        //            //Start an edit session and operation
        //            workspaceEdit.StartEditing(true);
        //            workspaceEdit.StartEditOperation();
        //            IProgressDialog2 pProgressDialog = ShowProgressIndicator("Calculating...", pLineLayer.FeatureClass.FeatureCount(null), 1);
        //            pProgressDialog.ShowDialog();
        //            //Set up the Outpoints cursor
        //            IFeatureCursor pFCurOutPoints = pOutpoints.Search(null, false);
        //            pFCurOutPoints = pOutpoints.FeatureClass.Insert(true);
        //            //Set up the LineLayer Cursor
        //            IFeatureCursor pFCur = pLineLayer.Search(null, false);
        //            IFeature pLineFeature = pFCur.NextFeature();
        //            IFeatureBuffer pFBuffer = pOutpoints.FeatureClass.CreateFeatureBuffer();
        //            ICurve pCurve;
        //            double dlbStartElevation;
        //            double dblPointElevation;
        //            double dlbProcessedLength = 0;
        //            double dblFCTotalLength = 0;
        //            int p = 0;
        //            while (pLineFeature != null)
        //            {
        //                pProgressDialog.Description = "Calculating line segment " + p.ToString() + " of: " + pLineLayer.FeatureClass.FeatureCount(null).ToString();
        //                //create startpoint
        //                pCurve = pLineFeature.Shape as ICurve;
        //                pFBuffer.Shape = pCurve.FromPoint;
        //                dlbStartElevation = GetPointElevation(pDepthSoundings, pLineLayer, pCurve.FromPoint, strDepthField);
        //                pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID);
        //                pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), 0);
        //                pFBuffer.set_Value(pFBuffer.Fields.FindField("Elevation"), Math.Round(dlbStartElevation, 4));
        //                pFCurOutPoints.InsertFeature(pFBuffer);
        //                double dblTotalDistance = pCurve.Length;
        //                dlbProcessedLength = dblInterval;
        //                IConstructPoint contructionPoint;
        //                IPoint ppoint;
        //                while (dlbProcessedLength <= dblTotalDistance)
        //                {
        //                    contructionPoint = new PointClass();
        //                    contructionPoint.ConstructAlong(pCurve, esriSegmentExtension.esriNoExtension, dlbProcessedLength, false);
        //                    ppoint = new PointClass();
        //                    ppoint = contructionPoint as IPoint;
        //                    pFBuffer.Shape = ppoint;
        //                    dblPointElevation = GetPointElevation(pDepthSoundings, pLineLayer, ppoint, strDepthField);
        //                    //dblFCTotalLength += dblInterval;
        //                    pFBuffer.set_Value(pFBuffer.Fields.FindField("LineOID"), pLineFeature.OID);
        //                    pFBuffer.set_Value(pFBuffer.Fields.FindField("Distance"), Math.Round(dlbProcessedLength, 4));
        //                    pFBuffer.set_Value(pFBuffer.Fields.FindField("Elevation"), Math.Round(dblPointElevation, 4));
        //                    pFCurOutPoints.InsertFeature(pFBuffer);
        //                    dlbProcessedLength += dblInterval;
        //                    pStepProgressor.Step();
        //                }
        //                dblFCTotalLength += dblInterval;
        //                p++;
        //                pLineFeature = pFCur.NextFeature();
        //            }
        //            //cleanup
        //            pFCurOutPoints.Flush();
        //            pFCur.Flush();
        //            //Stop editing
        //            workspaceEdit.StopEditOperation();
        //            workspaceEdit.StopEditing(true);
        //            pProgressDialog.HideDialog();
        //            pmxdoc.ActiveView.Refresh();
        //       }
        //    catch (Exception ex)
        //    {
        //        MessageBox.Show(ex.Message);
        //        MessageBox.Show(ex.StackTrace);
        //    }
        //}
        private IFeatureClass MakePointFC()
        {
            try
            {

                IGxCatalogDefaultDatabase Defaultgdb = ArcMap.Application as IGxCatalogDefaultDatabase;
                Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
                IWorkspace pWorkspace = workspaceFactory.OpenFromFile(Defaultgdb.DefaultDatabaseName.PathName, 0);

                IFeatureWorkspace workspace = pWorkspace as IFeatureWorkspace;
                UID CLSID = new UID();
                CLSID.Value = "esriGeodatabase.Feature";

                IFields pFields = new FieldsClass();
                IFieldsEdit pFieldsEdit = pFields as IFieldsEdit;
                pFieldsEdit.FieldCount_2 = 6;

                IGeoDataset geoDataset = ArcMap.Document.ActiveView.FocusMap.get_Layer(0) as IGeoDataset;

                IGeometryDef pGeomDef = new GeometryDef();
                IGeometryDefEdit pGeomDefEdit = pGeomDef as IGeometryDefEdit;
                pGeomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPoint;
                pGeomDefEdit.SpatialReference_2 = geoDataset.SpatialReference;

                IField pField;
                IFieldEdit pFieldEdit;

                //pField = new FieldClass();
                //pFieldEdit = pField as IFieldEdit;
                //pFieldEdit.AliasName_2 = "ObjectID";
                //pFieldEdit.Name_2 = "ObjectID";
                //pFieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
                //pFieldsEdit.set_Field(0, pFieldEdit);

                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "SHAPE";
                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                pFieldEdit.GeometryDef_2 = pGeomDef;
                pFieldsEdit.set_Field(0, pFieldEdit);

                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "LineOID";
                pFieldEdit.Name_2 = "LineOID";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeInteger;
                pFieldsEdit.set_Field(1, pFieldEdit);

                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "Distance";
                pFieldEdit.Name_2 = "Distance";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.set_Field(2, pFieldEdit);

                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "Elevation";
                pFieldEdit.Name_2 = "Elevation";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.set_Field(3, pFieldEdit);

                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "X";
                pFieldEdit.Name_2 = "X";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.set_Field(4, pFieldEdit);

                pField = new FieldClass();
                pFieldEdit = pField as IFieldEdit;
                pFieldEdit.AliasName_2 = "Y";
                pFieldEdit.Name_2 = "Y";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.set_Field(5, pFieldEdit);

                string strFCName = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetRandomFileName());
                char[] chars = strFCName.ToCharArray();
                if (Char.IsDigit(chars[0]))
                {
                    strFCName = strFCName.Remove(0, 1);
                }
                KillExistingFeatureclass(strFCName);

                IFeatureClass pFeatureClass = workspace.CreateFeatureClass(strFCName, pFieldsEdit, CLSID, null, esriFeatureType.esriFTSimple, "SHAPE", "");
                return pFeatureClass;

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
                return null;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            label2.Text = "正在生成shp文件...";
            OleDbConnection conn_access = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + database_path + ";" + "Persist Security Info=False;");

            conn_access.Open();
            //获取表名
            string           sql_sheet = "select * from[" + comboBox1.Text + "]";
            OleDbDataAdapter ada       = new OleDbDataAdapter(sql_sheet, conn_access);
            DataTable        dt        = new DataTable();

            ada.Fill(dt);
            string            strShapeFolder    = "E:\\毕业设计\\txttoshp";
            string            strShapeFile      = "myshp.shp";
            string            shapeFileName     = strShapeFolder + strShapeFile;
            IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(strShapeFolder, 0);

            IFeatureClass pFeatureClass;

            IPoint      pPoint;
            IFields     pFields     = new Fields();
            IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;
            IField      pField      = new Field();
            IFieldEdit  pFieldEdit  = (IFieldEdit)pField;
            ISpatialReferenceFactory    spatialReferenceFactory = new SpatialReferenceEnvironment();
            IGeographicCoordinateSystem pGCS;

            pGCS = spatialReferenceFactory.CreateGeographicCoordinateSystem
                       ((int)esriSRGeoCS2Type.esriSRGeoCS_AuthalicSphere_GRS1980);
            pFieldEdit.Name_2 = "SHAPE";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;

            IGeometryDefEdit pGeoDef     = new GeometryDef() as IGeometryDefEdit;
            IGeometryDefEdit pGeoDefEdit = (IGeometryDefEdit)pGeoDef;

            pGeoDefEdit.GeometryType_2     = esriGeometryType.esriGeometryPoint;
            pGeoDefEdit.SpatialReference_2 = pGCS;
            pFieldsEdit.AddField(pField);
            pFieldEdit.GeometryDef_2 = pGeoDef;
            //添加字段
            #region
            pField            = new Field();
            pFieldEdit        = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "X坐标值";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
            pFieldsEdit.AddField(pField);

            pField            = new Field();
            pFieldEdit        = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "Y坐标值";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
            pFieldsEdit.AddField(pField);

            pField            = new Field();
            pFieldEdit        = (IFieldEdit)pField;
            pFieldEdit.Name_2 = "高程";
            pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
            pFieldsEdit.AddField(pField);
            #endregion
            //创建shp
            #region
            try
            {
                pFeatureClass = pFeatureWorkspace.CreateFeatureClass(strShapeFile, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
            }
            catch
            {
                pFeatureClass = pFeatureWorkspace.CreateFeatureClass(strShapeFile, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
            }

            progressBar1.Value   = 0;
            progressBar1.Maximum = dt.Rows.Count;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                pPoint   = new ESRI.ArcGIS.Geometry.Point();
                pPoint.X = Convert.ToDouble(dt.Rows[i][1]);
                pPoint.Y = Convert.ToDouble(dt.Rows[i][2]);
                pPoint.Z = Convert.ToDouble(dt.Rows[i][3]);
                IFeature pFeature = pFeatureClass.CreateFeature();
                pFeature.Shape = pPoint;
                pFeature.set_Value(pFeature.Fields.FindField("X坐标值"), dt.Rows[i][1]);
                pFeature.set_Value(pFeature.Fields.FindField("Y坐标值"), dt.Rows[i][2]);
                pFeature.set_Value(pFeature.Fields.FindField("高程"), dt.Rows[i][3]);
                pFeature.Store();
                progressBar1.Value++;
            }

            IFeatureLayer pFeaturelayer = new FeatureLayer();
            pFeaturelayer.FeatureClass = pFeatureClass;
            pFeaturelayer.Name         = "layer";
            axMapControl1.Map.AddLayer(pFeaturelayer);
            #endregion
        }
Пример #38
0
        public static void cp(IPolygon pPolygon)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.Filter = "Shape文件(*.shp)|*.shp";
            saveFileDialog.Title = "新建面shp文件";
            saveFileDialog.CheckFileExists = true;
            saveFileDialog.RestoreDirectory = true;
            DialogResult dialogResult = saveFileDialog.ShowDialog();
            string shpPath;
            string shpName;
            IWorkspaceFactory pWorkSpaceFactory = new ShapefileWorkspaceFactory();
            if (dialogResult == DialogResult.OK)
            {
                IFeatureClass pFeatureClass;
                string date = DateTime.Now.ToLongDateString().ToString();
                //saveFileDialog.FileName = date + "采集的坐标点";
                string fileFullName = saveFileDialog.FileName;
                int index = fileFullName.LastIndexOf("\\");
                shpName = fileFullName.Substring(index + 1);
                shpPath = fileFullName.Substring(0, index);
                IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkSpaceFactory.OpenFromFile(shpPath, 0);
                IWorkspaceEdit pWorkspaceEdit = (IWorkspaceEdit)pFeatureWorkspace;
                IGeometryDef pGeometryDef = new GeometryDef();
                IGeometryDefEdit pGeometryDefEdit = pGeometryDef as IGeometryDefEdit;
                pGeometryDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;//点、线、面什么的

                ISpatialReferenceFactory2 ipSpaRefFa = new SpatialReferenceEnvironmentClass();
                IGeographicCoordinateSystem ipGeoCorSys = new GeographicCoordinateSystemClass();

                ipGeoCorSys = ipSpaRefFa.CreateGeographicCoordinateSystem((int)esriSRGeoCSType.esriSRGeoCS_WGS1984);
                ISpatialReference ipSpaRef = ipGeoCorSys;
                pGeometryDefEdit.SpatialReference_2 = ipSpaRef;

                /*if (System.IO.File.Exists(saveFileDialog.FileName))
                {
                    if (MessageBox.Show("是否替换原文件?", "询问", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {

                        pFeatureClass = pFeatureWorkspace.OpenFeatureClass(shpName);
                        IDataset pDataset = (IDataset)pFeatureClass;
                        pDataset.Delete();
                    }
                    else
                        return;
                }
                else
                {
                    fileFullName = null;
                    return;
                }*/

                //设置字段

                double area;
                IFields pFields = new FieldsClass();
                IFieldsEdit pFieldsEdit = (IFieldsEdit)pFields;

                IField pField = new FieldClass();
                IFieldEdit pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "SHAPE";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
                pFieldEdit.GeometryDef_2 = pGeometryDef;
                pFieldsEdit.AddField(pField);

                pField = new FieldClass();
                pFieldEdit = (IFieldEdit)pField;
                pFieldEdit.Name_2 = "面积";
                pFieldEdit.Type_2 = esriFieldType.esriFieldTypeDouble;
                pFieldsEdit.AddField(pField);
                //创建shp
                pWorkspaceEdit.StartEditOperation();//启动编辑

                pFeatureClass = pFeatureWorkspace.CreateFeatureClass(shpName, pFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");

                pPolygon = new PolygonClass();
                IArea s = pPolygon as IArea;
                area = s.Area;
                IFeature pfeature = pFeatureClass.CreateFeature();
                pfeature.Shape = pPolygon;
                pfeature.set_Value(pfeature.Fields.FindField("面积"), area.ToString());
                pfeature.Store();
                pWorkspaceEdit.StopEditOperation();
                IFeatureLayer pFeaturelayer = new FeatureLayerClass();
                pFeaturelayer.FeatureClass = pFeatureClass;
                pFeaturelayer.Name = "采集坐标图层";

            }
        }