ThinkGeo.com    |     Documentation    |     Premium Support

GeoTiffRasterLayer code sample

Hi,



Do you have a map control code sample with a combination of a GeoTiffRasterLayer layer and other SQLite or shape file layers (something like the OsmWorldMapKitExplorer project? 



I have modified the OsmWorldMapKitExplorer project only to show a GeoTiffRasterLayer layer but it does not work. I’ve commented out the layers statistics code. It could be a wrong UpperThreshold/LowerThreshold setting, but I’ve tried multiple ways.



private void LayoutRoot_Loaded(object sender, RoutedEventArgs e)
        {
            // Setup the overlay


           LayerOverlay layerOverlay = (LayerOverlay)e.Overlay;




            //Tiff Layer


            Layer tifLayer = GetGeoTiffRasterLayer( Map1.ZoomLevelSet.ZoomLevel15.Scale, Map1.ZoomLevelSet.ZoomLevel01.Scale);
            layerOverlay.Layers.Add(“TifLayer”, tifLayer);



            // Setup the map
            Map1.MapUnit = GeographyUnit.Meter;
        


            Map1.CurrentExtent = tifLayer.GetBoundingBox();           
            Map1.MapTools.ScaleLine.IsEnabled = true;
            Map1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.FromArgb(255, 172, 205, 226));                               



            // Add the overlay to the map
            Map1.Overlays.Add(“worldmapkit”, layerOverlay);           
            
            Map1.Refresh();
        }



        private Layer GetGeoTiffRasterLayer(double zoomMin, double zoomMax)
        {
            GeoTiffRasterLayer gtrl = new GeoTiffRasterLayer(@“C:\Projects\WorldMapKitData\GeoTiff\NE2_HR_LC_SR_final.tif”);
            gtrl.UpperThreshold = zoomMax;
            gtrl.LowerThreshold = zoomMin;
            return gtrl;
        }



Thanks,

Gene

Hi,



I have some progress while waiting for your reply.


 I’ve
been able  to add a GeoTiff layer to a
map control (Zoom 1 to 6). Now I try to show some of the OsmWorldMapKitLayer layers (line and point
layers only) on the top of the GeoTiff layer.



 When
I add the tiff layer after OSM layers, I have to set the tiff layer transparency
to see the OSM layers:



 layerOverlay.Layers.Add(osmWorldMapKitLayer);


 //Tiff Layer


Layer tifLayer = NavData.GetGeoTiffRasterLayer();


layerOverlay.Layers.Add("TiffLayer",
tifLayer);


 When
I add the tiff layer before OSM layers, the tiff layer is not visible:



 layerOverlay.Layers.Add(osmWorldMapKitLayer);


 //Tiff Layer


Layer tifLayer = NavData.GetGeoTiffRasterLayer();


layerOverlay.Layers.Add("TiffLayer",
tifLayer);


What should
I do to show the OsmWorldMapKitLayer
layers (line and point layers only) on the top of the GeoTiff layer?



Thanks,

Gene



Hi Gene,



As I guess, the reason when you add the tiff layer before OSM layer and the tiff layer is not visible is because some of the OSM layers overlap the tiff layer. You can try to comment some layers out to see if helps. Basically, you need to disable the background layers and polygon layers, you can find them in OsmWorldMapKitLayer souce codes:


protected override void OpenCore()
        {
            //layers.Add("ne_baseland30m_polygon", GetBaseLand30mPolygonLayer());
            //layers.Add("ne_state5m_polygon", GetStateLabelLayer());
            //layers.Add("ne_ocean1m_polygon", GetOceanLabelLayer());
            //layers.Add("ne_place2m_point", GetPlace2mLabelLayer());
            //layers.Add("osm_place_point", GetPlaceLabelLayer());
            //layers.Add("osm_baseland1m_polygon", GetBaseLand1mPolygonLayer());
            //layers.Add("osm_baseland_polygon", GetBaseLandPolygonLayer());
            //layers.Add("osm_land300k_polygon", GetLand300kPolygonLayer());
            //layers.Add("osm_land100k_polygon", GetLand100kPolygonLayer());
            //layers.Add("osm_land_polygon", GetLandPolygonLayer());
            //layers.Add("ne_water10m_polygon", GetWater10mPolygonLayer());
            //layers.Add("osm_water1m_polygon", GetWater1mPolygonLayer());
            //layers.Add("osm_water_polygon", GetWaterPolygonLayer());
            
}
 
public void DrawBackground(GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
        {
            //DrawBackgroundCore(canvas, labelsInAllLayers);
        }

Please let us know if helps.



Thanks,



Troy

Hi Troy,



I’ve already excluded polygon layers for the tiff layer zooms, but I’ve only disabled the map control BackgroundOverlay.BackgroundBrush.

It started to work when I updated the OsmWorldMapKitLayer.DrawBackgroundCore function.



Thank you very much for your help.



Thanks,

Gene




Hi,



I only show the tiff layer from Zoom 1 to 6. Is it possible to set the background for particular zooms?



Thanks,

Gene

I’ve added a layer with  one large polygon which I show for zooms from 7 to 20 as a “background” layer using a water color. This approach solves the issue, but I’m still would like to know if there is a way to set a Map background for particular zooms only. 
  
 Gene

Hi Gene,



Using a background layer is a very smart and effectual way. I have another way, in DrawCore, we can override it like:


protected override void DrawCore(GeoCanvas canvas, System.Collections.ObjectModel.Collection<SimpleCandidate> labelsInAllLayers)
        {
            ZoomLevel tempCurrentZoomLevel = layers[0].ZoomLevelSet.GetZoomLevelForDrawing(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit);
            if (tempCurrentZoomLevel.Scale >= layers[0].ZoomLevelSet.ZoomLevel06.Scale)
            {
                DrawBackground(canvas, labelsInAllLayers);
            }
 
            foreach (FeatureLayer layer in layers)
            {
                ZoomLevel currentZoomLevel = layer.ZoomLevelSet.GetZoomLevelForDrawing(canvas.CurrentWorldExtent, canvas.Width, canvas.MapUnit);
                SetWhereClause(layer, currentZoomLevel);
 
                layer.Draw(canvas, labelsInAllLayers);
            }
        }

But, i would recommend the way that you are using.



Thanks,

Troy