Beispiel #1
0
        public bool StartNewDocument()
        {
            try
            {
                // Only required on 10; requires reference to ESRI.ArcGIS.Version (also only on 10)
                if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop))
                {
                    return(false);
                }

                IDocument doc = new MxDocumentClass();
                doc.Parent.Visible = true;
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Beispiel #2
0
        //使用addXY进行经纬度描点
        public void CreateXYLayer()
        {
            try
            {
                IMxDocument pMxDoc;
                IMap pMap = axMapControl.Map;

                IApplication m_app;

                IDocument doc = new MxDocumentClass();
                m_app = doc.Parent;
                pMxDoc = (IMxDocument)m_app.Document;
                pMap = pMxDoc.FocusMap;

                IStandaloneTableCollection pStTabCol;
                IStandaloneTable pStandaloneTable;
                ITable pTable = null;
                pStTabCol = (IStandaloneTableCollection) pMap;
                for (int intCount = 0; intCount < pStTabCol.StandaloneTableCount; intCount++)
                {
                    pStandaloneTable = (IStandaloneTable) pStTabCol.get_StandaloneTable(intCount);
                    if (pStandaloneTable.Name == @"e:\XYSample.txt")
                    {
                        pTable = pStandaloneTable.Table;
                        break;
                    }
                }
                if (pTable == null)
                {
                    MessageBox.Show("The table was not found");
                    return;
                }

                IDataset pDataSet;
                IName pTableName;
                pDataSet = (IDataset) pTable;
                pTableName = pDataSet.FullName;

                IXYEvent2FieldsProperties pXYEvent2FieldsProperties;
                pXYEvent2FieldsProperties = new XYEvent2FieldsPropertiesClass();
                pXYEvent2FieldsProperties.XFieldName = "x";
                pXYEvent2FieldsProperties.YFieldName = "y";
                pXYEvent2FieldsProperties.ZFieldName = "";

                ISpatialReferenceFactory pSpatialReferenceFactory;
                pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
                IProjectedCoordinateSystem pProjectedCoordinateSystem;
                pProjectedCoordinateSystem = pSpatialReferenceFactory.CreateProjectedCoordinateSystem(26911);
                // esriSRProjCS_NAD1983UTM_11N

                // Create the XY name object and set it's properties
                IXYEventSourceName pXYEventSourceName = new XYEventSourceNameClass();
                IName pXYName;
                IXYEventSource pXYEventSource;
                pXYEventSourceName.EventProperties = pXYEvent2FieldsProperties;
                pXYEventSourceName.SpatialReference = pProjectedCoordinateSystem;
                pXYEventSourceName.EventTableName = pTableName;
                pXYName = (IName) pXYEventSourceName;
                pXYEventSource = (IXYEventSource) pXYName.Open();

                // Create a new Map Layer
                IFeatureLayer pFLayer = new FeatureLayerClass();
                pFLayer.FeatureClass = (IFeatureClass) pXYEventSource;
                pFLayer.Name = "Sample XY Event layer";

                // Add the layer extension (this is done so that when you edit
                // the layer's Source properties and click the Set Data Source
                // button, the Add XY Events Dialog appears)
                ILayerExtensions pLayerExt;
                IFeatureLayerSourcePageExtension pRESPageExt = new XYDataSourcePageExtensionClass();
                pLayerExt = (ILayerExtensions) pFLayer;
                pLayerExt.AddExtension(pRESPageExt);

                pMap.AddLayer(pFLayer);
            }

            catch (System.Exception SysEx)
            {
                MessageBox.Show(SysEx.Message,".NET Error: ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
            }
        }
Beispiel #3
0
        //使用addXY进行经纬度描点
        public void  CreateXYLayer()
        {
            try
            {
                IMxDocument pMxDoc;
                IMap        pMap = axMapControl.Map;

                IApplication m_app;

                IDocument doc = new MxDocumentClass();
                m_app  = doc.Parent;
                pMxDoc = (IMxDocument)m_app.Document;
                pMap   = pMxDoc.FocusMap;

                IStandaloneTableCollection pStTabCol;
                IStandaloneTable           pStandaloneTable;
                ITable pTable = null;
                pStTabCol = (IStandaloneTableCollection)pMap;
                for (int intCount = 0; intCount < pStTabCol.StandaloneTableCount; intCount++)
                {
                    pStandaloneTable = (IStandaloneTable)pStTabCol.get_StandaloneTable(intCount);
                    if (pStandaloneTable.Name == @"e:\XYSample.txt")
                    {
                        pTable = pStandaloneTable.Table;
                        break;
                    }
                }
                if (pTable == null)
                {
                    MessageBox.Show("The table was not found");
                    return;
                }

                IDataset pDataSet;
                IName    pTableName;
                pDataSet   = (IDataset)pTable;
                pTableName = pDataSet.FullName;

                IXYEvent2FieldsProperties pXYEvent2FieldsProperties;
                pXYEvent2FieldsProperties            = new XYEvent2FieldsPropertiesClass();
                pXYEvent2FieldsProperties.XFieldName = "x";
                pXYEvent2FieldsProperties.YFieldName = "y";
                pXYEvent2FieldsProperties.ZFieldName = "";

                ISpatialReferenceFactory pSpatialReferenceFactory;
                pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
                IProjectedCoordinateSystem pProjectedCoordinateSystem;
                pProjectedCoordinateSystem = pSpatialReferenceFactory.CreateProjectedCoordinateSystem(26911);
                // esriSRProjCS_NAD1983UTM_11N

                // Create the XY name object and set it's properties
                IXYEventSourceName pXYEventSourceName = new XYEventSourceNameClass();
                IName          pXYName;
                IXYEventSource pXYEventSource;
                pXYEventSourceName.EventProperties  = pXYEvent2FieldsProperties;
                pXYEventSourceName.SpatialReference = pProjectedCoordinateSystem;
                pXYEventSourceName.EventTableName   = pTableName;
                pXYName        = (IName)pXYEventSourceName;
                pXYEventSource = (IXYEventSource)pXYName.Open();

                // Create a new Map Layer
                IFeatureLayer pFLayer = new FeatureLayerClass();
                pFLayer.FeatureClass = (IFeatureClass)pXYEventSource;
                pFLayer.Name         = "Sample XY Event layer";

                // Add the layer extension (this is done so that when you edit
                // the layer's Source properties and click the Set Data Source
                // button, the Add XY Events Dialog appears)
                ILayerExtensions pLayerExt;
                IFeatureLayerSourcePageExtension pRESPageExt = new XYDataSourcePageExtensionClass();
                pLayerExt = (ILayerExtensions)pFLayer;
                pLayerExt.AddExtension(pRESPageExt);

                pMap.AddLayer(pFLayer);
            }

            catch (System.Exception SysEx)
            {
                MessageBox.Show(SysEx.Message, ".NET Error: ", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }