コード例 #1
0
        private void loadRasterList()
        {
            bool itWorked = false;

            foreach (KeyValuePair <String, Boolean> raster in rasterList)
            {
                if (raster.Value == true)
                {
                    if (!itWorked)
                    {
                        saveFileTypeList(getExtension());
                    }
                    itWorked = true;

                    string filePath = txbRasterWorkspace.Text + "\\" + addPrefixAndSuffixToFileName(raster.Key) + getExtension();
                    try
                    {
                        IRasterLayer rasterLayer = new RasterLayer();
                        rasterLayer.CreateFromFilePath(filePath);
                        _mxdocument.AddLayer(rasterLayer);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                        // Just So ArcMap doesn't crash ;)
                    }
                }
            }
            if (itWorked)
            {
                _mxdocument.ActivatedView.Refresh();
            }

            rasterList.Clear();
        }
コード例 #2
0
ファイル: add_form.cs プロジェクト: BGCX261/ziggis-svn-to-git
        /// <summary>
        /// Add PostGIS Layer to ArcMap
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ok_Click(object sender, EventArgs e)
        {
            Hide();
            owner.application.RefreshWindow();
            try
            {
                // Create a new layer for each checked PostGIS layers in the list
                if (clbLayers.CheckedItems.Count > 0)
                {
                    foreach (string layerToAdd in clbLayers.CheckedItems)
                    {
                        IFeatureClass fc    = fwks.OpenFeatureClass(layerToAdd);
                        IFeatureLayer layer = new PostGisFeatureLayer();
                        //IFeatureLayer layer = new FeatureLayerClass();

                        IGeoFeatureLayer gfl = layer as IGeoFeatureLayer;

                        /*
                         * // Paolo - remove this
                         * IFeatureRenderer fr = new VerySimpleCustomRenderer();
                         * gfl.Renderer = fr;
                         * //end of sample....
                         */

                        /*
                         * //COD (101,103...)
                         * IUniqueValueRenderer uvr = new CustomUniqueValueRenderer();
                         * uvr.FieldCount = 1;
                         * uvr.set_Field(0, "code");
                         * uvr.DefaultSymbol = (ISymbol)CreateSimpleFillSymbol(0, 0, 255);
                         * uvr.UseDefaultSymbol = true;
                         * //add values
                         * uvr.AddValue("CA06", "CA06", (ISymbol)CreateSimpleFillSymbol(255, 0, 0));
                         * uvr.AddValue("CA05", "CA05", (ISymbol)CreateSimpleFillSymbol(0, 255, 0));
                         * //render
                         * gfl.Renderer = (IFeatureRenderer)uvr;
                         */

                        layer.FeatureClass = fc;
                        layer.Name         = fc.AliasName;
                        // Add the new layer.
                        IMxDocument doc = (IMxDocument)owner.application.Document;
                        doc.AddLayer(layer);
                    }
                }
                else
                {
                    MessageBox.Show("No PostGIS layers added.");
                }
            }
            catch (COMException COMex)
            {
                MessageBox.Show("Error " + COMex.ErrorCode.ToString() + ": " + COMex.Message);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }
コード例 #3
0
        private void LoadFileList()
        {
            bool       itWorked    = false;
            GroupLayer rasterGroup = null;

            if (_fileList.Count > 0)
            {
                rasterGroup      = new GroupLayer();
                rasterGroup.Name = "New Files";
            }

            foreach (KeyValuePair <String, Boolean> file in _fileList)
            {
                if (file.Value == true)
                {
                    if (!itWorked)
                    {
                        //SaveFileTypeList(GetExtension());
                        itWorked = true;
                    }

                    string filePath = txb_FileWorkspace.Text + "\\" + Utilities.Utilities_General.AddPrefixAndSuffixToFileName(file.Key, txb_Prefix.Text, txb_Suffix.Text) + GetExtension();
                    try
                    {
                        IRasterLayer rasterLayer = new RasterLayer();
                        rasterLayer.CreateFromFilePath(filePath);
                        ILegendGroup group = ((ILegendInfo)rasterLayer).get_LegendGroup(0);
                        group.Visible = false;
                        rasterGroup.Add(rasterLayer);
                    }
                    catch (Exception ex)
                    {
                        ex.ToString();
                        // Just So ArcMap doesn't crash ;)
                    }
                }
            }
            if (itWorked)
            {
                if (rasterGroup != null)
                {
                    _mxdocument.AddLayer(rasterGroup);
                }
                _mxdocument.ActivatedView.Refresh();
            }

            _fileList.Clear();
        }
コード例 #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            IGxDialog gxd = new GxDialog();

            gxd.AllowMultiSelect = false;
            gxd.ButtonCaption    = "Add";
            gxd.Title            = "Add a shapefile";
            gxd.RememberLocation = true;

            IGxObjectFilter           filter1 = new GxFilterFileGeodatabases();
            IGxObjectFilter           filter2 = new GxFilterShapefiles();
            IGxObjectFilterCollection filters = gxd as IGxObjectFilterCollection;

            filters.AddFilter(filter1, true);
            filters.AddFilter(filter2, false);

            IEnumGxObject enumObj;

            if (gxd.DoModalOpen(ArcMap.Application.hWnd, out enumObj) == false) // show dialog
            {
                return;                                                         // return if clicking on cancel
            }
            IGxObject gxObj    = enumObj.Next();
            int       len1     = gxObj.FullName.Length;
            int       len2     = gxObj.Name.Length;
            string    shpPath  = gxObj.FullName.Substring(0, len1 - len2);
            string    shpPath2 = gxObj.FullName.Substring(0);

            IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument;

            IWorkspaceFactory wsf          = new ShapefileWorkspaceFactory();
            IWorkspace        ws           = wsf.OpenFromFile(shpPath, 0);
            IFeatureWorkspace fws          = ws as IFeatureWorkspace;
            IFeatureClass     featureClass = fws.OpenFeatureClass(gxObj.BaseName);
            IFeatureLayer     featureLayer = new FeatureLayer();

            featureLayer.FeatureClass = featureClass;
            ILayer layer = (ILayer)featureLayer;

            layer.Name = gxObj.BaseName;
            mxdoc.AddLayer(layer);
            mxdoc.ActiveView.Refresh();
            mxdoc.UpdateContents();

            textBox2.Text = shpPath2;
            tracts        = shpPath2;
        }
コード例 #5
0
        /// <summary>
        /// Add ArcIMS layer to map
        /// </summary>
        /// <param name="ipMxDoc"></param>
        /// <param name="strServer"></param>
        /// <param name="strLayerName"></param>
        /// <param name="strSecretName"></param>
        /// <returns></returns>
        private bool addLayerArcIMS(IMxDocument ipMxDoc, string strServer, string strLayerName, string strSecretName)
        {
            // Connect to service and create new IMS layer
            IIMSServiceDescription pIMSServiceDescription = new IMSServiceName();

            pIMSServiceDescription.URL         = strServer;
            pIMSServiceDescription.Name        = strLayerName;
            pIMSServiceDescription.ServiceType = acServiceType.acMapService;


            IIMSMapLayer pIMSLayer = new IMSMapLayer();

            pIMSLayer.ConnectToService(pIMSServiceDescription);
            pIMSLayer.Visible = false;

            //make them all non-visible
            if (pIMSLayer is ICompositeLayer)
            {
                ICompositeLayer ipCompLayer;
                int             idx;

                ipCompLayer = (ICompositeLayer)pIMSLayer;
                for (idx = 0; idx < ipCompLayer.Count; idx++)
                {
                    ipCompLayer.get_Layer(idx).Visible = false;
                }
            }

            //add it
            ipMxDoc.AddLayer(pIMSLayer);

            // add to the service list
            string strItem = EncodeServiceList(strServer, strLayerName, strSecretName);

            logger.writeLog(StringResources.AddingServiceList + strItem);
            colServiceList.Add(strItem);

            logger.writeLog("strServer = " + strServer + "strServer & strLayerName = " + strServer + strLayerName);
            return(true);
        }
コード例 #6
0
        // Öppnar rasterlager.
        public void AddRasterUsingOpenFileDialog(IActiveView activeView)
        {
            if (activeView == null)
            {
                return;
            }

            System.Windows.Forms.OpenFileDialog openFileDialog = new
                                                                 System.Windows.Forms.OpenFileDialog();
            openFileDialog.InitialDirectory = @"H:\VT2019\GIS_App\Projekt\Program\Data\InData";
            openFileDialog.Filter           = "Rasterfiles (*.tif)|*.tif";
            openFileDialog.FilterIndex      = 2;
            openFileDialog.RestoreDirectory = true;
            openFileDialog.Multiselect      = false;

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                IRasterLayer rasterLayer = new RasterLayer();
                rasterLayer.CreateFromFilePath(openFileDialog.FileName);
                mxDoc.AddLayer(rasterLayer);
            }
        }
コード例 #7
0
        public void MakeScratchPoints()
        {
            try
            {
                IMxDocument pmxdoc = ArcMap.Document as IMxDocument;
                IMap        pmap   = pmxdoc.FocusMap;

                ILayer pShorePoints = FindLayer(pmap, "ShorePoints");

                if (pShorePoints != null)
                {
                    pmap.DeleteLayer(pShorePoints);
                }


                IScratchWorkspaceFactory  workspaceFactory  = new FileGDBScratchWorkspaceFactoryClass();
                IScratchWorkspaceFactory2 workspaceFactory2 = workspaceFactory as IScratchWorkspaceFactory2;
                IWorkspace scratchWorkspace = workspaceFactory2.CreateNewScratchWorkspace();

                IFeatureWorkspace pFeatWorkspace = scratchWorkspace as IFeatureWorkspace;


                // This function creates a new feature class in a supplied feature dataset by building all of the
                // fields from scratch. IFeatureClassDescription (or IObjectClassDescription if the table is
                // created at the workspace level) can be used to get the required fields and are used to
                // get the InstanceClassID and ExtensionClassID.
                // Create new fields collection with the number of fields you plan to add. Must add at least two fields
                // for a feature class: Object ID and Shape field.
                IFields     fields     = new FieldsClass();
                IFieldsEdit fieldsEdit = (IFieldsEdit)fields;
                fieldsEdit.FieldCount_2 = 3;

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

                IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined;
                fieldEdit.Name_2      = "OBJECTID";
                fieldEdit.AliasName_2 = "OBJECT ID";
                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.esriGeometryPoint;
                geometryDefEdit.SpatialReference_2 = pmap.SpatialReference;
                // 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.
                geometryDefEdit.GridCount_2 = 1;
                geometryDefEdit.set_GridSize(0, 0);
                geometryDefEdit.HasM_2 = false;
                geometryDefEdit.HasZ_2 = false;

                // 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);

                // Create a field of type double to hold some information for the features.
                fieldUserDefined = new Field();

                fieldEdit              = (IFieldEdit)fieldUserDefined;
                fieldEdit.Name_2       = "ID";
                fieldEdit.AliasName_2  = "ID";
                fieldEdit.Editable_2   = true;
                fieldEdit.IsNullable_2 = false;
                fieldEdit.Precision_2  = 2;
                fieldEdit.Scale_2      = 5;
                fieldEdit.Type_2       = esriFieldType.esriFieldTypeDouble;
                fieldsEdit.set_Field(2, fieldUserDefined);

                // Create a feature class description object to use for specifying the CLSID and EXTCLSID.
                IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass();
                IObjectClassDescription  ocDesc = (IObjectClassDescription)fcDesc;

                IFeatureClass pLineFClass = pFeatWorkspace.CreateFeatureClass("ShorePoints", fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, "SHAPE", "");


                IFeatureLayer pFeatureLayer = new FeatureLayerClass();
                pFeatureLayer.FeatureClass = pLineFClass;

                pFeatureLayer.Name = "ShorePoints";
                pmxdoc.AddLayer(pFeatureLayer);
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                MessageBox.Show(ex.StackTrace);
            }
        }
コード例 #8
0
ファイル: CSubs.cs プロジェクト: sishui198/UnStackPoints
        /// <summary>
        /// this function takes a table and creates a shapefile (XY events) layer
        /// that is then added to the map
        /// </summary>
        /// <param name="pMxDoc">the map doc</param>
        /// <param name="sWorkspacePath">where to put the shapefile that is generated from the xy events / and where the dbf lives</param>
        /// <param name="sTableName">the name of the dbf to open</param>
        /// <param name="pSpatRef">the spatial ref for the prj file for the shapefile</param>\ 
        /// <changelog>
        ///
        ///         comments created.
        ///
        /// </changelog>
        public void addXYEvents(IMxDocument pMxDoc, string sWorkspacePath, string sTableName, ISpatialReference pSpatRef, string xField, string yField, string zField)
        {
            IWorkspaceFactory pWSF = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFeatureWorkspace = (IFeatureWorkspace)pWSF.OpenFromFile(sWorkspacePath, 0);
            ITable            pTable            = (ITable)pFeatureWorkspace.OpenTable(sTableName);

            if (pTable == null)
            {
                MessageBox.Show("The table was not found");
                return;
            }

            // Create a new standalone table and add it
            // to the collection of the focus map
            IStandaloneTable pStTab = new StandaloneTableClass();

            pStTab.Table = (ITable)pTable;

            //sortTable(ref pTable);

            // Get the table name object
            IDataset pDataSet   = (IDataset)pStTab;
            IName    pTableName = pDataSet.FullName;

            // Specify the X and Y fields
            IXYEvent2FieldsProperties pXYEvent2FieldsProperties = new XYEvent2FieldsPropertiesClass();

            pXYEvent2FieldsProperties.XFieldName = xField;
            pXYEvent2FieldsProperties.YFieldName = yField;
            pXYEvent2FieldsProperties.ZFieldName = zField;

            // Create the XY name object and set it's properties
            IXYEventSourceName pXYEventSourceName = new XYEventSourceNameClass();

            pXYEventSourceName.EventProperties = pXYEvent2FieldsProperties;
            if (pSpatRef != null)
            {
                pXYEventSourceName.SpatialReference = pSpatRef;
            }
            pXYEventSourceName.EventTableName = pTableName;
            IName          pXYName        = (IName)pXYEventSourceName;
            IXYEventSource pXYEventSource = (IXYEventSource)pXYName.Open();

            // Create a new Map Layer
            IFeatureLayer pFLayer = new FeatureLayerClass();

            pFLayer.FeatureClass = (IFeatureClass)pXYEventSource;
            pFLayer.Name         = sTableName;

            //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)
            XYDataSourcePageExtension pRESPageExt = new XYDataSourcePageExtension();
            ILayerExtensions          pLayerExt   = (ILayerExtensions)pFLayer;

            pLayerExt.AddExtension(pRESPageExt);

            //Get the FcName from the featureclass
            IFeatureClass pFc = pFLayer.FeatureClass;

            pDataSet = (IDataset)pFc;
            IFeatureClassName pINFeatureClassName = (IFeatureClassName)pDataSet.FullName;
            IDatasetName      pInDsName           = (IDatasetName)pINFeatureClassName;

            //Get the selection set
            IFeatureSelection pFSel   = (IFeatureSelection)pFLayer;
            ISelectionSet     pSelSet = (ISelectionSet)pFSel.SelectionSet;

            //Define the output feature class name
            IFeatureClassName pFeatureClassName = new FeatureClassNameClass();
            IDatasetName      pOutDatasetName   = (IDatasetName)pFeatureClassName;
            //string sDSName = ensureDataName(pDataSet.Name, sWorkspacePath);

            string sDSName = pDataSet.Name; // +DateTime.UtcNow.DayOfYear + DateTime.UtcNow.Hour + DateTime.UtcNow.Minute + DateTime.UtcNow.Second;

            pOutDatasetName.Name = sDSName;

            IWorkspaceName pWorkspaceName = new WorkspaceNameClass();

            pWorkspaceName.PathName = sWorkspacePath;
            pWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapeFileWorkspaceFactory";

            pOutDatasetName.WorkspaceName    = pWorkspaceName;
            pFeatureClassName.FeatureType    = esriFeatureType.esriFTSimple;
            pFeatureClassName.ShapeType      = esriGeometryType.esriGeometryPoint;
            pFeatureClassName.ShapeFieldName = "Shape";

            //Export
            IExportOperation pExportOp = new ExportOperationClass();

            pExportOp.ExportFeatureClass(pInDsName, null, null, null, pOutDatasetName as IFeatureClassName, 0);

            IFeatureClass pClass = (IFeatureClass)pFeatureWorkspace.OpenFeatureClass(sDSName);
            IFeatureLayer pLayer = new FeatureLayerClass();

            pLayer.FeatureClass = pClass;
            pLayer.Name         = sDSName;//pClass.AliasName;

            pMxDoc.AddLayer(pLayer);
            pMxDoc.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null);
        }
コード例 #9
0
        // Function with arguments that have been passed from each sensor.
        public void bandCombination(GUI_AddRaster theGUI, int int_RedBandIndex, int int_GreenBandIndex, int int_BlueBandIndex)
        {
            try
            {
                // Folder path only.
                string rasterFolderPath = System.IO.Path.GetDirectoryName(theGUI.textBox_PathURL.Text);

                // Image file name only.
                string rasterFileName = System.IO.Path.GetFileName(theGUI.textBox_PathURL.Text);

                // Map document.
                IMxDocument mxDoc = ArcMap.Application.Document as IMxDocument;

                // Needed for working with rasters.
                IWorkspaceFactory wSF = new RasterWorkspaceFactoryClass();

                // Set the raster image workspace.
                IWorkspace wS = wSF.OpenFromFile(rasterFolderPath, ArcMap.Application.hWnd);

                // Prepare the raster workspace.
                IRasterWorkspace rasterWS = wS as IRasterWorkspace;

                // Open the raster image.
                IRasterDataset rasterDataset = rasterWS.OpenRasterDataset(rasterFileName);

                // Prepare raster image as raster layer.
                IRasterLayer rasterLayer = new RasterLayerClass();

                // Create the raster layer from raster image.
                rasterLayer.CreateFromDataset(rasterDataset);

                // Add raster layer to map.
                mxDoc.AddLayer(rasterLayer);

                // Required for displaying raster layer with specific band combinations (the renderer).
                IRasterRGBRenderer2 rgbRen = new RasterRGBRendererClass();
                IRasterRenderer     rasRen = rgbRen as IRasterRenderer;

                // Assign band combination based on parameters that were fed into the function.
                rgbRen.RedBandIndex   = int_RedBandIndex;
                rgbRen.GreenBandIndex = int_GreenBandIndex;
                rgbRen.BlueBandIndex  = int_BlueBandIndex;

                // Rename the raster layer to sensor type + study type + image name, with spaces and file extension removed.
                rasterLayer.Name = theGUI.combo_SensorType.SelectedItem.ToString().Replace(" ", string.Empty) + "_" +
                                   theGUI.combo_StudyType.SelectedItem.ToString().Replace(" ", string.Empty) + "__" +
                                   System.IO.Path.GetFileNameWithoutExtension(rasterFileName).Replace(" ", string.Empty);

                // Update the renderer with band combinations.
                rasterLayer.Renderer = rasRen;
                rasRen.Update();

                if (theGUI.checkBox_RasterExtent.Checked)
                {
                    // Zoom to raster image extent if the checkbox is checked.
                    mxDoc.ActiveView.Extent = rasterLayer.AreaOfInterest;
                }

                // Refresh the map and update the table of contents.
                mxDoc.ActiveView.Refresh();
                mxDoc.UpdateContents();
            }

            catch (Exception exc)
            {
                // Catch any exception found and display a message box.
                MessageBox.Show("Exception caught: " + nL + exc.Message + nL + exc.StackTrace);
                return;
            }
        }
コード例 #10
0
ファイル: OpenWMC.cs プロジェクト: k4th/geoportal-server
        /// <summary>
        /// Add ArcIMS layer to map
        /// </summary>
        /// <param name="ipMxDoc"></param>
        /// <param name="strServer"></param>
        /// <param name="strLayerName"></param>
        /// <param name="strSecretName"></param>
        /// <returns></returns>
        private bool addLayerArcIMS(IMxDocument ipMxDoc, string strServer, string strLayerName, string strSecretName)
        {
            // Connect to service and create new IMS layer
            IIMSServiceDescription pIMSServiceDescription = new IMSServiceName();
            pIMSServiceDescription.URL = strServer;
            pIMSServiceDescription.Name = strLayerName;
            pIMSServiceDescription.ServiceType = acServiceType.acMapService;

            IIMSMapLayer pIMSLayer = new IMSMapLayer();
            pIMSLayer.ConnectToService(pIMSServiceDescription);
            pIMSLayer.Visible = false;

            //make them all non-visible
            if (pIMSLayer is ICompositeLayer)
            {
                ICompositeLayer ipCompLayer;
                int idx;

                ipCompLayer = (ICompositeLayer)pIMSLayer;
                for (idx = 0; idx < ipCompLayer.Count; idx++)
                    ipCompLayer.get_Layer(idx).Visible = false;
            }

            //add it
            ipMxDoc.AddLayer(pIMSLayer);

            // add to the service list
            string strItem = EncodeServiceList(strServer, strLayerName, strSecretName);
            logger.writeLog(StringResources.AddingServiceList + strItem);
            colServiceList.Add(strItem);

            logger.writeLog("strServer = " + strServer + "strServer & strLayerName = " + strServer + strLayerName);
            return true;
        }