コード例 #1
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            List <ExplorerDialogFilter> filters = new List <ExplorerDialogFilter>();

            filters.Add(new OpenDataFilter());

            ExplorerDialog dlg = new ExplorerDialog("Import Extent", filters, true);

            dlg.MulitSelection = true;

            ISpatialReference sRef = SpatialReference.FromID("epsg:" + cmbEpsgs.SelectedItem.ToString());

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                IEnvelope bounds = null;
                foreach (IExplorerObject exObject in dlg.ExplorerObjects)
                {
                    if (exObject == null || exObject.Object == null)
                    {
                        continue;
                    }

                    IEnvelope objEnvelope = null;

                    if (exObject.Object is IDataset)
                    {
                        foreach (IDatasetElement element in ((IDataset)exObject.Object).Elements)
                        {
                            if (element == null)
                            {
                                continue;
                            }
                            objEnvelope = ClassEnvelope(element.Class, sRef);
                        }
                    }
                    else
                    {
                        objEnvelope = ClassEnvelope(exObject.Object as IClass, sRef);
                    }

                    if (objEnvelope != null)
                    {
                        if (bounds == null)
                        {
                            bounds = new Envelope(objEnvelope);
                        }
                        else
                        {
                            bounds.Union(objEnvelope);
                        }
                    }
                }

                if (bounds != null)
                {
                    this.CurrentEpsgExtent = bounds;
                }
            }

            if (_metadata != null && cmbEpsgs.SelectedIndex >= 0)
            {
                _metadata.SetEPSGEnvelope(_currentEpsg, this.CurrentEpsgExtent);
            }
        }