If I am loading a shapefile via the ShapefileTable class and I have some other layer that is in a different spatial reference, how can I get them both to display in the map? I believe when dealing with the local services there is some 'magic' that causes additional layers that are added to be projected to the spatial reference of the map.
More specifically we use an ArcGISTiledMapServiceLayer as a basemap and would like display our shapefiles on top of this layer.
How can we achieve this (preferably without killing performance)?
Note: The FeatureLayer performance when using direct access to shapefiles is greatness! Well worth the wait.
Solved! Go to Solution.
Shapefiles does not support reprojection on the fly. The recommended approach is to use a basemap in the same spatial reference, or project your shapefiles prior to using them.
If all else fails, you can use the ShapefileTable to query all rows and put them in a graphics layer - however be very careful with performance and memory consumption that this approach can cause.
Shapefiles does not support reprojection on the fly. The recommended approach is to use a basemap in the same spatial reference, or project your shapefiles prior to using them.
If all else fails, you can use the ShapefileTable to query all rows and put them in a graphics layer - however be very careful with performance and memory consumption that this approach can cause.
Here's an example that shows some simple conditional logic to determine when shapefile contents need to be displayed as graphics or features. It is important to note that QueryAsync will load the entire shapefile into memory, so as Morten mentioned, memory consumption can be an issue. The code example also shows how to limit the number of features returned using the MaximumRows property. You can use this technique to control the number of features, and thus memory, used in your application.
Esri.ArcGISRuntime.Data.ShapefileTable table = await Esri.ArcGISRuntime.Data.ShapefileTable.OpenAsync(filename);
if (table.SpatialReference != mv.SpatialReference)
{
var items = await table.QueryAsync(new Esri.ArcGISRuntime.Data.QueryFilter() { MaximumRows = 1000});
GraphicsOverlay overlay = new GraphicsOverlay()
{
GraphicsSource = items.Select(f => new Graphic(f.Geometry, f.Attributes)),
RenderingMode = GraphicsRenderingMode.Static
};
// Define renderer for graphics overlay
// overlay.Renderer = sr;
mv.GraphicsOverlays.Add(overlay);
}
else
{
FeatureLayer layer = new FeatureLayer(table);
mv.Map.Layers.Add(layer);
}
The shapefiles I am dealing with have typically in the range of 100k to 500k graphics. I have experimented with loading into a graphics layer before but the memory definitely becomes an issue . I would like to avoid a Maximum records cap. Coming at this from a different angle, would it be more trivial to project my ArcGISTiledMapServiceLayer to the spatial reference of my shapefile?
For that type of data, please consider creating a Runtime Geodatabase in the correct projection, or better publish it to a server and use a tiled (of if you have to a dynamic) mapservice. These are much better geared to handle this amount of data than shapefiles are.
All of our layers are added dynamically by an end user. We are also supporting Geodatabase, Tile packages, and various other data sources in our application (if our clients have them). I just happen to know that some of our clients are using sizeable shapefiles currently (with an ancient Map Objects implementation). We would like to continue allowing them to use these shapefiles if we can find a suitable method.
If using the Desktop API in the Runtime SDK for .NET, you may want to consider using local server. You can use a map package to spin up a local map service, then leverage dynamic layers to add data on the fly. Shapefiles added to a local map service in this fashion would be reprojected on the fly (just like they are when using a remote server aka ArcGIS Server), but it would increase the complexity and size of your app deployment. Here's a sample: arcgis-runtime-samples-dotnet/DynamicLayerAddData.xaml at master · Esri/arcgis-runtime-samples-dotne...
@Rex: We have already been down the local server path. It is too slow for dealing with the shapefiles we are working with and we would like to avoid the max record cap.
It looks like our best solution is to make sure the basemap and shapefiles are in the same spatial reference. Are shapefile layers loaded via the ShapefileTable class going to be able to reproject on the fly sometime down the road?
*Marking Morten's original response as the answer because it most completely answers my original question. Thanks for the responses and tossing some ideas out there.
Yes, we're considering support for reprojection of local datasets, including shapefiles. However we don't have a timeline yet for when that feature will be included.
Hi,
Tables (Shapefile, etc) now reproject on the fly in the v100.x series of releases.
Please download the latest Visual Studio extension from ArcGIS for Developers or update your NuGet packages via the NuGet package manager.
Cheers
Mike