Beispiel #1
0
        public ObjectModels.Common.IEnvelope GetEnvelope()
        {
            var env = _geom.Envelope();
            var ll  = env.GetLowerLeftCoordinate();
            var ur  = env.GetUpperRightCoordinate();

            return(ObjectFactory.CreateEnvelope(ll.X, ll.Y, ur.X, ur.Y));
        }
Beispiel #2
0
        /// <summary>
        /// Установка зумирования и активной выборки (запуск через командную строку - отсюда название)
        /// </summary>
        /// <param name="sel_base">выборка, которую следует отобразить</param>
        internal static void ThroughAssZoomAndSelection(MgSelectionBase sel_base)
        {
            internal_saved_selection = AcMapFeatureEntityService.AddFeaturesToSelectionSet(null, sel_base);             // преобразование в SelectionSet и обратно,

            sel_base = AcMapFeatureEntityService.GetSelection(internal_saved_selection);                                // иначе дает сбой метод GetSelectedFeatures()

            MgEnvelope extents = new MgEnvelope();

            MgReadOnlyLayerCollection layers = sel_base.GetLayers();

            foreach (MgLayerBase layer in layers)
            {
                MgFeatureReader ftr_reader     = sel_base.GetSelectedFeatures(layer, layer.FeatureClassName, false);
                string          geom_prop_name = ftr_reader.GetClassDefinition().DefaultGeometryPropertyName;

                while (ftr_reader.ReadNext())
                {
                    MgByteReader      byte_reader       = ftr_reader.GetGeometry(geom_prop_name);
                    MgAgfReaderWriter agf_reader_writer = new MgAgfReaderWriter();
                    MgGeometry        curr_geom         = agf_reader_writer.Read(byte_reader);
                    extents.ExpandToInclude(curr_geom.Envelope());
                }
            }



            // зумирование и вызов функции выбора через командную строку

            Core.no_handle_selection = true;             // чтобы изменение выборки не обрабатывалось

            string zoom_str;

            if ((extents.Width == 0) && (extents.Width == extents.Height))
            {
                zoom_str = "'_zoom _c "
                           + extents.LowerLeftCoordinate.X.ToString() + "," + extents.LowerLeftCoordinate.Y.ToString() + " ";
            }
            else
            {
                zoom_str = "'_zoom _w "
                           + (extents.LowerLeftCoordinate.X - extents.Width / 2).ToString()
                           + ","
                           + (extents.LowerLeftCoordinate.Y - extents.Height / 2).ToString()
                           + " "
                           + (extents.UpperRightCoordinate.X + extents.Width / 2).ToString()
                           + ","
                           + (extents.UpperRightCoordinate.Y + extents.Height / 2).ToString();
            }


            Core.SendStringToExecute(zoom_str + "\n"
                                     + "ThroughAssZoomAndSelectionHelperFunction\n"
                                     , true, false, false);
        }
Beispiel #3
0
        public override void Invoke()
        {
            var viewer    = this.Viewer;
            var sel       = viewer.GetSelection();
            var selLayers = sel.GetLayers();

            if (selLayers == null)
            {
                MessageBox.Show(Strings.TextNoSelection);
                return;
            }

            //This doesn't work :(
            //
            //var provider = viewer.GetProvider();
            //var featSvc = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService);
            //var ext = sel.GetExtents(featSvc);
            //var ll = ext.LowerLeftCoordinate;
            //var ur = ext.UpperRightCoordinate;
            //viewer.ZoomToExtents(ll.X, ll.Y, ur.X, ur.Y);
            MgEnvelope env = new MgEnvelope();

            if (_agfRw == null)
            {
                _agfRw = new MgAgfReaderWriter();
            }
            for (var i = 0; i < selLayers.GetCount(); i++)
            {
                var layer = selLayers.GetItem(i);
                var fr    = sel.GetSelectedFeatures(layer, layer.FeatureClassName, false);
                try
                {
                    string geomName = layer.GetFeatureGeometryName();
                    while (fr.ReadNext())
                    {
                        if (!fr.IsNull(geomName))
                        {
                            MgByteReader agf  = null;
                            MgGeometry   geom = null;
                            try
                            {
                                agf  = fr.GetGeometry(geomName);
                                geom = _agfRw.Read(agf);
                                env.ExpandToInclude(geom.Envelope());
                            }
                            finally
                            {
                                if (agf != null)
                                {
                                    agf.Dispose();
                                    agf = null;
                                }
                                if (geom != null)
                                {
                                    geom.Dispose();
                                    geom = null;
                                }
                            }
                        }
                    }
                }
                finally
                {
                    fr.Close();
                }
            }
            var ll = env.LowerLeftCoordinate;
            var ur = env.UpperRightCoordinate;

            viewer.ZoomToExtents(ll.X, ll.Y, ur.X, ur.Y);
        }