ThinkGeo.com    |     Documentation    |     Premium Support

Map fails with error message: The projection is not open

I get the following error messages:


'The projection is not open. Please open it before calling this method'.


- Which projection?


- Which method?


and


'projection initilalization failed. Parameter name: externalProjectionParameters'


- What value?


 


How do I get my map to render?


thanks


 


ShapeFileFeatureLayer postcodeLayer = new ShapeFileFeatureLayer(MapPath("~/App_Data/Maps/hsp_r46_region.shp"));new Proj4Projection(27700,27700); AreaStyles.County1);ApplyUntilZoomLevel.Level20;

Map1.StaticOverlay.Layers.Add(


Map1.ZoomToScale(4613998);


Map1.CurrentExtent =


"PostcodeLayer", postcodeLayer);new RectangleShape(-12, 59, 3.5, 50);

 


 


postcodeLayer.FeatureSource.Projection =



postcodeLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(


postcodeLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel =



Fergus, 
  
   I am having a hard time reading the code you posted.  I think for some reason the forum stripped out allot of it.  Could you put the code in a text file and attach it to the post?  In this way I can see your code and help you find the issue. 
  
 Some things I noticed from the code fragments.  When you create your projection class you specify 27700 for both the incoming and outgoing projection.  This is not correct, if the data is already in the 27700 projection and that is how you want it displayed then you don’t need projection at all.  You do need to make sure your Map.MapUnit is set to either feet or meters, whichever unit system the 27700 uses. 
  
 Some general thoughts on Open & Close methods. 
  
   In general whenever you get a “x is not open please open it before calling the method” you are creating one of our openable objects just as FeatureSource, Projection, or Layers and setting them onto another object where the open state is not the same.   
  
 For example when you create a ShapeFileFeatureLayer it has some objects that it creates inside of it.  One of them is a ShapeFileFeatureSource which is accessible through the layer as the .FeatureSource property.  Another one is a projection object which is accessible through the .FeatureSource.Projection property.  Let’s take the example that you create a new ShapeFileFeatureLayer and specify a shape file but not a projection.  You next call the Open method on it.  The Open method will call the Open method on the ShapeFileFeatureSource that it has inside of it.  Also if the ShapeFileFeatureSource has a projection object inside of it then the Open call will cascade to that as well.  The intention is that a call to Open the higher level objects will open the all the lower level objects inside of it.   
  
   Now the wrinkle.  What if we called the Open on the ShapeFileFeatureLayer without a projection object?  Well it will try to call the open but it will see it is null and just bypass that code.  What if now you create a new projection instance and did not call it’s open and set it to ShapeFileFeatureLayer.FeatureSource.Projection = [your new projection instance].  Well now there is an inconsistent state.  The Layer and FeatureSource is open but your new projection object is not.  You should have set your projection object before calling the open.  Or if you already called the open then you needed to call the open on the projection object when you passed it in.  Close works the same way.  If you call close on the higher level object then the close cascades down the object tree. 
  
 David

Hi, Thanks for your  reply. 
  
 I’ve modified your ‘DrawThematicFeatures’ sample to use our file and it fails in the same way. 
 In this reply it won’t let me add  attachments, so let’s hope selecting the whole class will work. 
  
 I added (27700, 27700) because that’s what I found in a post by one of your guys earlier. Without it I don’t get my features drawn at all. The .prj file has ‘PROJCS[“British National Grid (ORD SURV GB)”,GEOGCS[“unnamed”,DATUM[“D_OSGB_1936”,SPHEROID[“Airy - 1848”,6377563,299.319997677743]],PRIMEM[“Greenwich”,0],UNIT[“degree”,0.0174532925199433]],PROJECTION[“Transverse_Mercator”],PARAMETER[“latitude_of_origin”,49],PARAMETER[“central_meridian”,-2],PARAMETER[“scale_factor”,0.9996012717],PARAMETER[“false_easting”,400000],PARAMETER[“false_northing”,-100000],UNIT[“METER”,1]]’ which I’ve looked up to mean 27700. 
  
 I’ve also used the projection constructor with this string, but the same error ocurrs. 
  
 I’ve read your text, but I’m not calling Open() 
  
  
  
  
 using System; 
 using ThinkGeo.MapSuite.Core; 
  
 namespace CSSamples 
 { 
     public partial class DrawThematicFeatures : System.Web.UI.Page 
     { 
         protected void Page_Load(object sender, EventArgs e) 
         { 
             Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#B3C6D4")); 
             Map1.CurrentExtent = new RectangleShape(-140, 60, 140, -60); 
             Map1.MapUnit = GeographyUnit.DecimalDegree; 
  
             // Draw thematic features 
             ClassBreakStyle classBreakStyle = new ClassBreakStyle(“POP_CNTRY”); 
             classBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, AreaStyles.Grass1)); 
             classBreakStyle.ClassBreaks.Add(new ClassBreak(1000000, AreaStyles.Evergreen2)); 
             classBreakStyle.ClassBreaks.Add(new ClassBreak(10000000, AreaStyles.Evergreen1)); 
             classBreakStyle.ClassBreaks.Add(new ClassBreak(50000000, AreaStyles.Crop1)); 
             classBreakStyle.ClassBreaks.Add(new ClassBreak(100000000, AreaStyles.Forest1)); 
  
             //ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/SampleData/world/cntry02.shp")); 
             ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/SampleData/emb/hsp_r46_region.shp")); 
             worldLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.Country1); 
             worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
             worldLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle); 
  
             worldLayer.FeatureSource.Projection = new Proj4Projection(27700, 27700); 
              
             Map1.StaticOverlay.Layers.Add(“WorldLayer”, worldLayer); 
  
             // The following two lines of code enable the client and server caching. 
             // If you enable these features it will greatly increase the scalability of your 
             // mapping application however there some side effects that may be counter intuitive. 
             // Please read the white paper on web caching or the documentation regarding these methods. 
  
             //Map1.StaticOverlay.ClientCache.CacheId = “WorldOverlay”; 
             //Map1.StaticOverlay.ServerCache.CacheDirectory = MapPath("~/ImageCache/" + Request.Path); 
         } 
     } 
 } 


Fergus,


  I have no idea how this is working but I can get you on the right track.


  Like I mentioned before if your data is all in 27700 then you don't need a projection object at all.  You will have to make some adjustments.  Here is what I did in a nutshell.


1.I changed the map unit you were setting to Meters from decimal degrees.

2.I removed the set current extent.

3.I removed the projection code all together.

4.I set the current extent from the layer itself.  I would debug through this and get the upper left and lower right and hard code this later.


The changes are below.


One strange thing is that I did get the error you get when trying to use the 27700.  I even looked up the EPSG code and the string and still no luck.  I am not sure why but this is a bug in either our code or Proj4's.  We will investigate and see what is going on there.  I hope this gets you going while we check the projection issue.





    public partial class DrawThematicFeatures : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#B3C6D4"));
            // Since your map is in meters and these are decimal degrees they don't mean much
            //Map1.CurrentExtent = new RectangleShape(-140, 60, 140, -60);
            Map1.MapUnit = GeographyUnit.Meter;

            // Draw thematic features 
            ClassBreakStyle classBreakStyle = new ClassBreakStyle("POP_CNTRY");
            classBreakStyle.ClassBreaks.Add(new ClassBreak(double.MinValue, AreaStyles.Grass1));
            classBreakStyle.ClassBreaks.Add(new ClassBreak(1000000, AreaStyles.Evergreen2));
            classBreakStyle.ClassBreaks.Add(new ClassBreak(10000000, AreaStyles.Evergreen1));
            classBreakStyle.ClassBreaks.Add(new ClassBreak(50000000, AreaStyles.Crop1));
            classBreakStyle.ClassBreaks.Add(new ClassBreak(100000000, AreaStyles.Forest1));

            //ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/SampleData/world/cntry02.shp")); 
            ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(MapPath("~/SampleData/emb/hsp_r46_region.shp"));
            worldLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(AreaStyles.Country1);
            worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
            worldLayer.ZoomLevelSet.ZoomLevel01.CustomStyles.Add(classBreakStyle);

            // I took out the code for projection all together.

            // Here I am going to get the boudnign box for the shape file.
            // I suggest you just debug through this and get the upper left and lower
            // right and hard code them like you did witht he decimal degrees ones above
            // that I commented out.
            worldLayer.Open();
            Map1.CurrentExtent = worldLayer.GetBoundingBox();
            worldLayer.Close();

            Map1.StaticOverlay.Layers.Add("WorldLayer", worldLayer);

            // The following two lines of code enable the client and server caching. 
            // If you enable these features it will greatly increase the scalability of your 
            // mapping application however there some side effects that may be counter intuitive. 
            // Please read the white paper on web caching or the documentation regarding these methods. 

            //Map1.StaticOverlay.ClientCache.CacheId = "WorldOverlay"; 
            //Map1.StaticOverlay.ServerCache.CacheDirectory = MapPath("~/ImageCache/" + Request.Path); 
        }
    }





Thanks. But there is still a problem. 
  
 :-) When I place the code you supplied in the sample web page it works. 
  
 :-( When I place it in may application (inside a Telerik Radpane inside a UserControl), all I see is the background. Not even the navigator control. 
  
 This is being handled with ticket 1751 - not sure who this is being looked at by - you might want to check it out. 
  
  
  
  


Fergus, 
  
   I see.  Ok so here are or were two issues.  I wanted to focus on getting rid of the projection stuff as you didn’t need it.  The second and the other issue is the 3rd part frame.  I responded to that a bit ago that we will need to get that frame and see if there is a collision between the javascripts.  This isnt going to get done quicly though as we are short handed this week. :-( 
  
 David