コード例 #1
0
        /// <summary>
        /// Assignes selected projection and displays results
        /// </summary>
        public bool Assign(string filename, MapWinGIS.GeoProjection proj)
        {
            MapWinGIS.GeoProjection projWGS84 = new MapWinGIS.GeoProjection();
            if (!projWGS84.ImportFromEPSG(4326))
            {
                MessageBox.Show("Failed to initialize WGS84 coordinate system.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            bool sameProj = proj.get_IsSame(projWGS84);
            int  count    = 0;

            bool success  = false;
            int  rowIndex = dgv.Rows.Add();

            m_shapefile = new MapWinGIS.Shapefile();
            if (m_shapefile.Open(filename, m_mapWin.Layers as MapWinGIS.ICallback))
            {
                this.Text = "Assigning projection: " + System.IO.Path.GetFileName(filename);
                this.lblProjection.Text = "Projection: " + proj.Name;

                // it will be faster to assing new instance of class
                // as ImportFromEPSG() is slow according to GDAL documentation
                m_shapefile.GeoProjection = proj;

                if (!sameProj)
                {
                    // we can't show preview on map without reprojection
                    if ((m_shapefile.StartEditingShapes(true, null)))
                    {
                        if (m_shapefile.ReprojectInPlace(projWGS84, ref count))
                        {
                            success = true;
                        }
                    }
                }
                else
                {
                    success = true;
                }
            }

            if (success)
            {
                this.AddShapefile(m_shapefile);
                return(true);
            }
            else
            {
                // no success in reprojection
                m_shapefile.Close();
                return(false);
            }
        }