ThinkGeo.com    |     Documentation    |     Premium Support

Openstreet map and Shapefiles

I have a client that uses the Openstreet maps.



They have just provided me with several Shp files they would like to add as layers



The Openstreetmaps   have a Geographyunit of Meters and the shape files are DecimalDegrees .



I tried the   ShapefileToGoogleMap sample code  ( Google gives me a forbidden message.)

I changed the base map from google to OSM.  As they use the same Projection I assumed this would work.

Although I get No errors , I also dont get any of the Shapefile objects displayed.



On the sample caode , I dont get a background map either.



How can I apply these features without editing the shape files?   Is this even possible.



my Key Code points

    

     Public MainOverlay As LayerOverlay = New LayerOverlay()

     Public Darlingtonlayer As ShapeFileFeatureLayer = New ShapeFileFeatureLayer(“MyShapeFile.shp”)



        Form1.WinformsMap1.MapUnit = GeographyUnit.Meter   'should be meter

        Form1.WinformsMap1.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255))



        osmOverlay = New OpenStreetMapOverlay() ’

        osmOverlay.IsBase = True

        osmOverlay.CacheDirectory = Application.StartupPath & “\OSMCache”



        Form1.WinformsMap1.Overlays.Add(osmOverlay)



         Darlingtonlayer.RequireIndex = False    

        Darlingtonlayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.MajorStreet3

        Darlingtonlayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20



        'Sets the projection parameters to go from Geodetic (EPSG 4326) or decimal degrees to Google Map projection (Spherical Mercator).

        proj4 = New Proj4Projection()

        proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326)

        proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()



        Darlingtonlayer.FeatureSource.Projection = proj4 : Darlingtonlayer.Name = “DarlingtonLayer”





       MainOverlay.Layers.Add(Darlingtonlayer.Name, Darlingtonlayer)

        MainOverlay.Name = “MainOverlay”

      





        'Sets the extend of the map based on the GPS point.

        proj4.Open()

        Dim projVertex As Vertex = proj4.ConvertToExternalProjection(lon, lat)



        Dim extendWidth As Double = 9200

        Dim extendHeight As Double = 4800



        Form1.WinformsMap1.CurrentExtent = New RectangleShape((projVertex.X - extendWidth), (projVertex.Y + extendHeight), (projVertex.X + extendWidth), (projVertex.Y - extendHeight))

        Form1.WinformsMap1.MinimumScale = 2000

        Form1.WinformsMap1.MaximumScale = 73824000






Hi Steve, 
  
 I checked the codes, and I didn’t find the MainOverlay is added into the map. And also I guess the map currentExtent which I guess might not be within the shape file area. 
  
 So, After the overlay is inserted into the map, you may be worth to try Darlingtonlayer.GetBoundngBox() as the value of currentExtent. 
  
 If the issue persists, please feel free to let us know. 
 Regards, 
 Troy 


The google forbidden message error is because your request is beyond the google server limits, more details please refer  
 thinkgeo.com/forums/MapSuite/tabid/143/aft/11803/Default.aspx on floor 3. 
  
 Thanks 


I missed the Portion where I add the Main Overlay to the map, in the above comment.   It did exist in the original code. 



I tried setting   Form1.WinformsMap1.CurrentExtent = Darlingtonlayer.GetBoundingBox 



after I ran the app.  My center lat / lon was 0,0   which is incorrect. should be 45,-78  approx 

Again No Lines were drawn on the map. 



And just to add sauce to the pudding,  The client has also sent us a Base map  in MXD format.   ( Is this possible)



To Simplfy. I created a small test app with all the pertinent parts. 



--------------------------------------- 

Imports System.Collections.Specialized 

Imports ThinkGeo.MapSuite.Core 

Imports ThinkGeo.MapSuite.DesktopEdition 





Public Class Form1 

Public osmOverlay As OpenStreetMapOverlay 

Public proj4 As Proj4Projection 



Public dzdir As String = Application.StartupPath & "\maps\darlington&#34



’  This is the Darlington Zone 1KM 

Public Darlingtonlayer As ShapeFileFeatureLayer = New ShapeFileFeatureLayer(dzdir & “Darlington_Secondary_Zones.shp”) 



Public MainOverlay As LayerOverlay = New LayerOverlay() 





Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 

WinformsMap1.MapUnit = GeographyUnit.Meter   'should be meter 

WinformsMap1.BackgroundOverlay.BackgroundBrush = New GeoSolidBrush(GeoColor.FromArgb(255, 198, 255, 255)) 



osmOverlay = New OpenStreetMapOverlay() ’ 

osmOverlay.IsBase = True 

osmOverlay.CacheDirectory = Application.StartupPath & “\OSMCache” 



WinformsMap1.Overlays.Add(osmOverlay) 





'Sets the projection parameters to go from Geodetic (EPSG 4326) or decimal degrees to Google Map projection (Spherical Mercator). 

proj4 = New Proj4Projection() 

proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(4326) 

proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString() 



proj4.Open() 

Dim projVertex As Vertex = proj4.ConvertToExternalProjection(-78.7, 43.86) 



Dim extendWidth As Double = 9200 

Dim extendHeight As Double = 4800 

WinformsMap1.CurrentExtent = New RectangleShape((projVertex.X - extendWidth), (projVertex.Y + extendHeight), (projVertex.X + extendWidth), (projVertex.Y - extendHeight)) 





WinformsMap1.MinimumScale = 2000 

WinformsMap1.MaximumScale = 73824000 





Darlingtonlayer.RequireIndex = False 

Darlingtonlayer.FeatureSource.Projection = proj4 



Darlingtonlayer.Name = “DarlingtonLayer” 

Darlingtonlayer.ZoomLevelSet.ZoomLevel01.DefaultLineStyle = LineStyles.ContestedBorder1 

Darlingtonlayer.ZoomLevelSet.ZoomLevel01.DefaultPointStyle = PointStyles.City1 

Darlingtonlayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20 



MainOverlay.Layers.Add(Darlingtonlayer.Name, Darlingtonlayer) 



WinformsMap1.Overlays.Add(“MainOverlay”, MainOverlay) 

WinformsMap1.Refresh() 

End Sub 

End Class 




Hi Steve,



Since you said the map center is near by the 0,0 when using layer’s boundingbox as map current extent, what I am guessing now is your shape file’s source EPSG is not based 4326 but with other projection system. I am not sure if there is a .prj file standing with your shape file, if there is, you may try to use the below codes:


Dim proj4 As New Proj4Projection()
proj4.InternalProjectionParametersString = Proj4Projection.ConvertPrjToProj4(File.ReadAllText("…/…/Darlington_Secondary_Zones.prj"))
proj4.ExternalProjectionParametersString = Proj4Projection.GetGoogleMapParametersString()
Darlingtonlayer.FeatureSource.Projection = proj4

Or we can debug  it by quick watch the value of the layer’s boundingbox. and then comparing it with the correct one "New RectangleShape((projVertex.X - extendWidth), (projVertex.Y + extendHeight), (projVertex.X + extendWidth), (projVertex.Y - extendHeight)) "



Besides, we also can comment out some codes one by one, like we don’t add the shape layer to see if the map are the correct location. If yes, we can say the issue is happened on the shapelayer. and then we can do narrow down the issue and do more test.



After checking all the codes, I didn’t find any clues except the above guess, if the issue persists, sending the shape file to us should be the most recommended way via email forumsupport@thinkgeo.com



Thanks,

Troy

There is a Prj file associated with these shape Files.



The above code failed  ConvertprjtoProj4   is not part of Proj4Projection   Version 4.5





Thank you

Hi Steve,



Since map suite version 4.5 doesn’t support this function, I find some other ways to convert prj text to the EPSG code or proj4 text.




        
  • using the online tool prj2epsg.org/search. In this tool, input the prj file text and then we can get the EGPS code, after we get the EPSG code, we can use it like: proj4.InternalProjectionParametersString = Proj4Projection.GetEpsgParametersString(EpsgCode)

  •     
  • Convert it with GDAL library. Here is a web-link to show how to do it.  gis.stackexchange.com/questi…/7615#7615


Hope it helps.

If the issue persists, please feel free to let us know.



Thanks,

Troy