Example #1
0
        public static bool SetAOIArugment(string[] fnames, IMonitoringSubProduct msp, bool multiSelect, out CoordEnvelope selectedEnvelope)
        {
            float maxResultion           = 0f;
            IRasterDataProvider prd      = null;
            CoordEnvelope       envelope = new CoordEnvelope(double.MaxValue, double.MinValue, double.MaxValue, double.MinValue);

            GeoDo.Project.ISpatialReference prdSpatialRef = null;
            foreach (string item in fnames)
            {
                try
                {
                    prd          = GeoDataDriver.Open(item) as IRasterDataProvider;
                    maxResultion = Math.Max(maxResultion, prd.ResolutionX);
                    envelope     = envelope.Union(new CoordEnvelope(prd.CoordEnvelope.MinX, prd.CoordEnvelope.MinX + prd.ResolutionX * prd.Width,
                                                                    prd.CoordEnvelope.MinY, prd.CoordEnvelope.MinY + prd.ResolutionY * prd.Height));
                    prdSpatialRef = prd.SpatialRef;
                }
                catch
                {
                    throw new ArgumentException("选择的文件:“" + Path.GetFileName(item) + "”无法进行面积统计。");
                }
                finally
                {
                    if (prd != null)
                    {
                        prd.Dispose();
                        prd = null;
                    }
                }
            }
            Size size = new Size((int)(envelope.Width / maxResultion), (int)(envelope.Height / maxResultion));

            using (frmStatSubRegionTemplates frm = new frmStatSubRegionTemplates(size, envelope, maxResultion))
            {
                frm.listView1.MultiSelect = multiSelect;
                if (prdSpatialRef != null)
                {
                    frm.SpatialRef = prdSpatialRef;
                }
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    //Feature[] features = frm.GetSelectedFeatures();
                    //AOIProvider aoiProvider = new AOIProvider(null);
                    //aoiProvider.GetBitmapIndexes
                    msp.ArgumentProvider.SetArg("AOI", frm.GetFeatureAOIIndex());
                    msp.ArgumentProvider.SetArg("AOIFeatures", frm.GetSelectedFeatures());
                    CodeCell.AgileMap.Core.Envelope env = frm.GetSelectedEnvelope();
                    if (env != null)
                    {
                        selectedEnvelope = new CoordEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY);
                    }
                    else
                    {
                        selectedEnvelope = null;
                    }
                    return(true);
                }
                else
                {
                    selectedEnvelope = null;
                    return(false);
                }
            }
        }