ThinkGeo.com    |     Documentation    |     Premium Support

Adding my own shape file

hi


i have some data including shp, shx, dbf, xml and some other files. using DisplayShapeMap user control in sample application, when i try to add shape files in my data, i always get the user control as blue colored in debug mode. interestingly enough; if i m not debugging i get the error 


"The parameter you supplied may not be null.

Parameter name: worldExtent"


can anybody tell me whats the problem? here is the code


           ShapeFileFeatureLayer worldLayer1 = new ShapeFileFeatureLayer(@"E:\GIS\vyrez\lesy.shp");

            worldLayer1.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;

            worldLayer1.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            ShapeFileFeatureLayer.BuildIndexFile(@"E:\GIS\vyrez\lesy.shp");



            winformsMap1.StaticOverlay.Layers.Add("Layer1", worldLayer1);

            winformsMap1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);

            winformsMap1.CurrentExtent = new RectangleShape(-180.0, 83.0, 180.0, -90.0);



            winformsMap1.Refresh();


Thanks



AdbulBasit, 
  
 Welcome to the community, hope you enjoy learning and sharing here. 
  
 From you code, seems you didn’t set the winforms.MapUnit.  
 
winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
 
 also, seems you are not using the latest version (3.0.199), as it should throw another exception if you didn’t set the map unit. 
  
 Another small issue is that you don’t need to call BuildIndexFile here. BuildIndexFile should only be called once to generate the idx/ids file. Once they are created, you do not need to call it again. 
  
 Thanks, 
  
 Ben

Hi Ben, 
 Thanks for your reply! 
  
 in fact i used the line of code you have mentioned, but it was missed when i copy it for my earlier post. please give your comments on my following scenario; 
  
 1: i downloaded Map Suite Desktop Edition 3.0 Beta 2 from the link download.thinkgeo.com/MapSuiteDesktopEvalSetup.zip 
 2: i downloaded a sample application from download.thinkgeo.com/HelloWorld_Desktop.zip 
 3: HelloWorld_Desktop works fine with the sample data downloaded with Map Suit Desktop Eval Setup 
 4: when i try to load the customer’s shape files (including shp, dbf, shx), WinformsMap control comes up blue with “unlicensed” written on it 
 5: i also created index files (idx, ids) according to the description 
  
 i tried to upload the shape files here but couldnt succeeded, size was less than 3 MB. can you provide me your email so that i can send you shape data. 
  
 following is the code i am using behind a button click; 
  
 FolderBrowserDialog fbd = new FolderBrowserDialog(); 
  
             if (fbd.ShowDialog() == DialogResult.OK) 
             { 
                 DirectoryInfo di = new DirectoryInfo(fbd.SelectedPath); 
  
                 winformsMap1.MapUnit = GeographyUnit.DecimalDegree; 
  
                 foreach (FileInfo fi in di.GetFiles("*.shp")) 
                 { 
                     ShapeFileFeatureLayer worldLayer = new ShapeFileFeatureLayer(fi.FullName); 
                     worldLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Urban1; 
                     worldLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 
  
                     winformsMap1.StaticOverlay.Layers.Add(worldLayer); 
                 } 
  
                 winformsMap1.CurrentExtent = new RectangleShape(0, 78, 30, 26); 
                 winformsMap1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean); 
  
                 winformsMap1.Refresh(); 
             }

Hi Ben, 
  
 i have send my shape file data to ‘support@thinkgeo.com’ and ask them to forward it to you. is this ok? 
  
 thanks, 
 Hamad

AdbulBasit, 



Thanks for providing your shapefiles. I loaded them in to Map Suite Explorer and found that you have area, line, and point-based shapefiles. To properly display these you will need to create a Style for each type of shapefile that you have; a AreaStyle for Area-based shapefiles, a LineStyle for Line-based shapefiles, and finally a PointStyle for point-based shapefiles.



Here is some example code you can add to the DisplayASimpleMap sample application:

private void Form1_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.Meter;

            //Setup Area-Based Layer
            ShapeFileFeatureLayer Budovy = new ShapeFileFeatureLayer(@"C:\Projects\budovy.shp");
            Budovy.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1;
            Budovy.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            //Setup Line-Based Layer
            ShapeFileFeatureLayer Inzisite = new ShapeFileFeatureLayer(@"C:\Projects\inzsite.shp");
            Inzisite.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.LocalRoad4;
            Inzisite.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            //Setup Point-Based Layer
            ShapeFileFeatureLayer VegetaceBody = new ShapeFileFeatureLayer(@"C:\Projects\vegetace_body.shp");
            VegetaceBody.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1;
            VegetaceBody.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

            winformsMap1.StaticOverlay.Layers.Add(Budovy);
            winformsMap1.StaticOverlay.Layers.Add(Inzisite);
            winformsMap1.StaticOverlay.Layers.Add(VegetaceBody);
            Budovy.Open();
            winformsMap1.CurrentExtent = Budovy.GetBoundingBox();
            Budovy.Close();
            winformsMap1.Refresh();
        }



Thanks for the reply, Ryan! 
  
 AdbulBasit, just let us know for more queries.

Ryan, Ben 
 Really thankful for your help, major issue has been resolved. 
  
 All the files are loaded property except "gn08_v013d.shp". its type is PolylineZ which is not implemented yet i guess. when i tried to open it in MapSuiteExplorer, it was crashed with "Object reference not set to an instance of an object." exception. index files were created alright throug ShapeFileFeatureLayer.BuildIndexFile() function. please help me in order to show this shape file. 
  
 thanks again! 
 Hamad

Hi Guys! 
  
 can you tell me that in the data i sent you earlier, what type of geo-referencing (lat/long etc) or projection is used? infact i need to show vehicles live location on that map based on lat/longs. i have seen Map Suite Desktop sample application and i am sure that if our shape files are properly geo-referenced it is possible. currently we are using mappoint, and due to its limitations we are looking forward to adapt ThinkGeo. can you people guide me in this regard, sorry i m new to these thing? 
  
 thanks 
 Hamad 
  


AbdulBasit, 
  
 We don’t support PolylineZ with the current version and we will add it in the upcoming one. So please wait for the new edition and sorry for the inconvenience for now. 
  
 After checking the *.prj file (which stores the projection info), I found the projection is “S-JTSK_Krovak_East_North”. The corresponding one in Proj4 is with the Id of 102067, but when I do the conversion with that, the projected point seems wrong. So can you let me know more about the data, or provide some documentation along with it as maybe I can find something there? The *.prj file should include all the info but I cannot read them, and our projection guru is not here these days. :( 
  
 Thanks, 
  
 Ben 


Hi Ben, 
 Thanks for your reply! 
  
 1: for PolylineZ; is there any way that i convert the shape file type to Polyline (or any other type) which is supported in current version? atleast the data in it would be visible. 
  
 2: i simply opened the *.prj file in MS Excel 2007 and got the following information; 
  
 PROJCS["S-JTSK_Krovak_East_North",GEOGCS["GCS_S_JTSK",DATUM["D_S_JTSK",SPHEROID["Bessel_1841",6377397.155,299.1528128]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Krovak"],PARAMETER["False_Easting",0.0],PARAMETER["False_Northing",0.0],PARAMETER["Pseudo_Standard_Parallel_1",78.5],PARAMETER["Scale_Factor",0.9999],PARAMETER["Azimuth",30.28813975277778],PARAMETER["Longitude_Of_Center",24.83333333333333],PARAMETER["Latitude_Of_Center",49.5],PARAMETER["X_Scale",-1.0],PARAMETER["Y_Scale",1.0],PARAMETER["XY_Plane_Rotation",90.0],UNIT["Meter",1.0]] 
  
 i guess each *.prj file contains the same data. there is also an xml file against each shp file. after opening it in ms excel, beside the other information there was a link esri.com/metadata/esriprof80.html. it might be useful. 
  
 i am searching if i could find any other information or documentation of this data. 
  
 thanks! 
 Hamad 


Hi Ben, 
 How are you? 
  
 i asked the shape file supplier about your query and they have stated that data is correct and it is in projection S-JTSK. ERSI for example like here download.arcdata.cz/utils/arcpad7.prj. i requested them to change the projection to WGS-84. i have sent you the re-projected data on ‘support@thinkgeo.com’. now the prj files contain; 
 GEOGCS[“GCS_WGS_1984”,DATUM[“D_WGS_1984”,SPHEROID[“WGS_1984”,6378137.0,298.257223563]],PRIMEM[“Greenwich”,0.0],UNIT[“Degree”,0.0174532925199433]] 
 would you please check the data now? 
  
 thanks, 
 Hamad 





 


Hamad,


I got your WGS84 data and display it on GoogleMap, they are matching exactly. So I think that data has no problem.


Still “gn08_v013d.shp” doesn't work because of the PolylineZ type. I'm afraid with the current version we cannot deal with the *Z type, we will definitely support drawing it in the next version. Sorry for the inconvenience.


Here is how I plot some of your WGS84 data to Google Earth, you can see the code as well as the snapshot.



 protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Map1.MapUnit = GeographyUnit.Meter;

                GoogleOverlay google = new GoogleOverlay("Google Map");
                google.JavaScriptLibraryUri = new Uri(ConfigurationManager.AppSettings["GoogleUri"]);
                google.GoogleMapType = GoogleMapType.Satellite;
                Map1.CustomOverlays.Add(google);

                ShapeFileFeatureLayer layer = new ShapeFileFeatureLayer(@"C:\Posts\WGS84\orez data.shp");
                layer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(50, GeoColor.StandardColors.Yellow));
                layer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                ShapeFileFeatureLayer layer2 = new ShapeFileFeatureLayer(@"C:\Posts\WGS84\lesy.shp");
                layer2.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.FromArgb(100, GeoColor.StandardColors.Green));
                layer2.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                ShapeFileFeatureLayer layer3 = new ShapeFileFeatureLayer(@"C:\Posts\WGS84\inzsite.shp");
                layer3.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.Highway3;
                layer3.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;

                Proj4Projection proj4 = new Proj4Projection();
                proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326);
                proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString();
                layer.FeatureSource.Projection = proj4;
                layer2.FeatureSource.Projection = proj4;
                layer3.FeatureSource.Projection = proj4;

                LayerOverlay layerOverlay = new LayerOverlay();
                layerOverlay.IsBaseOverlay = false;
                layerOverlay.Layers.Add(layer);
                layerOverlay.Layers.Add(layer2);
                layerOverlay.Layers.Add(layer3);
                Map1.CustomOverlays.Add(layerOverlay);

                Map1.CurrentExtent = layerOverlay.GetBoundingBox();
            }
        }


Thanks,


Ben




Hi Ben, thanks for replying. 



i loaded this data in Map Suite Desktop, now i want to pick lat long of a point clicked by mouse and show a vehicle icon (may be a bmp) at specific lat long. can u tell me how to? 



thanks, 

Hamad



Hamad, 
  
 You can hook up the MapClick event and within its event handler argument, you can directly get the corresponding world coordinate of the point you clicked. Please have a look at the How Do I sample (Querying Feature Layers -> Find the Feature(s) the user clicked on) for detail. 
  
 To show an icon (bitmap) at specific lat long, please have a look at this sample (Styles->Draw a point using a bitmap), that’s very simple and straightforward. 
  
 Thanks, 
  
 Ben 
  


Ben, 
  
 thanks for your email, i had managed to do this. here is the piece of code i am using against mouse click on map 
  
 private void winformsMap1_MapClick(object sender, WinformsMapClickEventArgs e) 
         { 
             if (bitmapLayer.InternalFeatures.Contains("Crossing")) 
                 bitmapLayer.InternalFeatures["Crossing"] = new Feature(e.WorldX, e.WorldY); 
             else 
                 bitmapLayer.InternalFeatures.Add("Crossing", new Feature(new PointShape(e.WorldX, e.WorldY))); 
  
             winformsMap1.Refresh(); 
         } 
  
 it takes 3 to 4 seconds to show the image on newer location. can it be minimized to around a second? it works fine if i dont use  winformsMap1.Refresh(); statement in above code, but takes same time to refresh. 
  
 Thanks, 
 Hamad

Hamad, 
  
 Does the bitmapLayer added to the DynamicOverlay? If yes, can you try the method winformsMap1.RefreshDynamic() which only refreshes the dynamic overlay but will do nothing to the StaticOverlays? Maybe this small method will solve your problem.  
  
 Thanks, 
  
 Ben

Hello Ben, 
 Thanks for your reply. 
  
 i have send may sample application for you on ‘support@thinkgeo.com’. please check that after executing “winformsMap1.RefreshDynamic();” statement, it requires 2 to 3 seconds to actually move the image to newer location. can we minimize this delay? 
 one more thing, how you integrated the code in your reply to any post?  do you use some tool not available to clients? it looks nice :) 
  
 regards, 
 Hamad




 


Hamad


Thanks for your sample codes, which is very helpful.


We confirmed this is a bug in the current DesktopEdition (3.0.199), we draw both StaticOverLay and DynamicOverlay inside MapClick event and that's why it is so slow. We will fix it in the upcoming version. Sorry for the inconvenience now. 


We have some tags helping us posting the source code nicely. Have a look at the page below and you will get it.


gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/4941/afv/topic/Default.aspx


Thanks,


Ben




Hi Ben,  
 thanks for your reply. 
  
 next thing i am trying is to focus on DynamicOverlay. as an image is added on it, i want to focus that image, either by Feature class of by lat long value. 
  
 Please tell me that when you are expected to release new version of DesktopEdition? if i purchase one now would i be able to get updated one under same license? 
  
 thanks 
 Hamad

Hamad, 
  
 I think the new release will be out earth next month. I am not very sure about the license stuff and one of our salesperson will answer your that question.  
  
 Thanks, 
  
 Ben