示例#1
0
        private static void Reproject()
        {
            var result = System.Windows.Forms.MessageBox.Show("Warning! This will modify the internal projection information of your layer. This should only be done if the wrong projection information was selected when initially loading the layer.\r\n\r\nTo change the map's display projection, please use the Map Projection button on the Home tab of the ribbon bar.", "Warning", System.Windows.Forms.MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Warning);

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                if (GisEditor.LayerListManager.SelectedLayerListItem == null)
                {
                    return;
                }
                FeatureLayer layer = GisEditor.LayerListManager.SelectedLayerListItem.ConcreteObject as FeatureLayer;

                if (layer != null)
                {
                    bool overSized = IsLayerOverSized(layer);
                    if (overSized)
                    {
                        string reprojectShapeFileNotification = "Applying a projection for this layer may affect performance. Please use the \"Reprojection Wizard\" in the \"Tools\" tab to reproject the ShapeFile to gain better performance.";
                        System.Windows.Forms.MessageBox.Show(reprojectShapeFileNotification, "Info", System.Windows.Forms.MessageBoxButtons.OK);
                    }

                    string initProj4String = GetActiveLayersProj4ProjectionParameter();
                    var    description     = GisEditor.LanguageManager.GetStringResource("SelectAProjectionForSingleLayerDescription");

                    ProjectionWindow proj4Window = new ProjectionWindow(initProj4String, description, "");
                    if (proj4Window.ShowDialog().GetValueOrDefault())
                    {
                        if (!string.IsNullOrEmpty(proj4Window.Proj4ProjectionParameters))
                        {
                            var projection = new Proj4Projection(proj4Window.Proj4ProjectionParameters, GisEditor.ActiveMap.DisplayProjectionParameters);
                            projection.SyncProjectionParametersString();
                            projection.Open();
                            layer.FeatureSource.Projection = projection;
                            ClearCache(layer);
                            GisEditor.ActiveMap.Refresh();
                        }
                    }
                }
            }
        }
示例#2
0
        private void SetInternalProjections(IEnumerable <FeatureLayer> featureLayers)
        {
            Collection <FeatureLayer> undefinedProjectionLayers = new Collection <FeatureLayer>();

            foreach (var featureLayer in featureLayers)
            {
                Proj4Projection proj4 = featureLayer.FeatureSource.Projection as Proj4Projection;
                if (proj4 == null ||
                    string.IsNullOrEmpty(proj4.InternalProjectionParametersString) ||
                    string.IsNullOrEmpty(proj4.ExternalProjectionParametersString))
                {
                    proj4 = new Proj4Projection();
                    string internalProj4 = GetInternalProj4ProjectionParameters(featureLayer);
                    if (string.IsNullOrEmpty(internalProj4))
                    {
                        if (IsDecimalDegree(featureLayer))
                        {
                            proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
                        }
                        else
                        {
                            undefinedProjectionLayers.Add(featureLayer);
                        }
                    }
                    else
                    {
                        proj4.InternalProjectionParametersString = internalProj4;
                    }

                    proj4.SyncProjectionParametersString();
                    featureLayer.FeatureSource.Projection = proj4;
                }
            }

            if (undefinedProjectionLayers.Count > 0)
            {
                bool   canceled      = false;
                bool   applyForAll   = false;
                string internalProj4 = string.Empty;
                foreach (var featureLayer in undefinedProjectionLayers)
                {
                    if (applyForAll && !string.IsNullOrEmpty(internalProj4))
                    {
                        SaveInternalProj4ProjectionParameters(featureLayer, internalProj4);
                    }
                    else
                    {
                        string           description      = String.Format(CultureInfo.InvariantCulture, "Please select internal projection of layer {0}.", GetUri(featureLayer));
                        ProjectionWindow projSelectWindow = new ProjectionWindow(string.Empty, description, "Apply For All");
                        if (projSelectWindow.ShowDialog().GetValueOrDefault())
                        {
                            internalProj4 = projSelectWindow.Proj4ProjectionParameters;
                            applyForAll   = projSelectWindow.SyncProj4ProjectionForAll;
                            SaveInternalProj4ProjectionParameters(featureLayer, internalProj4);
                        }
                        else
                        {
                            featureLayer.IsVisible = false;
                            applyForAll            = projSelectWindow.SyncProj4ProjectionForAll;
                            canceled = true;
                        }
                    }

                    if (canceled && applyForAll)
                    {
                        break;
                    }
                }
            }
        }