Esempio n. 1
0
 /// <summary>
 /// return Spatial Reference
 /// </summary>
 /// <returns>ISpatialReference of wgs84</returns>
 internal static ESRI.ArcGIS.Geometry.ISpatialReference returnSR()
 {
     // wgs84
     ESRI.ArcGIS.Geometry.ISpatialReferenceFactory    spatialReferenceFactory    = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
     ESRI.ArcGIS.Geometry.ISpatialReference           spatialReference           = spatialReferenceFactory.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);
     ESRI.ArcGIS.Geometry.ISpatialReferenceResolution spatialReferenceResolution = (ESRI.ArcGIS.Geometry.ISpatialReferenceResolution)spatialReference;
     return(spatialReference);
 }
Esempio n. 2
0
        public ESRI.ArcGIS.Carto.IFeatureLayer2 CreateFeatureLayer(string name, ESRI.ArcGIS.Geometry.ISpatialReference spatialReference, string workspacename)
        {
            ESRI.ArcGIS.Geodatabase.IFeatureClass fc = CreateFeatureClass(name, spatialReference, workspacename);
            ESRI.ArcGIS.Carto.IFeatureLayer2      fl = new ESRI.ArcGIS.Carto.FeatureLayer() as ESRI.ArcGIS.Carto.IFeatureLayer2;
            fl.FeatureClass = fc;
            ((ESRI.ArcGIS.Carto.ILayer)fl).Name = name;

            return(fl);
        }
Esempio n. 3
0
        public ESRI.ArcGIS.Geodatabase.IFeatureClass CreateFeatureClass(string name, ESRI.ArcGIS.Geometry.ISpatialReference spatialReference, string workspacename)
        {
            ESRI.ArcGIS.Geodatabase.IWorkspace w = WorkSpace.CreateInMemoryWorkspace(workspacename);

            ESRI.ArcGIS.Geodatabase.IFeatureWorkspace fw = (ESRI.ArcGIS.Geodatabase.IFeatureWorkspace)w;


            ESRI.ArcGIS.Geodatabase.IFields2 fields = CreateFields(spatialReference);
            ESRI.ArcGIS.esriSystem.UID       uid    = new ESRI.ArcGIS.esriSystem.UID();
            ESRI.ArcGIS.Geodatabase.IFeatureClassDescription fcDesc = new ESRI.ArcGIS.Geodatabase.FeatureClassDescriptionClass();
            ESRI.ArcGIS.Geodatabase.IObjectClassDescription  ocDesc = (ESRI.ArcGIS.Geodatabase.IObjectClassDescription)fcDesc;

            ESRI.ArcGIS.Geodatabase.IFeatureClass fc = fw.CreateFeatureClass(name, fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, ESRI.ArcGIS.Geodatabase.esriFeatureType.esriFTSimple, "Shape", "");

            return(fc);
        }
Esempio n. 4
0
        public override ESRI.ArcGIS.Geodatabase.IFields2 CreateFields(ESRI.ArcGIS.Geometry.ISpatialReference spatialReference)
        {
            ESRI.ArcGIS.Geodatabase.IFields2    fields     = new ESRI.ArcGIS.Geodatabase.FieldsClass();
            ESRI.ArcGIS.Geodatabase.IFieldsEdit fieldsEdit = (ESRI.ArcGIS.Geodatabase.IFieldsEdit)fields;

            ESRI.ArcGIS.Geodatabase.IFieldEdit2 fieldedit = CreateField("ObjectID", "FID", ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeOID, 0);
            fieldsEdit.AddField(fieldedit);

            //add id
            fieldedit = CreateField("LineID", "LineID", ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGUID, 36);
            fieldedit.DefaultValue_2 = 0; // add default for letter
            fieldsEdit.AddField(fieldedit);

            // place holder for letter
            fieldedit = CreateField("LETTER", "LETTER",
                                    ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString, 20);
            fieldedit.DefaultValue_2 = "X"; // add default for letter
            fieldsEdit.AddField(fieldedit);

            // just another field
            fieldedit = CreateField("NOTES", "NOTES",
                                    ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeString, 225);
            fieldsEdit.AddField(fieldedit);

            // add geomtype
            ESRI.ArcGIS.Geodatabase.IGeometryDef     geometryDef     = new ESRI.ArcGIS.Geodatabase.GeometryDefClass();
            ESRI.ArcGIS.Geodatabase.IGeometryDefEdit geometryDefEdit = (ESRI.ArcGIS.Geodatabase.IGeometryDefEdit)geometryDef;
            geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline;

            ESRI.ArcGIS.Geometry.ISpatialReferenceResolution spatialReferenceResolution = (ESRI.ArcGIS.Geometry.ISpatialReferenceResolution)spatialReference;
            ESRI.ArcGIS.Geometry.ISpatialReferenceTolerance  spatialReferenceTolerance  = (ESRI.ArcGIS.Geometry.ISpatialReferenceTolerance)spatialReference;
            spatialReferenceTolerance.SetDefaultXYTolerance();
            geometryDefEdit.SpatialReference_2 = spatialReference;

            ESRI.ArcGIS.Geodatabase.IField     geometryField     = new ESRI.ArcGIS.Geodatabase.FieldClass();
            ESRI.ArcGIS.Geodatabase.IFieldEdit geometryFieldEdit = (ESRI.ArcGIS.Geodatabase.IFieldEdit)geometryField;
            geometryFieldEdit.Name_2        = "Shape";
            geometryFieldEdit.Type_2        = ESRI.ArcGIS.Geodatabase.esriFieldType.esriFieldTypeGeometry;
            geometryFieldEdit.GeometryDef_2 = geometryDef;
            fieldsEdit.AddField(geometryField);

            return(fields);
        }
Esempio n. 5
0
        private void InsertValueAndGetPos2(string FieldName)//位置和要素要同时获取,否则值和位置可能不对应
        {
            //try
            //{
            if (fatherform.MFGridView2 != null)
            {
                //添加列
                if (fatherform.MFGridView2.ColumnCount == 0)
                {
                    if (TitleField == "")
                    {
                        fatherform.MFGridView2.Columns.Add("FeatureID", "FeatureID");
                    }
                    else
                    {
                        fatherform.MFGridView2.Columns.Add(TitleField, TitleField);
                    }
                    fatherform.MFGridView2.Columns.Add(FieldName, FieldName);
                }
                else
                {
                    fatherform.MFGridView2.Columns.Add(FieldName, FieldName);
                }
                //添加值
                ILayer61 SlctdLyr    = Program.sgworld.ProjectTree.GetLayer(LayerID);
                string[] ExtractFile = SlctdLyr.DataSourceInfo.ConnectionString.Split(';');
                string   FilePath    = ExtractFile[0].Substring(9);

                IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(FilePath), 0);
                IFeatureClass     pFeatureClass     = (IFeatureClass)pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileName(FilePath));

                bool   ReProjectOrNot = false;  //标记是否需要重投影
                string LayerCord      = SlctdLyr.CoordinateSystem.WktDescription;
                string TerrainCord    = Program.sgworld.Terrain.CoordinateSystem.WktDescription;
                if (LayerCord != TerrainCord)
                {
                    ReProjectOrNot = true;
                }

                string             AValue    = "";
                IPosition61        cPos      = null;
                List <IPosition61> Positions = new List <IPosition61>();
                double             dXCoord;
                double             dYCoord;
                double             dAltitude         = 0;
                AltitudeTypeCode   eAltitudeTypeCode = AltitudeTypeCode.ATC_ON_TERRAIN;
                double             dYaw      = 0.0;
                double             dPitch    = 0.0;
                double             dRoll     = 0.0;
                double             dDistance = 20000;
                for (int i = 0; i < pFeatureClass.FeatureCount(null); i++)
                {
                    //插入值
                    AValue = pFeatureClass.GetFeature(i).get_Value(pFeatureClass.FindField(FieldName)).ToString();
                    if (fatherform.MFGridView2.ColumnCount == 2)
                    {
                        if (fatherform.MFGridView2.Columns[0].Name == "FeatureID")
                        {
                            this.fatherform.MFGridView2.Rows.Add(pFeatureClass.GetFeature(i).OID, AValue);
                        }
                        else
                        {
                            this.fatherform.MFGridView2.Rows.Add(pFeatureClass.GetFeature(i).get_Value(pFeatureClass.FindField(TitleField)).ToString(), AValue);
                        }
                    }
                    else
                    {
                        if (this.fatherform.MFGridView2.RowCount > 0)
                        {
                            fatherform.MFGridView2.Rows[i].Cells[FieldName].Value = AValue;
                        }
                    }
                    //获取位置
                    ESRI.ArcGIS.Geometry.IGeometry pGeometry = pFeatureClass.GetFeature(i).Shape;
                    if (ReProjectOrNot)
                    {
                        ESRI.ArcGIS.Geometry.ISpatialReferenceFactory    srFactory = new ESRI.ArcGIS.Geometry.SpatialReferenceEnvironmentClass();
                        ESRI.ArcGIS.Geometry.IGeographicCoordinateSystem gcs       = srFactory.CreateGeographicCoordinateSystem((int)ESRI.ArcGIS.Geometry.esriSRGeoCSType.esriSRGeoCS_WGS1984);
                        ESRI.ArcGIS.Geometry.ISpatialReference           sr1       = gcs;
                        pGeometry.Project(sr1);
                    }
                    ESRI.ArcGIS.Geometry.IPoint pPoint = null;
                    switch (pFeatureClass.ShapeType)
                    {
                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint:
                        pPoint = (ESRI.ArcGIS.Geometry.IPoint)pGeometry;

                        break;

                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline:
                        pPoint = ((ESRI.ArcGIS.Geometry.IPolyline)pGeometry).ToPoint;
                        break;

                    case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon:
                        pPoint = ((ESRI.ArcGIS.Geometry.IArea)(ESRI.ArcGIS.Geometry.IPolygon) pGeometry).Centroid;
                        break;

                    default:
                        break;
                    }
                    dXCoord = pPoint.X;
                    dYCoord = pPoint.Y;
                    cPos    = Program.sgworld.Creator.CreatePosition(dXCoord, dYCoord, dAltitude, eAltitudeTypeCode, dYaw, dPitch, dRoll, dDistance);
                    Positions.Add(cPos);
                }
                if (Positions != null)
                {
                    fatherform.StaThemePos = Positions;
                }
            }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show("Unexpected Error:" + ex.Message);
            //}
            /***20130227杨漾(去掉trycatch,抛给上层trycatch处理异常)****/
        }
Esempio n. 6
0
        private static IFields GetCurveAreaFields(bool isShape, bool isDissolved, ESRI.ArcGIS.Geometry.ISpatialReference georef = null)
        {
            IFields     fields     = new FieldsClass();
            IFieldsEdit fieldsEdit = (IFieldsEdit)fields;

            List <IField> fieldList = ClassLib.Fields.getFields(isDissolved);

            fieldsEdit.FieldCount_2 = fieldList.Count + 2;

            for (int i = 0; i < fieldList.Count; i++)
            {
                fieldsEdit.set_Field(i + 2, fieldList[i]);
            }

            // Create Object ID field.
            IField     fieldUserDefined = new Field();
            IFieldEdit fieldEdit        = (IFieldEdit)fieldUserDefined;

            if (isShape)
            {
                fieldEdit.Name_2      = "FID";
                fieldEdit.AliasName_2 = "FID";
            }
            else
            {
                fieldEdit.Name_2      = "OBJECTID";
                fieldEdit.AliasName_2 = "OBJECTID";
            }
            fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID;
            fieldsEdit.set_Field(0, fieldUserDefined);

            // Create Shape field.
            fieldUserDefined = new Field();
            fieldEdit        = (IFieldEdit)fieldUserDefined;
            // Set up geometry definition for the Shape field.
            // You do not have to set the spatial reference, as it is inherited from the feature dataset.
            IGeometryDef     geometryDef     = new GeometryDefClass();
            IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;

            geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline;
            // By setting the grid size to 0, you are allowing ArcGIS to determine the appropriate grid sizes for the feature class.
            // If in a personal geodatabase, the grid size is 1,000. If in a file or ArcSDE geodatabase, the grid size
            // is based on the initial loading or inserting of features.
            if (!isShape)
            {
                geometryDefEdit.GridCount_2 = 1;
                geometryDefEdit.set_GridSize(0, 0);
            }
            geometryDefEdit.HasM_2 = false;
            geometryDefEdit.HasZ_2 = false;
            if (georef != null)
            {
                geometryDefEdit.SpatialReference_2 = georef;
            }
            // Set standard field properties
            fieldEdit.Name_2        = "SHAPE";
            fieldEdit.Type_2        = esriFieldType.esriFieldTypeGeometry;
            fieldEdit.GeometryDef_2 = geometryDef;
            fieldEdit.IsNullable_2  = true;
            fieldEdit.Required_2    = true;
            fieldsEdit.set_Field(1, fieldUserDefined);



            return(fields);
        }
Esempio n. 7
0
 public virtual ESRI.ArcGIS.Geodatabase.IFields2 CreateFields(ESRI.ArcGIS.Geometry.ISpatialReference spatialReference)
 {
     return(null);
 }