async private void btnImport_Click(object sender, EventArgs e) { List <ExplorerDialogFilter> filters = new List <ExplorerDialogFilter>(); filters.Add(new OpenDataFilter()); filters.Add(new OpenSpatialReferenceFilter()); ExplorerDialog dlg = new ExplorerDialog("Import Spatial Reference", filters, true); dlg.MulitSelection = false; if (dlg.ShowDialog() == DialogResult.OK && dlg.ExplorerObjects.Count == 1) { IExplorerObject exObject = dlg.ExplorerObjects[0]; var instatnce = await exObject?.GetInstanceAsync(); if (instatnce is IFeatureDataset) { _sRef = await((IFeatureDataset)instatnce).GetSpatialReference(); } else if (instatnce is IRasterDataset) { _sRef = await((IRasterDataset)instatnce).GetSpatialReference(); } else if (instatnce is IFeatureClass) { _sRef = ((IFeatureClass)instatnce).SpatialReference; } else if (instatnce is IRasterClass) { _sRef = ((IRasterClass)instatnce).SpatialReference; } else if (instatnce is IWebServiceClass) { _sRef = ((IWebServiceClass)instatnce).SpatialReference; } else if (instatnce is ISpatialReference) { _sRef = instatnce as ISpatialReference; } else { MessageBox.Show("Can't import spatial reference from data object..."); return; } MakeGUI(); } }
async private void btnGetGridDataset_Click(object sender, EventArgs e) { List <ExplorerDialogFilter> filters = new List <ExplorerDialogFilter>(); filters.Add(new OpenRasterDatasetFiler()); ExplorerDialog dlg = new ExplorerDialog("Image/Grid Dataset", filters, true); dlg.MulitSelection = false; if (dlg.ShowDialog() == DialogResult.OK) { foreach (IExplorerObject exObject in dlg.ExplorerObjects) { var instance = await exObject?.GetInstanceAsync(); if (instance == null) { continue; } _ds = instance as IRasterDataset; if (_ds != null) { txtGridDataset.Text = _ds.DatasetName; IEnvelope env = null; foreach (IDatasetElement element in await _ds.Elements()) { if (element != null && element.Class is IFeatureClass) { if (env == null) { env = new Envelope(((IFeatureClass)element.Class).Envelope); } else { env.Union(((IFeatureClass)element.Class).Envelope); } } } spatialIndexControl1.Extent = env; } else { txtGridDataset.Text = String.Empty; } } } }