ThinkGeo.com    |     Documentation    |     Premium Support

Shapefile over cloud map

Hello Thinkgeo community.

I am just getting into the Thinkgeo environment so I am still learning the ropes…I am still learning .NET as well so I am fairly rookie.

I am trying to add a shapefile that is overlayed to scale on the cloud vector map.

I can load both the shapefiles and the vector map but the shapefiles are loaded in the middle of the ocean.

I’ve tried looking at some of the samples but it doesn’t seem like I am missing anything. If it matters, the shapefiles are from natural earth

  private void mapView_Loaded(object sender, RoutedEventArgs e)
    {
        mapView.MapUnit = GeographyUnit.Meter;

        // Add a base map overlay.
        var cloudVectorBaseMapOverlay = new ThinkGeoCloudVectorMapsOverlay("USlbIyO5uIMja2y0qoM21RRM6NBXUad4hjK3NBD6pD0~", "f6OJsvCDDzmccnevX55nL7nXpPDXXKANe5cN6czVjCH0s8jhpCH-2A~~", ThinkGeoCloudVectorMapsMapType.Light);
        mapView.Overlays.Add(cloudVectorBaseMapOverlay);

        mapView.CurrentExtent = new RectangleShape(-20000000, 20000000, 20000000, -20000000);

        // Create a shapefileLayer, passing in the path of a shape file. 
        ShapeFileFeatureLayer shapefileLayer = new ShapeFileFeatureLayer(@"ne_10m_admin_1_states_provinces.shp");
        ShapeFileFeatureLayer shapefileLayer2 = new ShapeFileFeatureLayer(@"ne_10m_roads.shp");
        ShapeFileFeatureLayer shapefileLayer3 = new ShapeFileFeatureLayer(@"ne_10m_rivers_lake_centerlines.shp");
        //ShapeFileFeatureLayer shapefileLayer4 = new ShapeFileFeatureLayer(@"ne_10m_ocean.shp");
        ShapeFileFeatureLayer shapefileLayer5 = new ShapeFileFeatureLayer(@"ne_10m_lakes_north_america.shp");
        ShapeFileFeatureLayer shapefileLayer6 = new ShapeFileFeatureLayer(@"ne_10m_rivers_north_america.shp");

        // Set the default area style and apply it to all 20 ZoomLevels
        shapefileLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(GeoPens.DimGray, new GeoSolidBrush(new GeoColor(128, GeoColors.ForestGreen)));



        shapefileLayer2.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(new GeoPen(GeoBrushes.DimGray, 4), new GeoPen(GeoBrushes.Black, 1));
        shapefileLayer3.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(new GeoPen(GeoBrushes.Blue, 4), new GeoPen(GeoBrushes.LightBlue, 1));
        shapefileLayer6.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(new GeoPen(GeoBrushes.Blue, 4), new GeoPen(GeoBrushes.LightBlue, 1));
        //shapefileLayer4.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(GeoPens.BrightBlue);
        shapefileLayer5.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = new AreaStyle(GeoPens.DimGray, new GeoSolidBrush(new GeoColor(128, GeoColors.Blue)));

        shapefileLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        shapefileLayer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        shapefileLayer3.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        shapefileLayer5.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        shapefileLayer6.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
        //shapefileLayer4.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

        //shapefileLayer.FeatureSource.ProjectionConverter = new ProjectionConverter(2276, 3857);
        //shapefileLayer2.FeatureSource.ProjectionConverter = new ProjectionConverter(2276, 3857);
        //shapefileLayer3.FeatureSource.ProjectionConverter = new ProjectionConverter(2276, 3857);
        ////shapefileLayer4.FeatureSource.ProjectionConverter = new ProjectionConverter(2276, 3857);
        //shapefileLayer5.FeatureSource.ProjectionConverter = new ProjectionConverter(2276, 3857);
        //shapefileLayer6.FeatureSource.ProjectionConverter = new ProjectionConverter(2276, 3857);


        // Create an Overlay to store the layer and add it to the map.
        LayerOverlay overlay = new LayerOverlay();
        overlay.Layers.Add(shapefileLayer);
        //overlay.Layers.Add(shapefileLayer2);
        overlay.Layers.Add(shapefileLayer3);
        overlay.Layers.Add(shapefileLayer5);
        overlay.Layers.Add(shapefileLayer6);
        //overlay.Layers.Add(shapefileLayer4);
        mapView.Overlays.Add(overlay);

        ShapeFileFeatureLayer.BuildIndexFile(@"ne_10m_rivers_north_america.shp");
        shapefileLayer.Open();
        shapefileLayer2.Open();
        shapefileLayer3.Open();
        //shapefileLayer4.Open();
        shapefileLayer5.Open();
        shapefileLayer6.Open();
        mapView.CurrentExtent = shapefileLayer.GetBoundingBox();



        mapView.Refresh();



        //layer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = new LineStyle(new GeoPen(GeoBrushes.DimGray, 4), new GeoPen(GeoBrushes.WhiteSmoke, 2));

    }

Hey Zach,

So, here you are experiencing wonderful world of projection and SRS (See Spatial reference system: https://en.wikipedia.org/wiki/Spatial_reference_system). You see, geometry can be stored in several thousand types of SRS. The two common ones are Spherical Mercator (SRID 3857) and Decimal Degrees WGS84 datum (SRID 4326). Your map is currently displaying in Spherical Mercator, but the Natural Earth data is in Decimal Degrees WGS84. In order to fix this, you need to reproject each of your layers to match your map’s projection. Luckily, that’s pretty easy to do here:

layer.FeatureSource.ProjectionConverter = new ProjectionConverter(4326, 3857);

What this does is dynamically translate the data on the layer to match the SRID of your map. So, what you’ll need to be aware of going further is knowing what projection your data is stored as and reproject it to match your map’s projection. So, in the future, if you find that you can’t find where your data is, or in the middle of the ocean, it’s almost certainly a projection issue.

Thanks,
Kyle