/// <summary> /// Reprojects all layers in the map frame so that they use the new /// projection ESRI string /// </summary> /// <param name="mapFrame">The map frame that contains all layers that should be reprojected</param> /// <param name="newProjEsriString">The ESRI WKT string of the new projection</param> public static void ReprojectMapFrame(IMapFrame mapFrame, string newProjEsriString) { //parse the projection ProjectionInfo newProjection = ProjectionInfo.FromEsriString(newProjEsriString); foreach (IMapLayer layer in mapFrame.GetAllLayers()) { if (layer.DataSet.CanReproject) { layer.DataSet.Reproject(newProjection); } } foreach (IMapGroup grp in mapFrame.GetAllGroups()) { grp.Projection = ProjectionInfo.FromEsriString(newProjEsriString); } mapFrame.Projection = newProjection; var parent = mapFrame.Parent as IMap; if (parent != null) { // this need to fire Map.ProjectionChanged event parent.Projection = newProjection; } }
/// <summary> /// Reprojects all layers in the map frame so that they use new projection /// </summary> /// <param name="mapFrame">The map frame that contains all layers that should be reprojected</param> /// <param name="newProjection">New projection</param> /// <param name="onCantReproject">Callback when layer can't be reprojected. Maybe null.</param> public static void ReprojectMapFrame(this IMapFrame mapFrame, ProjectionInfo newProjection, Action <ILayer> onCantReproject = null) { if (mapFrame == null) { throw new ArgumentNullException("mapFrame"); } if (newProjection == null) { throw new ArgumentNullException("newProjection"); } // assign rotation to projection transform depending on mapframe angle if (mapFrame.Angle != 0) { newProjection.Transform.Rotated = true; newProjection.Transform.Angle = mapFrame.Angle; } else { newProjection.Transform.Rotated = false; newProjection.Transform.Angle = 0; } foreach (var layer in mapFrame.GetAllLayers()) { if (layer.CanReproject) { layer.Reproject(newProjection); } else { onCantReproject?.Invoke(layer); } } foreach (var grp in mapFrame.GetAllGroups()) { grp.Projection = newProjection; } mapFrame.Projection = newProjection; var parent = mapFrame.Parent as IMap; if (parent != null) { // this need to fire Map.ProjectionChanged event parent.Projection = newProjection; } }
/// <summary> /// Reprojects all layers in the map frame so that they use new projection /// </summary> /// <param name="mapFrame">The map frame that contains all layers that should be reprojected</param> /// <param name="newProjection">New projection</param> /// <param name="onCantReproject">Callback when layer can't be reprojected. Maybe null.</param> public static void ReprojectMapFrame(this IMapFrame mapFrame, ProjectionInfo newProjection, Action <ILayer> onCantReproject = null) { if (mapFrame == null) { throw new ArgumentNullException("mapFrame"); } if (newProjection == null) { throw new ArgumentNullException("newProjection"); } foreach (var layer in mapFrame.GetAllLayers()) { if (layer.CanReproject) { layer.Reproject(newProjection); } else { if (onCantReproject != null) { onCantReproject(layer); } } } foreach (var grp in mapFrame.GetAllGroups()) { grp.Projection = newProjection; } mapFrame.Projection = newProjection; var parent = mapFrame.Parent as IMap; if (parent != null) { // this need to fire Map.ProjectionChanged event parent.Projection = newProjection; } }
/// <summary> /// Reprojects all layers in the map frame so that they use new projection. /// </summary> /// <param name="mapFrame">The map frame that contains all layers that should be reprojected.</param> /// <param name="newProjection">New projection.</param> /// <param name="onCantReproject">Callback when layer can't be reprojected. Maybe null.</param> public static void ReprojectMapFrame(this IMapFrame mapFrame, ProjectionInfo newProjection, Action <ILayer> onCantReproject = null) { if (mapFrame == null) { throw new ArgumentNullException(nameof(mapFrame)); } if (newProjection == null) { throw new ArgumentNullException(nameof(newProjection)); } foreach (var layer in mapFrame.GetAllLayers()) { if (layer.CanReproject) { layer.Reproject(newProjection); } else { onCantReproject?.Invoke(layer); } } foreach (var grp in mapFrame.GetAllGroups()) { grp.Projection = newProjection; } mapFrame.Projection = newProjection; if (mapFrame.Parent is IMap parent) { // this is needed to fire the Map.ProjectionChanged event parent.Projection = newProjection; } }