Ejemplo n.º 1
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            string     coordsys = "GEOGCS[\"LL84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.0174532925199433,AUTHORITY[\"EPSG\",\"9108\"]],AXIS[\"Lat\",NORTH],AXIS[\"Long\",EAST],AUTHORITY[\"EPSG\",\"4326\"]]";
            MgEnvelope env      = new MgEnvelope(10, 10, 20, 20);



            MgMapBase map1 = factory.CreateMap(coordsys, env, "map1");
            MgMapBase map2 = factory.CreateMap(coordsys, env, "map2");
            MgMapBase map3 = factory.CreateMap(coordsys, env, "map3");
            MgMapBase map4 = factory.CreateMap(coordsys, env, "map4");

            MgMapCollection coll = new MgMapCollection();

            coll.Add(map1);
            coll.Insert(1, map2);
            coll.Add(map3);

            Assert.AreEqual(3, coll.Count);
            Assert.AreEqual(coll[2].GetName(), "map3");

            coll[1] = map4;


            string txt = "";

            foreach (MgMapBase map in coll)
            {
                txt += "[" + map.GetName() + "]";
            }
            Assert.AreEqual("[map1][map4][map3]", txt);
        }
Ejemplo n.º 2
0
        private void OnLineDigitized(double x1, double y1, double x2, double y2)
        {
            MgMapBase map = mgMapViewer1.GetMap();
            //Create a coordiante system from the map's SRS
            MgCoordinateSystemFactory csFactory = new MgCoordinateSystemFactory();
            MgCoordinateSystem        mapCs     = csFactory.Create(map.GetMapSRS());

            //Invoke the appropriate measure method depending on the type
            //of coordinate system
            double dist = 0.0;

            if (mapCs.GetType() == MgCoordinateSystemType.Geographic)
            {
                dist = mapCs.MeasureGreatCircleDistance(x1, y1, x2, y2);
            }
            else
            {
                dist = mapCs.MeasureEuclideanDistance(x1, y1, x2, y2);
            }

            //Convert this distance to meters
            dist = mapCs.ConvertCoordinateSystemUnitsToMeters(dist);

            MessageBox.Show("Distance is: " + dist + " meters");
        }
Ejemplo n.º 3
0
        private void btnLayerVisibility_Click(object sender, EventArgs e)
        {
            MgMapBase         map    = _viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();

            new LayerVisibilityDialog(layers).ShowDialog();
        }
Ejemplo n.º 4
0
        internal RedlineLayer[] GetAvailableLayers(MgMapBase map)
        {
            var fsId = GetRegistryFeatureSource();
            MgLayerCollection   mapLayers = map.GetLayers();
            List <RedlineLayer> layers    = new List <RedlineLayer>();
            MgFeatureReader     reader    = null;

            try
            {
                reader = _featSvc.SelectFeatures(fsId, "Default:MarkupRegistry", null);
                while (reader.ReadNext())
                {
                    layers.Add(new RedlineLayer(reader.GetString("Name"),
                                                reader.GetString("ResourceId"),
                                                reader.GetString("LayerDefinition"),
                                                reader.GetInt32("GeometryTypes"),
                                                (RedlineStylizationType)reader.GetInt32("StyleType")));
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            return(layers.ToArray());
        }
Ejemplo n.º 5
0
 protected virtual void DisposeExistingMap()
 {
     if (_map != null)
     {
         _map.Dispose();
         _map = null;
     }
 }
Ejemplo n.º 6
0
        private void btnDisplaySpatialReference_Click(object sender, EventArgs e)
        {
            MgMapBase            map   = _viewer.GetMap();
            MgResourceIdentifier resId = map.MapDefinition;
            string mapSrs = map.GetMapSRS();

            MessageBox.Show("Map: (" + resId.ToString() + ") uses this reference system: " + Environment.NewLine + Environment.NewLine + mapSrs);
        }
Ejemplo n.º 7
0
 protected virtual void DisposeExistingMap()
 {
     if (_map != null)
     {
         _map.Dispose();
         _map = null;
     }
 }
Ejemplo n.º 8
0
        private void btnSelectDistrict1_Click(object sender, EventArgs e)
        {
            MgMapBase         map       = _viewer.GetMap();
            MgLayerCollection layers    = map.GetLayers();
            MgLayerBase       districts = layers.GetItem("Districts");
            MgLayerBase       parcels   = layers.GetItem("Parcels");

            //Query the geometry of district 1
            MgFeatureQueryOptions districtQuery = new MgFeatureQueryOptions();

            districtQuery.SetFilter("Autogenerated_SDF_ID = 1");

            MgFeatureReader   reader       = districts.SelectFeatures(districtQuery);
            MgGeometry        districtGeom = null;
            MgAgfReaderWriter agfRw        = new MgAgfReaderWriter();

            try
            {
                reader.ReadNext();
                MgByteReader geomAgf = reader.GetGeometry(districts.GetFeatureGeometryName());
                districtGeom = agfRw.Read(geomAgf);
            }
            finally
            {
                reader.Close();
            }

            //Now use this geometry as the basis of our 2nd query

            MgFeatureQueryOptions parcelQuery = new MgFeatureQueryOptions();

            parcelQuery.SetFilter("RNAME LIKE 'SCHMITT%'");
            parcelQuery.SetSpatialFilter(parcels.GetFeatureGeometryName(), districtGeom, MgFeatureSpatialOperations.Inside);

            //Select the features
            reader = parcels.SelectFeatures(parcelQuery);

            MgSelectionBase selection = _viewer.GetSelection();

            try
            {
                selection.FromXml(""); //Clear existing selection data
                selection.AddFeatures(parcels, reader, 0);
            }
            finally
            {
                reader.Close();
            }

            //Because we manipulated the active selection outside the viewer
            //We need to call UpdateSelection() to instruct the viewer to
            //re-render the active selection. The "true" parameter instructs
            //the viewer to raise the SelectionChanged event as well, so that
            //subscribers like the Property Pane get updated as well.
            _viewer.UpdateSelection(true);
            _viewer.RefreshMap();
        }
Ejemplo n.º 9
0
 public MgLegendControlPresenter(ILegendView legend, MgMapViewerProvider provider)
 {
     _legend = legend;
     _provider = provider;
     _map = _provider.GetMap();
     InitInitialSelectabilityStates();
     _resSvc = (MgResourceService)_provider.CreateService(MgServiceType.ResourceService);
     _selectableIcon = Properties.Resources.lc_select;
     _unselectableIcon = Properties.Resources.lc_unselect;
 }
Ejemplo n.º 10
0
        public RedlineManager(IMapViewer viewer)
        {
            _map    = viewer.GetMap();
            _viewer = viewer;
            var provider = _viewer.GetProvider();

            _resSvc   = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            _featSvc  = (MgFeatureService)provider.CreateService(MgServiceType.FeatureService);
            _registry = new RedlineRegistry(SessionID, _resSvc, _featSvc);
        }
Ejemplo n.º 11
0
        private void btnQueryDistrict1_Click(object sender, EventArgs e)
        {
            MgMapBase         map       = _viewer.GetMap();
            MgLayerCollection layers    = map.GetLayers();
            MgLayerBase       districts = layers.GetItem("Districts");
            MgLayerBase       parcels   = layers.GetItem("Parcels");

            //Query the geometry of district 1
            MgFeatureQueryOptions districtQuery = new MgFeatureQueryOptions();

            districtQuery.SetFilter("Autogenerated_SDF_ID = 1");

            MgFeatureReader   reader       = districts.SelectFeatures(districtQuery);
            MgGeometry        districtGeom = null;
            MgAgfReaderWriter agfRw        = new MgAgfReaderWriter();

            try
            {
                reader.ReadNext();
                MgByteReader geomAgf = reader.GetGeometry(districts.GetFeatureGeometryName());
                districtGeom = agfRw.Read(geomAgf);
            }
            finally
            {
                reader.Close();
            }

            //Now use this geometry as the basis of our 2nd query

            MgFeatureQueryOptions parcelQuery = new MgFeatureQueryOptions();

            parcelQuery.SetFilter("RNAME LIKE 'SCHMITT%'");
            parcelQuery.SetSpatialFilter(parcels.GetFeatureGeometryName(), districtGeom, MgFeatureSpatialOperations.Inside);

            //Select the features
            reader = parcels.SelectFeatures(parcelQuery);
            List <string> results = new List <string>();

            try
            {
                while (reader.ReadNext())
                {
                    if (!reader.IsNull("RPROPAD"))
                    {
                        results.Add(reader.GetString("RPROPAD"));
                    }
                }
            }
            finally
            {
                reader.Close();
            }

            new ParcelQueryResultWindow(results).ShowDialog();
        }
Ejemplo n.º 12
0
        public void LoadMap(MgMapBase map)
        {
            if (map == null)
                return;

            DisposeExistingMap();
            _map = map;
            OnNewMapLoaded(map);
            var h = this.MapLoaded;
            if (h != null)
                h(this, EventArgs.Empty);
        }
Ejemplo n.º 13
0
        private void printDocument_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            MgMapViewerProvider provider  = _viewer.GetProvider();
            MgSelectionBase     selection = _viewer.GetSelection();
            MgMapBase           map       = _viewer.GetMap();
            MgPoint             pt        = map.ViewCenter;
            MgCoordinate        coord     = pt.Coordinate;
            float leftMargin = e.MarginBounds.Left;
            float topMargin  = e.MarginBounds.Top;
            float yPos       = topMargin;
            float pageHeight = e.MarginBounds.Height;

            //Write title
            var titleFont = new Font(FontFamily.GenericSansSerif, 18.0f, GraphicsUnit.Point);
            var sizeTitle = e.Graphics.MeasureString(txtTitle.Text, titleFont);

            e.Graphics.DrawString(txtTitle.Text, titleFont, Brushes.Black, new PointF(leftMargin, yPos));

            yPos += (sizeTitle.Height * 1.1f);

            var scaleFont = SystemFonts.CaptionFont;
            var scaleStr  = string.Format("{0} 1 : {1}", Strings.TextScale, _viewer.GetMap().ViewScale); //NOXLATE
            var sizeScale = e.Graphics.MeasureString(scaleStr, scaleFont);

            //Scale to fit within this page
            var imgHeight = (int)(pageHeight - (sizeTitle.Height * 1.1f) - (sizeScale.Height * 1.1f));
            var imgWidth  = e.MarginBounds.Width;

            using (var state = provider.CreateTransientState())
            {
                var tempState = new MgMapDisplayParameters(coord.X, coord.Y, map.ViewScale, imgWidth, imgHeight, (int)numDPI.Value);
                state.PushState(tempState);
                MgByteReader br = provider.RenderMap(selection, "PNG"); //NOXLATE
                using (MgReadOnlyStream stream = new MgReadOnlyStream(br))
                {
                    Image img = Image.FromStream(stream);
                    e.Graphics.DrawImage(img, leftMargin, yPos, imgWidth, imgHeight);
                    img.Dispose();
                }
            }

            yPos += imgHeight;

            //Render scale
            if (chkScale.Checked)
            {
                e.Graphics.DrawString(scaleStr, scaleFont, Brushes.Black, new PointF(leftMargin, yPos));
            }

            e.HasMorePages = false;
        }
Ejemplo n.º 14
0
        public static String MakeUniqueLayerName(MgMapBase map, String layerName, String themeName)
        {
            String desiredName = "_" + layerName + themeName; //NOXLATE
            String uniqueName  = desiredName;
            int    index       = 1;

            var layers = map.GetLayers();

            while (layers.Contains(uniqueName))
            {
                uniqueName = desiredName + index.ToString();
                index++;
            }
            return(uniqueName);
        }
Ejemplo n.º 15
0
        private void btnListLayerGroups_Click(object sender, EventArgs e)
        {
            MgMapBase              map    = _viewer.GetMap();
            MgResourceIdentifier   resId  = map.MapDefinition;
            MgLayerGroupCollection groups = map.GetLayerGroups();

            List <string> results = new List <string>();

            for (int i = 0; i < groups.GetCount(); i++)
            {
                MgLayerGroup group = groups.GetItem(i);
                results.Add(group.Name + " (" + group.LegendLabel + ")");
            }

            MessageBox.Show("Map (" + resId.ToString() + ") has " + groups.GetCount() + " layers: " + Environment.NewLine + Environment.NewLine + string.Join(Environment.NewLine, results.ToArray()));
        }
Ejemplo n.º 16
0
        public void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            MgMapBase mb = new MgMapBase();

            Assert.AreEqual("", mb.Name);
            Assert.AreEqual("", mb.SessionId);
            Assert.IsNull(mb.MapDefinition);
            Assert.AreEqual("", mb.MapSRS);
            Assert.IsNull(mb.MapExtent);
            Assert.IsNull(mb.ViewCenter);
            Assert.AreEqual(1.0, mb.ViewScale);
            Assert.IsNull(mb.DataExtent);
            Assert.AreEqual(96, mb.DisplayDpi);
            Assert.AreEqual(0, mb.DisplayWidth);
            Assert.AreEqual(0, mb.DisplayHeight);
            Assert.AreEqual(0, mb.FiniteDisplayScaleCount);
        }
Ejemplo n.º 17
0
        public void LoadMap(MgMapBase map)
        {
            if (map == null)
            {
                return;
            }

            DisposeExistingMap();
            _map = map;
            OnNewMapLoaded(map);
            var h = this.MapLoaded;

            if (h != null)
            {
                h(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 18
0
        public override void Execute(IPlatformFactory factory, ITestLogger logger)
        {
            try
            {
                MgResourceService resSvc = (MgResourceService)factory.CreateService(MgServiceType.ResourceService);

                var root = "../../TestData/TileService/";
                LoadResource(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", root + "UT_RoadCenterLines.fs");
                LoadResourceData(resSvc, "Library://UnitTests/Data/RoadCenterLines.FeatureSource", "UT_RoadCenterLines.sdf", MgResourceDataType.File, root + "UT_RoadCenterLines.sdf");
                LoadResource(resSvc, "Library://UnitTests/Layers/RoadCenterLines.LayerDefinition", root + "UT_RoadCenterLines.ldf");

                LoadResource(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", root + "UT_VotingDistricts.fs");
                LoadResourceData(resSvc, "Library://UnitTests/Data/VotingDistricts.FeatureSource", "UT_VotingDistricts.sdf", MgResourceDataType.File, root + "UT_VotingDistricts.sdf");
                LoadResource(resSvc, "Library://UnitTests/Layers/VotingDistricts.LayerDefinition", root + "UT_VotingDistricts.ldf");

                LoadResource(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", root + "UT_Parcels.fs");
                LoadResourceData(resSvc, "Library://UnitTests/Data/Parcels.FeatureSource", "UT_Parcels.sdf", MgResourceDataType.File, root + "UT_Parcels.sdf");
                LoadResource(resSvc, "Library://UnitTests/Layers/Parcels.LayerDefinition", root + "UT_Parcels.ldf");

                byte[]               tsd        = Properties.Resources.UT_XYZ;
                MgByteSource         sourceTSD  = new MgByteSource(tsd, tsd.Length);
                MgByteReader         contentTSD = sourceTSD.GetReader();
                MgResourceIdentifier resTSD     = new MgResourceIdentifier("Library://UnitTests/TileSets/Test.TileSetDefinition");

                resSvc.SetResource(resTSD, contentTSD, null);

                string mdf = Encoding.UTF8.GetString(Properties.Resources.UT_BaseMap);
                mdf = string.Format(mdf, resTSD.ToString());
                byte[]               mdfBytes   = Encoding.UTF8.GetBytes(mdf);
                MgByteSource         sourceMDF  = new MgByteSource(mdfBytes, mdfBytes.Length);
                MgByteReader         contentMDF = sourceMDF.GetReader();
                MgResourceIdentifier resMDF     = new MgResourceIdentifier("Library://UnitTests/Maps/LinkedTileSet.MapDefinition");

                resSvc.SetResource(resMDF, contentMDF, null);

                //This should throw because making a MgMap from a Map Defintion that links to a XYZ tile set
                //is not supported
                MgMapBase map = factory.CreateMap(resMDF);

                Assert.Fail("Expected MgUnsupportedTileProviderException to be thrown");
            }
            catch (MgUnsupportedTileProviderException)
            {
            }
        }
Ejemplo n.º 19
0
        private void btnRefreshLayersOnMap_Click(object sender, EventArgs e)
        {
            lstLayersOnMap.Clear();
            var               mgr    = GetRedlineManager();
            MgMapBase         map    = _component.Viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();

            foreach (var layer in mgr.GetAvailableLayers())
            {
                //Omit those not on the map
                if (layers.IndexOf(layer.SystemName) < 0)
                {
                    continue;
                }

                AddRedlineLayerOnMap(layer);
            }
        }
Ejemplo n.º 20
0
        public DigitizingAndRedlining(IMapViewer viewer)
        {
            InitializeComponent();
            _viewer    = viewer;
            _geomFact  = new MgGeometryFactory();
            _wktRW     = new MgWktReaderWriter();
            _agfRW     = new MgAgfReaderWriter();
            this.Title = "Digitizing and Redlining";
            _viewer.PropertyChanged += OnViewerPropertyChanged;
            MgMapBase         map    = _viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();

            if (layers.IndexOf("Redline") >= 0)
            {
                _redlineLayer = (MgdLayer)layers.GetItem("Redline");
            }
            CheckDigitizingState();
        }
Ejemplo n.º 21
0
        public static string GetMapSrs(MgMapBase map)
        {
            try
            {
                String srs = map.GetMapSRS();
                if (srs != string.Empty)
                {
                    return(srs);
                }
            }
            catch (MgException)
            {
            }

            //No SRS, set to ArbitrayXY meters
            //
            return("LOCALCS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]"); //NOXLATE
        }
Ejemplo n.º 22
0
        public InteractingWithLayers(IMapViewer viewer)
        {
            InitializeComponent();
            _viewer    = viewer;
            this.Title = "Interacting With Layers";

            MgMapBase         map    = _viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();

            if (layers.IndexOf("Roads") >= 0 && layers.IndexOf("Streets") < 0)
            {
                btnRenameRoadsLayer.Text = "Rename Roads Layer to Streets";
            }
            else if (layers.IndexOf("Roads") < 0 && layers.IndexOf("Streets") >= 0)
            {
                btnRenameRoadsLayer.Text = "Rename Streets Layer to Roads";
            }
        }
Ejemplo n.º 23
0
        protected void CreateMapFromResource(int paramSetId)
        {
            if (_map != null)
            {
                return;
            }

            _unitTestVm.Execute("Select ParamValue from Params WHERE ParamSet={0} AND ParamName=\"MAPDEFINITION\"", paramSetId);
            string mapName = _unitTestVm.GetString("ParamValue");

            if (string.IsNullOrEmpty(mapName))
            {
                mapName = "Library://maplayertest/World.MapDefinition";
            }

            MgResourceIdentifier mdfId = new MgResourceIdentifier(mapName);

            _map = _creator.CreateMap(mdfId);
        }
Ejemplo n.º 24
0
        internal void UpdateRedlineText(string text, int[] ids)
        {
            MgMapBase         map          = _viewer.GetMap();
            MgLayerCollection layers       = map.GetLayers();
            MgLayerBase       redlineLayer = layers.GetItem(_layer.SystemName);

            //HACK: Workaround FeatId leaky abstraction in SHP provider
            MgClassDefinition cls = redlineLayer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
            MgPropertyDefinition           idProp  = idProps.GetItem(0);

            redlineLayer.ForceRefresh();

            //This lib doesn't reference mg-desktop so the convenience APIs aren't available to us
            //Gotta go the old verbose route
            List <string> filters = new List <string>();

            foreach (int id in ids)
            {
                filters.Add(idProp.Name + " = " + id);
            }
            string updateFilter = string.Join(" OR ", filters.ToArray());
            MgFeatureCommandCollection commands     = new MgFeatureCommandCollection();
            MgPropertyCollection       updateValues = new MgPropertyCollection();
            MgStringProperty           updateProp   = new MgStringProperty(RedlineSchemaFactory.TEXT_NAME, text);

            updateValues.Add(updateProp);

            MgUpdateFeatures update = new MgUpdateFeatures(redlineLayer.FeatureClassName, updateValues, updateFilter);

            commands.Add(update);

            MgPropertyCollection result       = redlineLayer.UpdateFeatures(commands);
            MgInt32Property      updateResult = result.GetItem(0) as MgInt32Property;
            MgStringProperty     errorResult  = result.GetItem(0) as MgStringProperty;

            if (errorResult != null)
            {
                throw new Exception(errorResult.GetValue());
            }
            _viewer.RefreshMap();
        }
Ejemplo n.º 25
0
        private void btnRenameRoadsLayer_Click(object sender, EventArgs e)
        {
            MgMapBase         map    = _viewer.GetMap();
            MgLayerCollection layers = map.GetLayers();

            bool bRefresh = false;

            if (layers.IndexOf("Roads") >= 0)
            {
                MgLayerBase roads = layers.GetItem("Roads");
                roads.Name        = "Streets";
                roads.LegendLabel = "Streets";

                MessageBox.Show("Layer (Roads) has been changed to (Streets)");
                btnRenameRoadsLayer.Text = "Rename Streets Layer to Roads";
                bRefresh = true;
            }
            else if (layers.IndexOf("Streets") >= 0)
            {
                MgLayerBase streets = layers.GetItem("Streets");
                streets.Name        = "Roads";
                streets.LegendLabel = "Roads";

                MessageBox.Show("Layer (Streets) has been changed to (Roads)");
                btnRenameRoadsLayer.Text = "Rename Roads Layer to Streets";
                bRefresh = true;
            }

            if (bRefresh)
            {
                _viewer.RefreshMap();
                IMapLegend legend = Shell.Instance.Legend;
                if (legend != null)
                {
                    legend.RefreshLegend();
                }
            }
        }
Ejemplo n.º 26
0
        public IEnumerable <RedlineObject> GetAllFeatures()
        {
            MgMapBase         map          = _viewer.GetMap();
            MgLayerCollection layers       = map.GetLayers();
            MgLayerBase       redlineLayer = layers.GetItem(_layer.SystemName);

            MgResourceIdentifier resId  = new MgResourceIdentifier(redlineLayer.GetFeatureSourceId());
            MgFeatureReader      reader = null;

            try
            {
                reader = _featSvc.SelectFeatures(resId, RedlineSchemaFactory.CLASS_NAME, null);

                //HACK: Another leaky abstraction. SHP will always choose FeatId, so once again
                //use the class definition to determine the identity property name
                MgClassDefinition cls = reader.GetClassDefinition();
                MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
                MgPropertyDefinition           keyProp = idProps.GetItem(0);
                string idName = keyProp.GetName();

                while (reader.ReadNext())
                {
                    int    id   = reader.GetInt32(idName);
                    string text = reader.IsNull(RedlineSchemaFactory.TEXT_NAME) ? string.Empty : reader.GetString(RedlineSchemaFactory.TEXT_NAME);

                    yield return(new RedlineObject(id, text));
                }
            }
            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
        }
Ejemplo n.º 27
0
        internal void DeleteRedlines(int[] ids)
        {
            MgMapBase         map          = _viewer.GetMap();
            MgLayerCollection layers       = map.GetLayers();
            MgLayerBase       redlineLayer = layers.GetItem(_layer.SystemName);

            //HACK: Workaround FeatId leaky abstraction in SHP provider
            MgClassDefinition cls = redlineLayer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
            MgPropertyDefinition           idProp  = idProps.GetItem(0);

            redlineLayer.ForceRefresh();

            //This lib doesn't reference mg-desktop so the convenience APIs aren't available to us
            //Gotta go the old verbose route
            List <string> filters = new List <string>();

            foreach (int id in ids)
            {
                filters.Add(idProp.Name + " = " + id);
            }
            string deleteFilter = string.Join(" OR ", filters.ToArray());
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();

            MgDeleteFeatures delete = new MgDeleteFeatures(redlineLayer.FeatureClassName, deleteFilter);

            commands.Add(delete);

            MgPropertyCollection result       = redlineLayer.UpdateFeatures(commands);
            MgInt32Property      deleteResult = result.GetItem(0) as MgInt32Property;

            if (deleteResult != null && deleteResult.GetValue() > 0)
            {
                _viewer.RefreshMap();
            }
        }
Ejemplo n.º 28
0
 public abstract MgTransientMapState CreateTransientState(MgMapBase map);
Ejemplo n.º 29
0
 protected MgMapViewerProvider(MgMapBase map)
 {
     SubInit();
     LoadMap(map);
 }
Ejemplo n.º 30
0
        private void btnCreateBuffer_Click(object sender, EventArgs e)
        {
            MgSelectionBase           selection = _viewer.GetSelection();
            MgReadOnlyLayerCollection layers    = selection.GetLayers();

            if (layers == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }
            MgLayerBase parcels = null;

            for (int i = 0; i < layers.GetCount(); i++)
            {
                MgLayerBase layer = layers.GetItem(i);
                if (layer.Name == "Parcels")
                {
                    parcels = layer;
                    break;
                }
            }
            if (parcels == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }

            int bufferRingSize  = 100; // measured in metres
            int bufferRingCount = 5;

            // Set up some objects for coordinate conversion
            MgMapBase           map             = _viewer.GetMap();
            MgLayerCollection   mapLayers       = map.GetLayers();
            MgMapViewerProvider provider        = _viewer.GetProvider();
            MgResourceService   resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            //Casting to MgdFeatureService because we want to use convenience APIs
            MgFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService);

            String                    mapWktSrs               = map.GetMapSRS();
            MgAgfReaderWriter         agfReaderWriter         = new MgAgfReaderWriter();
            MgWktReaderWriter         wktReaderWriter         = new MgWktReaderWriter();
            MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
            MgCoordinateSystem        srs        = coordinateSystemFactory.Create(mapWktSrs);
            MgMeasure                 srsMeasure = srs.GetMeasure();
            string                    sessionId  = Guid.NewGuid().ToString();

            BufferHelper helper = new BufferHelper();

            // Check for a buffer layer. If it exists, delete
            // the current features.
            // If it does not exist, create a feature source and
            // a layer to hold the buffer.

            MgdLayer bufferLayer = null;
            int      layerIndex  = mapLayers.IndexOf("Buffer");

            if (layerIndex < 0)
            {
                // The layer does not exist and must be created.

                MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource");
                helper.CreateBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId);
                bufferLayer = helper.CreateBufferLayer(resourceService, bufferFeatureResId, sessionId);
                mapLayers.Insert(0, bufferLayer);
            }
            else
            {
                bufferLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex);
                bufferLayer.DeleteFeatures("ID like '%'");
            }

            // Get the selected features from the MgSelection object
            MgFeatureReader featureReader = selection.GetSelectedFeatures(parcels, parcels.GetFeatureClassName(), false);

            // Process each item in the MgFeatureReader. Get the
            // geometries from all the selected features and
            // merge them into a single geometry.

            MgGeometryCollection inputGeometries = new MgGeometryCollection();

            while (featureReader.ReadNext())
            {
                MgByteReader featureGeometryData = featureReader.GetGeometry(parcels.GetFeatureGeometryName());
                MgGeometry   featureGeometry     = agfReaderWriter.Read(featureGeometryData);

                inputGeometries.Add(featureGeometry);
            }

            MgGeometryFactory geometryFactory  = new MgGeometryFactory();
            MgGeometry        mergedGeometries = geometryFactory.CreateMultiGeometry(inputGeometries);

            // Add buffer features to the temporary feature source.
            // Create multiple concentric buffers to show area.
            // If the stylization for the layer draws the features
            // partially transparent, the concentric rings will be
            // progressively darker towards the center.
            // The stylization is set in the layer template file, which
            // is used in function CreateBufferLayer().

            for (int bufferRing = 0; bufferRing < bufferRingCount; bufferRing++)
            {
                double     bufferDist     = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize * (bufferRing + 1));
                MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure);

                MgPropertyCollection properties = new MgPropertyCollection();
                properties.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry)));

                MgFeatureReader fr = bufferLayer.InsertFeatures(properties);
                fr.Close();
            }

            bufferLayer.SetVisible(true);
            bufferLayer.ForceRefresh();
            bufferLayer.SetDisplayInLegend(true);

            MessageBox.Show("Buffer created");
            _viewer.RefreshMap();
            IMapLegend legend = Shell.Instance.Legend;

            if (legend != null)
            {
                legend.RefreshLegend();
            }
        }
Ejemplo n.º 31
0
 protected virtual void OnNewMapLoaded(MgMapBase map) { }
Ejemplo n.º 32
0
        public void LoadMap(MgMapBase map)
        {
            if (_provider == null)
                throw new InvalidOperationException(Strings.ErrorViewerNotInitialized);

            _provider.LoadMap(map);
        }
Ejemplo n.º 33
0
        private void btnFindFeaturesInBuffer_Click(object sender, EventArgs e)
        {
            MgSelectionBase           selection      = _viewer.GetSelection();
            MgReadOnlyLayerCollection selectedLayers = selection.GetLayers();

            if (selectedLayers == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }
            MgLayerBase parcels = null;

            for (int i = 0; i < selectedLayers.GetCount(); i++)
            {
                MgLayerBase layer = selectedLayers.GetItem(i);
                if (layer.Name == "Parcels")
                {
                    parcels = layer;
                    break;
                }
            }
            if (parcels == null)
            {
                MessageBox.Show("Select a parcel");
                return;
            }

            int bufferRingSize = 500; // measured in metres

            // Set up some objects for coordinate conversion

            MgMapBase           map             = _viewer.GetMap();
            MgLayerCollection   mapLayers       = map.GetLayers();
            MgMapViewerProvider provider        = _viewer.GetProvider();
            MgResourceService   resourceService = (MgResourceService)provider.CreateService(MgServiceType.ResourceService);
            //Casting to MgdFeatureService because we want to use convenience APIs
            MgFeatureService featureService = (MgdFeatureService)provider.CreateService(MgServiceType.FeatureService);
            string           sessionId      = Guid.NewGuid().ToString();

            String                    mapWktSrs               = map.GetMapSRS();
            MgAgfReaderWriter         agfReaderWriter         = new MgAgfReaderWriter();
            MgWktReaderWriter         wktReaderWriter         = new MgWktReaderWriter();
            MgCoordinateSystemFactory coordinateSystemFactory = new MgCoordinateSystemFactory();
            MgCoordinateSystem        srs        = coordinateSystemFactory.Create(mapWktSrs);
            MgMeasure                 srsMeasure = srs.GetMeasure();

            // Check for a buffer layer. If it exists, delete
            // the current features.
            // If it does not exist, create a feature source and
            // a layer to hold the buffer.

            BufferHelper helper      = new BufferHelper();
            MgdLayer     bufferLayer = null;
            int          layerIndex  = map.GetLayers().IndexOf("Buffer");

            if (layerIndex < 0)
            {
                // The layer does not exist and must be created.

                MgResourceIdentifier bufferFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//Buffer.FeatureSource");
                helper.CreateBufferFeatureSource(featureService, mapWktSrs, bufferFeatureResId);
                bufferLayer = helper.CreateBufferLayer(resourceService, bufferFeatureResId, sessionId);
                map.GetLayers().Insert(0, bufferLayer);
            }
            else
            {
                bufferLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex);
                bufferLayer.DeleteFeatures("ID like '%'");
            }

            // Check for a parcel marker layer. If it exists, delete
            // the current features.
            // If it does not exist, create a feature source and
            // a layer to hold the parcel markers.

            MgdLayer parcelMarkerLayer = null;

            layerIndex = map.GetLayers().IndexOf("ParcelMarker");
            if (layerIndex < 0)
            {
                MgResourceIdentifier parcelFeatureResId = new MgResourceIdentifier("Session:" + sessionId + "//ParcelMarker.FeatureSource");
                helper.CreateParcelMarkerFeatureSource(featureService, mapWktSrs, parcelFeatureResId);
                parcelMarkerLayer = helper.CreateParcelMarkerLayer(resourceService, parcelFeatureResId, sessionId);
                map.GetLayers().Insert(0, parcelMarkerLayer);
            }
            else
            {
                parcelMarkerLayer = (MgdLayer)map.GetLayers().GetItem(layerIndex);
                parcelMarkerLayer.DeleteFeatures("ID like '%'");
            }

            // Check each layer in the selection.

            for (int i = 0; i < selectedLayers.GetCount(); i++)
            {
                // Only check selected features in the Parcels layer.

                MgdLayer layer = (MgdLayer)selectedLayers.GetItem(i);

                if (layer.GetName() == "Parcels")
                {
                    string geomName = layer.GetFeatureGeometryName();
                    System.Diagnostics.Trace.TraceInformation("Marking all parcels inside the buffer that are of type 'MFG'");

                    MgFeatureReader featureReader = selection.GetSelectedFeatures(layer, layer.GetFeatureClassName(), false);


                    // Process each item in the MgFeatureReader. Get the
                    // geometries from all the selected features and
                    // merge them into a single geometry.

                    MgGeometryCollection inputGeometries = new MgGeometryCollection();
                    while (featureReader.ReadNext())
                    {
                        MgByteReader featureGeometryData = featureReader.GetGeometry(geomName);
                        MgGeometry   featureGeometry     = agfReaderWriter.Read(featureGeometryData);

                        inputGeometries.Add(featureGeometry);
                    }

                    MgGeometryFactory geometryFactory  = new MgGeometryFactory();
                    MgGeometry        mergedGeometries = geometryFactory.CreateMultiGeometry(inputGeometries);

                    // Create a buffer from the merged geometries

                    double     bufferDist     = srs.ConvertMetersToCoordinateSystemUnits(bufferRingSize);
                    MgGeometry bufferGeometry = mergedGeometries.Buffer(bufferDist, srsMeasure);

                    // Create a filter to select parcels within the buffer. Combine
                    // a basic filter and a spatial filter to select all parcels
                    // within the buffer that are of type "MFG".

                    MgFeatureQueryOptions queryOptions = new MgFeatureQueryOptions();
                    queryOptions.SetFilter("RTYPE = 'MFG'");
                    queryOptions.SetSpatialFilter(geomName, bufferGeometry, MgFeatureSpatialOperations.Inside);

                    featureReader = layer.SelectFeatures(queryOptions);

                    // Get the features from the feature source,
                    // determine the centroid of each selected feature, and
                    // add a point to the ParcelMarker layer to mark the
                    // centroid.
                    // Collect all the points into an MgFeatureCommandCollection,
                    // so they can all be added in one operation.

                    MgFeatureCommandCollection parcelMarkerCommands = new MgFeatureCommandCollection();
                    int inserted = 0;
                    while (featureReader.ReadNext())
                    {
                        MgByteReader byteReader = featureReader.GetGeometry(geomName);
                        MgGeometry   geometry   = agfReaderWriter.Read(byteReader);
                        MgPoint      point      = geometry.GetCentroid();

                        // Create an insert command for this parcel.
                        MgPropertyCollection properties = new MgPropertyCollection();
                        properties.Add(new MgGeometryProperty("ParcelLocation", agfReaderWriter.Write(point)));
                        //parcelMarkerCommands.Add(new MgInsertFeatures("ParcelMarkerClass", properties));
                        MgFeatureReader fr = parcelMarkerLayer.InsertFeatures(properties);
                        fr.Close();
                        inserted++;
                    }
                    featureReader.Close();

                    if (inserted == 0)
                    {
                        MessageBox.Show("No parcels within the buffer area match.");
                        return;
                    }

                    // Create a feature in the buffer feature source to show the area covered by the buffer.

                    MgPropertyCollection props = new MgPropertyCollection();
                    props.Add(new MgGeometryProperty("BufferGeometry", agfReaderWriter.Write(bufferGeometry)));
                    bufferLayer.InsertFeatures(props);

                    // Ensure that the buffer layer is visible and in the legend.

                    bufferLayer.SetVisible(true);
                    bufferLayer.ForceRefresh();
                    bufferLayer.SetDisplayInLegend(true);
                    parcelMarkerLayer.SetVisible(true);
                    parcelMarkerLayer.ForceRefresh();

                    MessageBox.Show("Done");
                    _viewer.RefreshMap();
                    IMapLegend legend = Shell.Instance.Legend;
                    if (legend != null)
                    {
                        legend.RefreshLegend();
                    }
                }
            }
        }
Ejemplo n.º 34
0
 public void MapBase()
 {
     MgMapBase mb = new MgMapBase();
     Assert.AreEqual("", mb.Name);
     Assert.AreEqual("", mb.SessionId);
     Assert.IsNull(mb.MapDefinition);
     Assert.AreEqual("", mb.MapSRS);
     Assert.IsNull(mb.MapExtent);
     Assert.IsNull(mb.ViewCenter);
     Assert.AreEqual(1.0, mb.ViewScale);
     Assert.IsNull(mb.DataExtent);
     Assert.AreEqual(96, mb.DisplayDpi);
     Assert.AreEqual(0, mb.DisplayWidth);
     Assert.AreEqual(0, mb.DisplayHeight);
     Assert.AreEqual(0, mb.FiniteDisplayScaleCount);
 }
Ejemplo n.º 35
0
Archivo: Util.cs Proyecto: kanbang/Colt
        public static String MakeUniqueLayerName(MgMapBase map, String layerName, String themeName)
        {
            String desiredName = "_" + layerName + themeName; //NOXLATE
            String uniqueName = desiredName;
            int index = 1;

            var layers = map.GetLayers();
            while (layers.Contains(uniqueName))
            {
                uniqueName = desiredName + index.ToString();
                index++;
            }
            return uniqueName;
        }
Ejemplo n.º 36
0
 protected MgMapViewerProvider(MgMapBase map)
 {
     SubInit();
     LoadMap(map);
 }
Ejemplo n.º 37
0
 protected override void OnNewMapLoaded(MgMapBase map)
 {
     _implMap = (MgdMap)map;
 }
Ejemplo n.º 38
0
 public abstract MgTransientMapState CreateTransientState(MgMapBase map);
Ejemplo n.º 39
0
 protected virtual void OnNewMapLoaded(MgMapBase map)
 {
 }
Ejemplo n.º 40
0
 internal RedlineLayer[] GetAvailableLayers(MgMapBase map)
 {
     var fsId = GetRegistryFeatureSource();
     MgLayerCollection mapLayers = map.GetLayers();
     List<RedlineLayer> layers = new List<RedlineLayer>();
     MgFeatureReader reader = null;
     try
     {
         reader = _featSvc.SelectFeatures(fsId, "Default:MarkupRegistry", null);
         while (reader.ReadNext())
         {
             layers.Add(new RedlineLayer(reader.GetString("Name"),
                                         reader.GetString("ResourceId"),
                                         reader.GetString("LayerDefinition"),
                                         reader.GetInt32("GeometryTypes"),
                                         (RedlineStylizationType)reader.GetInt32("StyleType")));
         }
     }
     finally
     {
         if (reader != null)
             reader.Close();
     }
     return layers.ToArray();
 }
Ejemplo n.º 41
0
        private void InsertRedlineGeometry(string text, MgGeometry geom, RedlineAction onRedlineAdded)
        {
            MgPropertyCollection feature  = new MgPropertyCollection();
            MgByteReader         agf      = _agfRW.Write(geom);
            MgGeometryProperty   geomProp = new MgGeometryProperty(RedlineSchemaFactory.GEOM_NAME, agf);

            feature.Add(geomProp);
            MgStringProperty strProp = new MgStringProperty(RedlineSchemaFactory.TEXT_NAME, text);

            feature.Add(strProp);

            MgMapBase         map                  = _viewer.GetMap();
            MgLayerCollection layers               = map.GetLayers();
            MgLayerBase       redlineLayer         = layers.GetItem(_layer.SystemName);
            MgClassDefinition cls                  = redlineLayer.GetClassDefinition();
            MgPropertyDefinitionCollection idProps = cls.GetIdentityProperties();
            MgPropertyDefinition           idProp  = idProps.GetItem(0);

            redlineLayer.ForceRefresh();

            //This lib doesn't reference mg-desktop so the convenience APIs aren't available to us
            //Gotta go the old verbose route
            MgFeatureCommandCollection commands = new MgFeatureCommandCollection();

            MgInsertFeatures insert = new MgInsertFeatures(redlineLayer.FeatureClassName, feature);

            commands.Add(insert);

            MgPropertyCollection result = redlineLayer.UpdateFeatures(commands);
            //Insert result is a MgFeatureProperty containing an MgFeatureReader
            MgFeatureProperty insertResult = result.GetItem(0) as MgFeatureProperty;
            MgStringProperty  errorResult  = result.GetItem(0) as MgStringProperty;

            if (insertResult != null)
            {
                var reader   = insertResult.GetValue();
                int inserted = 0;
                int?id       = null;
                try
                {
                    if (reader.ReadNext())
                    {
                        inserted++;
                        id = reader.GetInt32(idProp.Name);
                    }
                }
                catch (MgException ex)
                {
                    ex.Dispose();
                }
                finally
                {
                    reader.Close();
                }
                if (inserted > 0)
                {
                    _viewer.RefreshMap();
                    onRedlineAdded(id, text);
                }
            }
            else if (errorResult != null)
            {
                throw new Exception(errorResult.GetValue());
            }
        }
Ejemplo n.º 42
0
Archivo: Util.cs Proyecto: kanbang/Colt
        public static string GetMapSrs(MgMapBase map)
        {
            try
            {
                String srs = map.GetMapSRS();
                if (srs != string.Empty)
                    return srs;
            }
            catch (MgException)
            {
            }

            //No SRS, set to ArbitrayXY meters
            //
            return "LOCALCS[\"Non-Earth (Meter)\",LOCAL_DATUM[\"Local Datum\",0],UNIT[\"Meter\", 1],AXIS[\"X\",EAST],AXIS[\"Y\",NORTH]]"; //NOXLATE
        }
Ejemplo n.º 43
0
 public override MgTransientMapState CreateTransientState(MgMapBase map)
 {
     return new MgdTransientMapState((MgdMap)map);
 }
Ejemplo n.º 44
0
        private void OnMapSetOnProvider(object sender, EventArgs e)
        {
            _hasTiledLayers = null;
            _map = _provider.GetMap();
            _mapCs = _provider.GetMapCoordinateSystem();
            _mapMeasure = _mapCs.GetMeasure();
            var bgColor = _map.GetBackgroundColor();
            if (bgColor.Length == 8 || bgColor.Length == 6)
            {
                _mapBgColor = ColorTranslator.FromHtml("#" + bgColor); //NOXLATE
                this.BackColor = _mapBgColor;
            }
            _provider.SetDisplaySize(this.Width, this.Height);
            _selection = _provider.CreateSelectionForMap();

            var env = _map.GetMapExtent();
            var ll = env.LowerLeftCoordinate;
            var ur = env.UpperRightCoordinate;

            _extX1 = _orgX1 = ll.X;
            _extY2 = _orgY2 = ll.Y;
            _extX2 = _orgX2 = ur.X;
            _extY1 = _orgY1 = ur.Y;

            if ((_orgX1 - _orgX2) == 0 || (_orgY1 - _orgY2) == 0)
            {
                _extX1 = _orgX1 = -.1;
                _extY2 = _orgX2 = .1;
                _extX2 = _orgY1 = -.1;
                _extY1 = _orgY2 = .1;
            }

            if (this.ConvertTiledGroupsToNonTiled)
            {
                var groups = _map.GetLayerGroups();
                for (int i = 0; i < groups.GetCount(); i++)
                {
                    var group = groups.GetItem(i);
                    _provider.MakeGroupNormal(group);
                }
            }

#if VIEWER_DEBUG
            CreateDebugFeatureSource();
#endif
            this.Focus();

            //Reset history stack
            _viewHistory.Clear();
            OnPropertyChanged("ViewHistory"); //NOXLATE
            _viewHistoryIndex = -1;
            OnPropertyChanged("ViewHistoryIndex"); //NOXLATE
            
            var handler = this.MapLoaded;
            if (handler != null)
                handler(this, EventArgs.Empty);

            InitialMapView();
        }