Add Photo Overlay in ArcGIS SDK for .NET

3269
3
08-03-2015 12:46 PM
JasonTrinidad1
New Contributor III

I am new to the ArcGIS SDK and I can't seem to find how to add a picture on top of the map, using 4-coner coordinates. In the snippet below, coords has the coordiantes for 4 points. I know all I try to do in this example is to fill a polygon with a picture, so if anyone has an example on how to overlay a picture over the map, I would appreciate it. Thanks.

System.Uri myPictureUri = new System.Uri("https://upload.wikimedia.org/wikipedia/commons/0/03/Piwnice_aerial_view.jpg");

Esri.ArcGISRuntime.Symbology.PictureFillSymbol pictureFillSymbol = new Esri.ArcGISRuntime.Symbology.PictureFillSymbol();
pictureFillSymbol.SetSourceAsync(myPictureUri);

var graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as Esri.ArcGISRuntime.Layers.GraphicsLayer;
if (graphicsLayer == null)
{
  graphicsLayer = new Esri.ArcGISRuntime.Layers.GraphicsLayer();
  graphicsLayer.ID = "MyGraphicsLayer";
  MyMap.Layers.Add(graphicsLayer);
}

System.Collections.ObjectModel.ObservableCollection<Esri.ArcGISRuntime.Geometry.PointCollection> rings =
  new System.Collections.ObjectModel.ObservableCollection<Esri.ArcGISRuntime.Geometry.PointCollection>();
Esri.ArcGISRuntime.Geometry.PointCollection pointCollection = new Esri.ArcGISRuntime.Geometry.PointCollection(MyMapView.SpatialReference);

for (int i = 0; i < coords.Length-2; i = i + 2)
{
  Esri.ArcGISRuntime.Geometry.MapPoint point;
  point = Esri.ArcGISRuntime.Geometry.ConvertCoordinate.FromDecimalDegrees(coords.ToString() + " " + coords[i + 1].ToString(), MyMapView.SpatialReference);
  pointCollection.Add(point);
}

rings.Add(pointCollection);

//Set Geometry
Esri.ArcGISRuntime.Geometry.Polygon p = new Esri.ArcGISRuntime.Geometry.Polygon(rings, MyMap.SpatialReference);
var overlayGraphic = new Esri.ArcGISRuntime.Layers.Graphic();
overlayGraphic.Geometry = p;
overlayGraphic.Symbol = pictureFillSymbol;

graphicsLayer.Graphics.Add(overlayGraphic);
0 Kudos
3 Replies
MichaelBranscomb
Esri Frequent Contributor

Hi,

The Photo Overlay you have sounds like an aerial photograph. We're working on a new high performance "RasterLayer" type which will be able to directly read image/raster files. Until then the best alternative may actually to use KML? Below is an example:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Folder>
  <name>Ground Overlays</name>
  <description>Examples of ground overlays</description>
  <GroundOverlay>
  <name>Large-scale overlay on terrain</name>
  <description>Overlay shows Mount Etna erupting
  on July 13th, 2001.</description>
  <Icon>
  <href>http://developers.google.com/kml/documentation/images/etna.jpg</href>
  </Icon>
  <LatLonBox>
  <north>37.91904192681665</north>
  <south>37.46543388598137</south>
  <east>15.35832653742206</east>
  <west>14.60128369746704</west>
  <rotation>-0.1556640799496235</rotation>
  </LatLonBox>
  </GroundOverlay>
  </Folder>
</kml>

You the approach you have discovered so far is unlikely to give the desired effect, because the PictureFillSymbol is simply tiling the image to fill the area of the polygon. Therefore you cannot guarantee the image will be correctly geo-referenced on the ground.

Cheers

Mike

JasonTrinidad1
New Contributor III

Thanks, Mike. Is there a way to add this Kml from a string parameter or a local file in .Net? Also, can href be a local file?

0 Kudos
JasonTrinidad1
New Contributor III

Just to be on the same page. What I want to do is similar as in this picture
stalag-xiia-aerial-google-earth-overlay.jpg

Can the KmlGroundOverlay class be used for this?

0 Kudos