Layer reprojection in ArcGIS Runtime .NET SDK 100.0.0

03-16-2017 09:01 AM
New Contributor III

I have a map with basemap in Spatial Reference = 54030 (Robinson) which is displayed in map viewer. Now I am trying to load a feature layer from the ArcGIS Portal. This layer has WebMercator SpatialReference = 3857 and I am trying to reproject it on the fly which doesn't seem to work.

I am referring to the guide Spatial references—ArcGIS Runtime SDK for .NET | ArcGIS for Developers, paragraph

Feature layers from feature services

When using a feature service table created from a feature service from ArcGIS Online or ArcGIS Enterprise, the service supports reprojection. Set its spatial reference to the same as the map's spatial reference before you initialize the table. This ensures the data is requested from the service in the correct spatial reference. When adding an ArcGIS feature layer to the map, ArcGIS Runtime automatically determines the correct spatial reference and requests data from the feature service accordingly.

According to the guide, I should be able to set SpatialReference either on service feature table, or service layer, but it is not possible. I tried also to make reprojection manually:

FeatureCollectionTable reprojectedCollectionTable = new FeatureCollectionTable(featureTable.Fields, featureTable.GeometryType, Map.SpatialReference) {Title = featureTable.TableName};
FeatureCollection featureCollection = new FeatureCollection(new List<FeatureCollectionTable> { reprojectedCollectionTable });
FeatureCollectionLayer layer = new FeatureCollectionLayer(featureCollection) { Name = reprojectedCollectionTable.Title };

That also doesn't work. How can I reproject layer and add to the map?


0 Kudos
3 Replies
Esri Regular Contributor

Thank you for your feedback. I will log an issue to get our documentation updated. You no longer need to specify SpatialReference on layer or table, this should automatically be discovered from the map that contains the layer.

You can try the following code, Map is in 54030 and FeatureLayer is in 3857. You can then replace FeatureLayer creation with your service or portal item.

Zooming in/out should update Map.Extent and trigger request for features. You can also use LayerViewStateChanged to check for Error/Status. Right now, I'm only using it to get to the layer's full extent.

        public Forum()
            MyMapView.LayerViewStateChanged += MyMapView_LayerViewStateChanged;
            MyMapView.Map = new Map(new SpatialReference(54030));
            MyMapView.Map.OperationalLayers.Add(new FeatureLayer(new Uri("")));

        private void MyMapView_LayerViewStateChanged(object sender, LayerViewStateChangedEventArgs e)
          if(e.Layer is FeatureLayer && e.Layer.FullExtent != null)
                MyMapView.SetViewpoint(new Viewpoint(e.Layer.FullExtent));
0 Kudos
New Contributor III

It doesn't work, I use FeatureServer, not MapServer as in your example

0 Kudos
New Contributor III

I managed to display some layers in SRID=3857 on our custom basemap (SRID=54030) by creating FeatureLayer from PortalItem url, but they appear after long waiting. They contain several features only, so I do not see why it takes so long time. Some layers do not appear at all. And even those which appear one time, do not appear next time, to me it looks random behavior. Is it reprojection that takes so unacceptably much time or it could be anything else?

P.S. I am creating map so:

var basemapLayer = new ArcGISTiledLayer(new Uri(""));
var basemap = new Basemap(basemapLayer);
Map = new Map(basemap);

0 Kudos