Is it possible to reporject a MsSql2008FeatureLayer from a 4326 to a different SRID using a projection?
It appears that the projection fails when I try setting this up this way, and I’m not entirely sure what the cause would be.
Dim sqlLayer As New MsSql2008FeatureLayer(GetClientMappingDBConnection, “Mapping_GIS_County_Info”, “Artificial_Key”, 4326)
sqlLayer.WhereClause = “WHERE " + String.Join(” OR ", From ci In CountyCodes
Where ci.Adjacent = False
Select "(State_Code = " & ci.StateCode.ToString() & " AND County_Code = " & ci.CountyCode.ToString() & “)”)
sqlLayer.SpatialIndexName = “IX_dbo_Mapping_GIS_County_Info_Spatial”
Dim projection As ManagedProj4Projection = New ManagedProj4Projection()
projection.InternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(4326)
projection.ExternalProjectionParametersString = ManagedProj4Projection.GetEpsgParametersString(_srid)
projection.Open()
sqlLayer.FeatureSource.Projection = projection
DefineLayerZoomLevelScales(sqlLayer)
Dim aStyle As AreaStyle = New AreaStyle(New GeoPen(GeoColor.SimpleColors.Blue, 4), New GeoSolidBrush(GeoColor.SimpleColors.Transparent))
Dim textStyle As New TextStyle(“Display_Name”, New GeoFont(“Arial”, 12, DrawingFontStyles.Bold), New GeoSolidBrush(GeoColor.StandardColors.Navy))
With textStyle
.HaloPen = New GeoPen(GeoColor.SimpleColors.White, 3)
.DuplicateRule = LabelDuplicateRule.UnlimitedDuplicateLabels
.XOffsetInPixel = 0
.YOffsetInPixel = 30
.FittingPolygonInScreen = True
.OverlappingRule = LabelOverlappingRule.AllowOverlapping
End With
sqlLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = aStyle
sqlLayer.ZoomLevelSet.ZoomLevel01.DefaultTextStyle = textStyle
sqlLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level18
sqlLayer.IsVisible = True
Return sqlLayer
This layer is then added to a LayerOverlay.
This layer displays perfectly fine when the projection isn’t applied; however, when the projection is set up as detailed above, nothing appears on the map. It also appears to return invalid coordinates when I return the bounding box of the LayerOverlay. The SRID I am attempting to project to is 3160.
Can anyone offer any advice?
MsSql2008FeatureLayer projection
I figured this out.
I had to set my unit of measure before the map was initially displayed alongside my custom zoom levels.
Once I did this, I also added an Open call to the projection before setting the FeatureSource’s projection to the projection I created. Once this was done, it appeared to work as intended.
Apparently asynchronously loading the map and setting some of these properties after it was initially displayed can cause some issues.
I was able to pinpoint this down as the culprit because my custom zoom levels wouldn’t work if I set the map’s zoom levels during the load event. I was able to do so on the layers themselves during this time, but doing so on both the layer and then the map would cause the layers that were previously showing correctly to not allow me to zoom in/out and still display themselves.
Following a similar concept with the projection allowed me to get the projections working correctly.
Hi Nathan,
I am glad to hear you figured that out, and thanks for your detail share, I think your post is helpful for other guy who met same question.
Regards,
Don