ArcGIS Pro 3.8 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / Map Class / SpatialReference Property
Example

In This Topic
    SpatialReference Property (Map)
    In This Topic
    Gets the spatial reference of the map.
    Syntax
    public SpatialReference SpatialReference {get;}
    Public ReadOnly Property SpatialReference As SpatialReference
    Example
    Format a Location Using the Current Map Location Unit
    {
      //Get the current view camera location
      var center_pt = new Coordinate2D(mapView.Camera.X, mapView.Camera.Y);
      //Get the current location unit
      var loc_unit = await QueuedTask.Run(() => map.GetLocationUnitFormat());
    
      //Format the camera location
      var str = loc_unit.FormatLocation(center_pt, map.SpatialReference);
      System.Diagnostics.Debug.WriteLine($"Formatted location: {str}");
    }
    Zoom To a Point
    {
      await QueuedTask.Run(() =>
      {
        //Create a point
        var pt = MapPointBuilderEx.CreateMapPoint(x, y, spatialReference);
        //Buffer it - for purpose of zoom
        var poly = GeometryEngine.Instance.Buffer(pt, buffer_size);
    
        //do we need to project the buffer polygon?
        if (!mapView.Map.SpatialReference.IsEqual(poly.SpatialReference))
        {
          //project the polygon
          poly = GeometryEngine.Instance.Project(poly, mapView.Map.SpatialReference);
        }
    
        //Zoom - add in a delay for animation effect
        mapView.ZoomTo(poly, new TimeSpan(0, 0, 0, 3));
      });
    }
    Get Line of Sight
    {
      tinLayer = null;
      MapPoint observerPoint = null;
      MapPoint targetPoint = null;
      CIMPointSymbol obstructionPointSymbol = null;
      CIMLineSymbol visibleLineSymbol = null;
      CIMLineSymbol invisibleLineSymbol = null;
    
      var losParams = new LineOfSightParams();
      losParams.ObserverPoint = observerPoint;
      losParams.TargetPoint = targetPoint;
    
      // add offsets if appropriate
      // losParams.ObserverHeightOffset = observerOffset;
      // losParams.TargetHeightOffset = targerOffset;
    
      // add obstruction feature class if appropriate (multipatch)
      //losParams.ObstructionsMultipatchFeatureClass = obsFeatureClass;
    
      // set output spatial reference
      losParams.OutputSpatialReference = mapView.Map.SpatialReference;
    
      LineOfSightResult results = null;
      try
      {
        await QueuedTask.Run(() =>
        {
          if (tinLayer.CanGetLineOfSight(losParams))
          {
            results = tinLayer.GetLineOfSight(losParams);
          }
        });
      }
      catch (Exception)
      {
        // handle exception
      }
    
      if (results != null)
      {
        bool targetIsVisibleFromObserverPoint = results.IsTargetVisibleFromObserverPoint;
        //These properties are not used. They will always be false
        // results.IsTargetVisibleFromVisibleLine;
        // results.IsTargetVisibleFromInvisibleLine;
    
        if (results.VisibleLine != null)
        {
          mapView.AddOverlay(results.VisibleLine, visibleLineSymbol.MakeSymbolReference());
        }
    
        if (results.InvisibleLine != null)
        {
          mapView.AddOverlay(results.VisibleLine, invisibleLineSymbol.MakeSymbolReference());
        }
    
        if (results.ObstructionPoint != null)
        {
          mapView.AddOverlay(results.ObstructionPoint, obstructionPointSymbol.MakeSymbolReference());
        }
      }
    }
    Use Select or Search with a Spatial Query
    {
      var mapView = MapView.Active;
      if (mapView == null)
        return;
    
      await QueuedTask.Run(() =>
      {
        if (!featSceneLayer.HasAssociatedFeatureService)
        {
          return;//no search or select
        }
    
        //Select all features within the current map view
        var sz = mapView.GetViewSize();
        var map_pt1 = mapView.ClientToMap(new System.Windows.Point(0, sz.Height));
        var map_pt2 = mapView.ClientToMap(new System.Windows.Point(sz.Width, 0));
    
        //Convert to an envelope
        var temp_env = EnvelopeBuilderEx.CreateEnvelope(map_pt1, map_pt2, mapView.Map.SpatialReference);
    
        //Project if needed to the layer spatial ref
        SpatialReference sr = null;
        using (var fc = featSceneLayer.GetFeatureClass())
        using (var fdef = fc.GetDefinition())
        {
          sr = fdef.GetSpatialReference();
        }
    
        var env = GeometryEngine.Instance.Project(temp_env, sr) as Envelope;
    
        //Set up a query filter
        var sf = new SpatialQueryFilter()
        {
          FilterGeometry = env,
          SpatialRelationship = SpatialRelationship.Intersects,
          SubFields = "*"
        };
    
        //Select against the feature service
        var select = featSceneLayer.Select(sf);
        if (select.GetCount() > 0)
        {
          //enumerate over the selected features
          using (var rc = select.Search())
          {
            while (rc.MoveNext())
            {
              using (var feature = rc.Current as Feature)
              {
                oid = feature.GetObjectID();
                //etc.
              }
            }
          }
        }
        mapView.Map.ClearSelection();
      });
    }
    Requirements

    Target Platforms: Windows 11 Home, Pro, Enterprise (64 bit)

    ArcGIS Pro version: 3.0 or higher.
    See Also