Click or drag to resize

Viewpoint Constructor (Geometry)

Initializes a new instance of the Viewpoint class with a bounding extent.

Namespace:  Esri.ArcGISRuntime.Mapping
Assembly:  Esri.ArcGISRuntime (in Esri.ArcGISRuntime.dll) Version: 100.11.0
public Viewpoint(
	Geometry targetGeometry


Type: Esri.ArcGISRuntime.GeometryGeometry
The geometry to use as the visible area.
ArgumentNullExceptiontargetGeometry cannot be null.
The spatial reference of the target geometry cannot be null.


Example Name: QueryFeatureCountAndExtent

Zoom to features matching a query and count the features in the current visible extent.

Code example screen shot.

// Copyright 2018 Esri.
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at:
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.

using Esri.ArcGISRuntime.Data;
using Esri.ArcGISRuntime.Geometry;
using Esri.ArcGISRuntime.Mapping;
using System;
using System.Windows;

namespace ArcGISRuntime.WPF.Samples.QueryFeatureCountAndExtent
        name: "Query feature count and extent",
        category: "Analysis",
        description: "Zoom to features matching a query and count the features in the current visible extent.",
        instructions: "Use the button to zoom to the extent of the state specified (by abbreviation) in the textbox or use the button to count the features in the current extent.",
        tags: new[] { "count", "feature layer", "feature table", "features", "filter", "number", "query" })]
    public partial class QueryFeatureCountAndExtent
        // URL to the feature service.
        private readonly Uri _medicareHospitalSpendLayer =
            new Uri("");

        // Feature table to query.
        private ServiceFeatureTable _featureTable;

        public QueryFeatureCountAndExtent()

        private async void Initialize()
            // Create the map with a basemap.
            Map myMap = new Map(BasemapStyle.ArcGISDarkGray);

            // Create the feature table from the service URL.
            _featureTable = new ServiceFeatureTable(_medicareHospitalSpendLayer);

            // Create the feature layer from the table.
            FeatureLayer myFeatureLayer = new FeatureLayer(_featureTable);

            // Add the feature layer to the map.

                // Wait for the feature layer to load.
                await myFeatureLayer.LoadAsync();

                // Set the map initial extent to the extent of the feature layer.
                myMap.InitialViewpoint = new Viewpoint(myFeatureLayer.FullExtent);

                // Add the map to the MapView.
                MyMapView.Map = myMap;
            catch (Exception e)
                MessageBox.Show(e.ToString(), "Error");

        private async void BtnZoomToFeaturesClick(object sender, RoutedEventArgs e)
                // Create the query parameters.
                QueryParameters queryStates = new QueryParameters{WhereClause = $"upper(State) LIKE '%{StateTextbox.Text}%'"};

                // Get the extent from the query.
                Envelope resultExtent = await _featureTable.QueryExtentAsync(queryStates);

                // Return if there is no result (might happen if query is invalid).
                if (resultExtent?.SpatialReference == null)
                    ResultsTextbox.Text = "No results. Search for an abbreviated name (e.g. NH).";

                // Create a viewpoint from the extent.
                Viewpoint resultViewpoint = new Viewpoint(resultExtent);

                // Zoom to the viewpoint.
                await MyMapView.SetViewpointAsync(resultViewpoint);

                // Update the UI.
                ResultsTextbox.Text = $"Zoomed to features in {StateTextbox.Text}";
            catch (Exception ex)
                MessageBox.Show(ex.ToString(), "Error");

        private async void BtnCountFeaturesClick(object sender, RoutedEventArgs e)
                // Get the current visible extent.
                Geometry currentExtent = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry;

                // Create the query parameters.
                QueryParameters queryCityCount = new QueryParameters
                    Geometry = currentExtent,
                    // Specify the interpretation of the Geometry query parameters.
                    SpatialRelationship = SpatialRelationship.Intersects

                // Get the count of matching features.
                long count = await _featureTable.QueryFeatureCountAsync(queryCityCount);

                // Update the UI.
                ResultsTextbox.Text = $"{count} features in extent";
            catch (Exception ex)
                MessageBox.Show(ex.ToString(), "Error");
<UserControl x:Class="ArcGISRuntime.WPF.Samples.QueryFeatureCountAndExtent.QueryFeatureCountAndExtent"
        <Style TargetType="Button">
            <Setter Property="Margin" Value="5,5,5,0" />
        <Style TargetType="TextBox">
            <Setter Property="Margin" Value="5,5,5,0" />
        <esri:MapView x:Name="MyMapView"/>
        <Border Style="{StaticResource BorderStyle}">
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <RowDefinition Height="auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                <TextBlock Text="Click 'Zoom to matching features' to zoom to features matching the given state abbreviation. Click 'Count features in extent' to count the features in the current extent (regardless of the results of the query)."
                           Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2"
                           TextWrapping="Wrap" FontWeight="SemiBold" />
                <TextBox x:Name="StateTextbox" 
                         Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" 
                <Button Content="Zoom to matching features" 
                        Grid.Row="2" Grid.Column="0" 
                        Click="BtnZoomToFeaturesClick" />
                <Button Content="Count features in extent" 
                        Grid.Row="2" Grid.Column="1" 
                        Click="BtnCountFeaturesClick" />
                <TextBox x:Name="ResultsTextbox"
                         Grid.Row="3" Grid.Column="0" Grid.ColumnSpan="2" 
                         IsEnabled="False" />
See Also
Additional Examples
Hyperlink to ExampleDescription
AddEncExchangeSetDisplay nautical charts per the ENC specification.
AddGraphicsWithSymbolsUse a symbol style to display a graphic on a graphics overlay.
AnalyzeHotspotsUse a geoprocessing service and a set of features to identify statistically significant hot spots and cold spots.
ApplyMosaicRuleApply mosaic rule to a mosaic dataset of rasters.
BufferListGenerate multiple individual buffers or a single unioned buffer around multiple points.
ChangeBlendRendererBlend a hillshade with a raster by specifying the elevation data. The resulting raster looks similar to the original raster, but with some terrain shading, giving it a textured look.
ChangeEncDisplaySettingsConfigure the display of ENC content.
ChangeFeatureLayerRendererChange the appearance of a feature layer with a renderer.
ChangeSublayerRendererApply a renderer to a sublayer.
ChangeViewpointSet the map view to a new viewpoint.
ClipGeometryClip a geometry with another geometry.
CustomDictionaryStyleUse a custom dictionary style (.stylx) to symbolize features using a variety of attribute values.
DisplayKmlDisplay KML from a URL, portal item, or local KML file.
DisplaySubtypeFeatureLayerDisplays a composite layer of all the subtype values in a feature class.
EditBranchVersioningCreate, query and edit a specific server version using service geodatabase.
EditFeatureLinkedAnnotationEdit feature attributes which are linked to annotation through an expression.
FeatureLayerSelectionSelect features in a feature layer.
FindAddressFind the location for an address.
FindRouteDisplay directions for a route between two points.
GenerateOfflineMapTake a web map offline.
GenerateOfflineMapWithOverridesTake a web map offline with additional options for each layer.
GeodatabaseTransactionsUse transactions to manage how changes are committed to a geodatabase.
GroupLayersGroup a collection of layers together and toggle their visibility as a group.
IdentifyKmlFeaturesShow a callout with formatted content for a KML feature.
ListKmlContentsList the contents of a KML file.
LocalServerMapImageLayerStart the Local Server and Local Map Service, create an ArcGIS Map Image Layer from the Local Map Service, and add it to a map.
MapImageLayerTablesFind features in a spatial table related to features in a non-spatial table.
OfflineBasemapByReferenceUse the `OfflineMapTask` to take a web map offline, but instead of downloading an online basemap, use one which is already on the device.
OfflineGeocodeGeocode addresses to locations and reverse geocode locations to addresses offline.
OfflineRoutingSolve a route on-the-fly using offline data.
QueryFeatureCountAndExtentZoom to features matching a query and count the features in the current visible extent.
RasterHillshadeUse a hillshade renderer on a raster.
RasterLayerGeoPackageDisplay a raster contained in a GeoPackage.
RasterRenderingRuleDisplay a raster on a map and apply different rendering rules to that raster.
RasterRgbRendererApply an RGB renderer to a raster layer to enhance feature visibility.
ReadShapefileMetadataRead a shapefile and display its metadata.
RenderPictureMarkersUse pictures for markers.
SelectEncFeaturesSelect features in an ENC layer.
ServiceFeatureTableCacheDisplay a feature layer from a service using the **on interaction cache** feature request mode.
ServiceFeatureTableNoCacheDisplay a feature layer from a service using the **no cache** feature request mode.
SetInitialMapAreaDisplay the map at an initial viewpoint representing a bounding geometry.
SimpleRenderersDisplay common symbols for all graphics in a graphics overlay with a renderer.
StyleWmsLayerChange the style of a Web Map Service (WMS) layer.
TraceUtilityNetworkDiscover connected features in a utility network using connected, subnetwork, upstream, and downstream traces.
ViewPointCloudDataOfflineDisplay local 3D point cloud data.
WmsIdentifyIdentify features in a WMS layer and display the associated popup content.
WMSLayerUrlDisplay a WMS layer using a WMS service URL.