ThinkGeo.com    |     Documentation    |     Premium Support

How I assign Projection to shapefiles, so that they fit right on google map

I have a shapefile which i want to display over Google Map, The projection defined in this shapefile is "SWEREF 99 1800".  But it could not fit right over Google Map. How I change/re-project my shapefile so that it fit right on google map?


shapefile is attached.


Need immediate help ?



Parkshp.zip (98.2 KB)

There are a couple of steps to go thorough to setup a layer to be reprojected.



        
  1. Figure out what the EPSG number is for the projection of your shapefile. I did a search in the Projection Documentation that Map Suite provides and found that the EPSG number for your shapefile was 3011. You can find this documentation here: 

        C:\Program Files (x86)\ThinkGeo\Map Suite Desktop Full Edition 4.5\Documentation\Projections

  2.     
  3. Next setup your code like the following: 
     public partial class DisplayASimpleMap : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Page.IsPostBack)
                {
                    Map1.MapUnit = GeographyUnit.Meter;
                   
                    //ShapeFileFeatureSource.BuildIndexFile(@"C:\Projects\ThinkGeo Customers\aa\Parkshp\Parkshp\park.shp",BuildIndexMode.DoNotRebuild);

                    // Setup ShapefileFeatureLayer and Styles
                    ShapeFileFeatureLayer park = new ShapeFileFeatureLayer(@"C:\Projects\ThinkGeo Customers\aa\Parkshp\Parkshp\park.shp");
                    park.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Antarctica1;
                    park.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                    // Setup Parameters for Projection
                    ManagedProj4Projection mproj4Projection = new ManagedProj4Projection();
                    mproj4Projection.InternalProjectionParameters = ManagedProj4Projection.GetEpsgParameters(3011);   
                    mproj4Projection.ExternalProjectionParameters = ManagedProj4Projection.GetGoogleMapParameters();
                    
                    // Set Projection of Park ShapeFileFeatureLayer
                    park.FeatureSource.Projection = mproj4Projection;                
                    
                    // Setup Google Overlay
                    GoogleOverlay google = new GoogleOverlay("Google Map");
                    google.JavaScriptLibraryUri = new Uri(ConfigurationManager.AppSettings["GoogleUri"]);
                    google.GoogleMapType = GoogleMapType.Normal;

                    // Setup Overlay to contain ShapeFileFeatureLayer
                    LayerOverlay shapeOverlay = new LayerOverlay("ShapeOverlay",false, TileType.SingleTile);
                    shapeOverlay.Layers.Add(park);

                    // Add Overlays to Map
                    Map1.CustomOverlays.Add(google);
                    Map1.CustomOverlays.Add(shapeOverlay);

                    // Set Map's Extent
                    park.Open();
                    Map1.CurrentExtent = park.GetBoundingBox();
                    park.Close();        
                  
                }
            }
        }


         



Thanks for the reply!


I have one more question.


How can i change Native projection of this shapefile ?. In what software, i can do that ?



Aa,


 To change the native projection of a shapefile, you need to create a new one in the projection of your choice using the SaveToProjection API. We have a Code Community project Save To Projection that deals with that scenario wiki.thinkgeo.com/wiki/Map_Suite_We...Projection


 So, for your case, we will have the following code and you can see how the resulting shapefile dsiplays on Google Map:




 //Code for creating new shapefile in Google Map projection from shapefile in SWEREF projection.

            //Projection class to go from SWEREF 18 00 (Sweden) projection to Google Map projection (Spherical Mercator).
            Proj4Projection SWEREFToGoogleMap_Projection = new Proj4Projection();
            SWEREFToGoogleMap_Projection.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(3011); //
            SWEREFToGoogleMap_Projection.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); //Google Map Projection

            //Creates a new shapefile in Google Map projection from the existing shapefile in SWEREF projection.
            ShapeFileFeatureLayer.SaveToProjection(@"..\..\Data\park.shp", @"..\..\Data\googlemap_park.shp", SWEREFToGoogleMap_Projection, OverwriteMode.Overwrite);



          //Code for displaying the shapefile natively in Google Map projection on Google Map.

            wpfMap1.MapUnit = GeographyUnit.Meter;
            
            GoogleMapsOverlay googleMapsOverlay = new GoogleMapsOverlay();
            wpfMap1.Overlays.Add(googleMapsOverlay);

            ShapeFileFeatureLayer shapeFileFeatureLayer = new ShapeFileFeatureLayer(@"..\..\Data\googlemap_park.shp");
            shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle =
                AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(150, GeoColor.StandardColors.Green), GeoColor.StandardColors.Black);

            shapeFileFeatureLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
           
            LayerOverlay layerOverlay = new LayerOverlay();
            layerOverlay.Layers.Add(shapeFileFeatureLayer);

            wpfMap1.Overlays.Add(layerOverlay);

            shapeFileFeatureLayer.Open();
            wpfMap1.CurrentExtent = shapeFileFeatureLayer.GetBoundingBox();
            shapeFileFeatureLayer.Close();

            wpfMap1.Refresh();