ThinkGeo.com    |     Documentation    |     Premium Support

Shapefiles not drawn

Hi,


I'm trying to display the following shapefiles over the Google Map:


istat.it/ambiente/cartografia/       (downloads are on the right side in zip format)


WIth many other shapefiles I had no problems, they rendered perfecty.


The code is the following:


 



Proj4Projection proj4 = new Proj4Projection(); 
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326); 
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString(); 

ShapeFileFeatureLayer.BuildIndexFile(MapPath(@"~/shapes/province/prov2001_s.shp"),BuildIndexMode.DoNotRebuild); 

ShapeFileFeatureLayer testLayer = new ShapeFileFeatureLayer(MapPath(@"~/shapes/province/prov2001_s.shp")); 
testLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; testLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; 

testLayer.FeatureSource.Projection = proj4; 
LayerOverlay layerOverLay1 = new LayerOverlay(); 
layerOverLay1.IsBaseOverlay = false; 
layerOverLay1.Name = "Comuni"; 
layerOverLay1.Layers.Add("TestLayer", testLayer); 

Map1.CustomOverlays.Add(layerOverLay1); 


What am I doing wrong?


 


Thanks


Fabio



Fabio, 
  
   I looked at the files and the issue is that the projection of the shape files are not decimal degrees.  If you open the .prj file in a text editor it will tell you the projection.  It looks like the data is in UTM Zone 32N.  I searched Google for “EPSG UTM 32N” and I found it is EPSG:25832.  This means you need to use 25832 instead of 4326. 
  
 proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(25832); 
  
 Try this out and let’s see what happens.  It is important to always know the projection of your data.  I know it can be tough if you gather it from different sources but it’s an important part of your mapping process. 
  
 David

Hi David, 
 thanks for your rapid and exhaustive response, now it works perfectly! 
  
 Fabio

Fabio, 


I changed your message a bit to make your code looks nicer. If you are interested, please see the documents here for how to post codes in the post.
gis.thinkgeo.com/Support/Dis....aspx#4720
 
Ben

Hi: 
  
 I think I have a similar problem, I have the same code, but I think that the projection is already on decimal degrees. This is the content of my .prj file: 
  
 GEOGCS["GCS_WGS_1984",DATUM["D_WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]] 
  
 Is this correct? Is that the problem? or maybe is other thing? 
  
 Thank you very much!

Miren,  
  
 Yes, your prj looks like a typical WGS84. Can you try to add that shape file together with the World file(cntry.shp, can be found in the sampe data) to Map Suite Explorer(start->All Programs->ThinkGeo->Map Suite Full Edition 3.0(Eval)), to see if that file matches with the background world.  If it’s WGS84, the 2 should match fine.  
  
 please let me know what you find. 
  
 Ben.

I have tried, and they match perfectly in the map suite explorer so... Why can't I see then? I let you the source code:

 


 



Map1.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.SimpleColors.PaleRed)
        Map1.MapUnit = GeographyUnit.DecimalDegree
        Map1.MapTools.OverlaySwitcher.Enabled = True
        Map1.MapTools.OverlaySwitcher.OnClientBaseOverlayChanged = "onLayerChanged"

        Dim google As New GoogleOverlay("Google Map")
        google.JavaScriptLibraryUri = New Uri("maps.google.com/maps?file=api&v=2&key=ABQIAAAAu6q_1FGrswj3A6sHtn7tshQwDYsTE1Tx03TJFyCqrcvRGAWYkBT1Y4BceXxzPDZv1EZHNn1vW4in1Q")
        google.IsBaseOverlay = True
        google.GoogleMapType = GoogleMapType.Normal

        Map1.CustomOverlays.Add(google)


        Dim PointLayer As New ShapeFileFeatureLayer(MapPath("~\Maps\espes2________pi.shp"))
        PointLayer.RequireIndex = False

        PointLayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.Capital1
        PointLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

        ShapeFileFeatureLayer.BuildIndexFile(MapPath("~\Maps\espes2________pi.shp"), BuildIndexMode.DoNotRebuild)

        Dim proj4 As New Proj4Projection()
        proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326)
        proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()
        PointLayer.FeatureSource.Projection = proj4

        Dim overlay As New LayerOverlay

        overlay.IsBaseOverlay = False
        overlay.Name = "Points"
        overlay.Layers.Add("Points", PointLayer)

        Map1.CustomOverlays.Add(overlay)

        PointLayer.Open()
        Map1.CurrentExtent = PointLayer.GetBoundingBox
        PointLayer.Close()


Miren, 



The MapUnit is not set right. As you are using GoogleMap as the baselayer, you should following its projection, which is in Meter instead of DecimalDegree. 



So just change the first line to 

Map1.MapUnit = GeographyUnit.Meter 

everything should be fine. 



Ben 

 



OK Thank you!! Now it works

Great! Let us know for any other queries.

Again, Sorry!


Now, I'm trying to do the same but instead of a shapefilefeaturelayer now I'm using an inmemorymarkerlayer. I think its all ok but I dont see the markers.


I let you the source code so, if you see anything please tell me. THANK YOU!!!!!


 


 



Map1.MapTools.PanZoomBar.Enabled = True
        Map1.MapTools.LoadingImage.Enabled = True

        Map1.MapBackground.BackgroundBrush = New GeoSolidBrush(GeoColor.SimpleColors.PaleRed)
        Map1.MapUnit = GeographyUnit.Meter
        Map1.MapTools.OverlaySwitcher.Enabled = True
        Map1.MapTools.OverlaySwitcher.OnClientBaseOverlayChanged = "onLayerChanged"

        Dim google As New GoogleOverlay("Google Map")
        google.JavaScriptLibraryUri = New Uri("maps.google.com/maps?file=api&v=2&key=ABQIAAAAu6q_1FGrswj3A6sHtn7tshQwDYsTE1Tx03TJFyCqrcvRGAWYkBT1Y4BceXxzPDZv1EZHNn1vW4in1Q")
        google.IsBaseOverlay = True
        google.GoogleMapType = GoogleMapType.Normal

        Map1.CustomOverlays.Add(google)

        Dim proj4 As New Proj4Projection()
        proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326)
        proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()

        Dim markers As New InMemoryMarkerOverlay()
        markers.IsBaseOverlay = False
        markers.ZoomLevelSet.ZoomLevel01.DefaultMarkerStyle.WebImage = New WebImage("~\theme\default\img\marker.gif")
        markers.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20
        markers.Name = "Hotels"
        markers.FeatureSource.Projection = proj4

        fillMarkers() 'this method adds features to the markerlayer

        Map1.CustomOverlays.Add(markers)


Miren, 
  
 We recreated your problem using our own data and everything will go well after the following line of code is added.  
  
 
Dim proj4 As New Proj4Projection()
proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326)
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()
‘ Map will show well after adding the following code
proj4.Open()
 
  
 It’s a bit strange that you didn’t see any exception. If your problem still exists, please do the following checkings.  
 1, the features you added into the marker overlay are Point Based, and in DecimalDegree 
 2, browser’s script debugging mode is enabled. (IE7 for example, Tools->Internet Options->Advanced (Tab)->uncheck “Disable script debugging”) 
  
 Thanks, 
  
 Ben. 
  
    


Hi Ben! 
  
 I’m sure that the features I add are correct so I’ve changed the browser configuration and now it throws me a runtime error: 
  
 Microsoft JScript runtime error: ‘NeuN’ is not defined 
  
 any idea? 
  
 Thank you for everything

Miren,  
  
 We have a known issue that if the region of system is not set to “English”, it will throw some JScript runtime error. I think this is your case, can you have a quick test, change your system’s Region to English and try the application again. If it works fine after changing the region, that’s probably the reason.  
  
 We will fix this issue in the next release. Before that, there doesn’t have very good solutions unless setting the region to “English”, sorry for the inconvenience.  
  
 How to change the Region: 
 Start->Control Panel ->Regional and Languages Options -> Regional Options. 
  
 Ben 


Hi Ben! 
 It doesn´t work. I have change all the Regional Settings to USA/English and now what happens is that the map is displayed but without the markers and with the browser absolutly jamed, I can’t pan or do anything on the map or on the browser page

Hi Ben! 
 It doesn´t work. I have change all the Regional Settings to USA/English and now what happens is that the map is displayed but without the markers and with the browser absolutly jamed, I can’t pan or do anything on the map or on the browser page. 
 I work with Windows Vista, maybe it’s important

Miren, 
  
 Thanks for letting us know. From what you said we confirmed it’s a known issue of 3.0.131 about the CultureInfo, we will make it right in the next version. Sorry for the inconvenient. 
  
 I’m curious that you still have problem when changing the Region Settings to USA/English. Could you please simplify your application and send us as a little sample? Maybe some code else is going wrong. 
  
 Ben. 


Here it is!


Maybe I forgot something like references or things like that but the important issue is in.


Let me know if you find something, Thank you!!!



Miren


Thanks for your code, which helps a lot.


In your code, we found two problems,


1. Map unit is not set properly.


               Map1.MapUnit = GeographyUnit.Meter


2. Too many markers are displayed in the initial extent which makes IE jammed up (as following)



Here are 2 suggestions for this case:

• If you don’t need popups or context menus for the marker, you can render them using ShapeFileFeatureLayer, instead of drawing every marker on client side, drawing all the points on one image on server and pass it back, that will be much faster and cheaper


• If you want to use markers, try to set their zoomlevels to reduce the count of markers in a view extent. For your case, the map will show better if the marker overlays’ initial zoomlevel is set to 17.



markers.ZoomLevelSet.ZoomLevel17.DefaultMarkerStyle.WebImage = New WebImage("marker_blue.gif")
markers.ZoomLevelSet.ZoomLevel17.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20

 
Ben.