Excellent, thank you. I actually did something similar
private void btnGetData_Click(object sender, EventArgs e)
{
Cursor.Current = Cursors.WaitCursor;
QueryFilter qf = MakeCacheQuery();
IEnumerable<MobileCacheInfo> emi = MobileApplication.Current.Project.EnumerateMobileCacheInfos();
foreach (MobileCacheInfo mi in emi)
{
MobileCache mc = new MobileCache(mi.MobileCache.StoragePath);
if (mc.CacheExists && mc.IsOpen)
mc.Close();
try
{
var con = new MobileServiceConnection();
con.Url = mi.MobileServiceConnection.Url;
con.CreateCache(mc);
mc.Open();
ICollection<FeatureLayer> flayers = mc.FeatureLayers;
foreach (FeatureLayer fl in flayers)
{
var flsyncAgent = new FeatureLayerSyncAgent(fl, con);
flsyncAgent.SynchronizationDirection = SyncDirection.DownloadOnly;
flsyncAgent.DownloadFilter = qf;
SyncResults sr = flsyncAgent.Synchronize();
}
}
finally
{
if (mc != null && mc.CacheExists && mc.IsOpen)
mc.Close();
}
}
Cursor.Current = Cursors.Default;
}
What is really unfortunate here though is the QueryFilter won't accept the GeometricRelationship - I can download all of the data that I have, but not a subset based on the intersection of the layers
private QueryFilter MakeCacheQuery()
{
if (cmbDownloadParameter.SelectedIndex < 3)
{
GpsConnection gps = Common.Utilities.GPSTools.GpsConnection;
if (gps == null)
{
gps = MobileApplication.Current.GpsConnectionManager.Connection;
}
Coordinate c = MobileApplication.Current.Project.SpatialReference.FromWgs84(gps.Longitude, gps.Latitude);
Geometry pointGeom = new ESRI.ArcGIS.Mobile.Geometries.Point(c);
Double dblRad = 100;
if (cmbDownloadParameter.SelectedItem.ToString().Equals("100 Meters"))
dblRad = 100;
else if (cmbDownloadParameter.SelectedItem.ToString().Equals("500 Meters"))
dblRad = 500;
else if (cmbDownloadParameter.SelectedItem.ToString().Equals("1 Kilometer"))
dblRad = 1000;
Polygon pg = Common.Geography.Geometry.BufferPointFromGpsCoordinate(c, dblRad);
QueryFilter qf = new QueryFilter(pg, GeometricRelationshipType.Intersect);
return qf;
}
}
With the buffering code here
public static class Geometry
{
public static Polygon BufferPointFromGpsCoordinate(Coordinate c, Double dblRadius)
{
Double dbDegreeToMeter = 0.0000089928;
Int32 degreeInterval = 1;
CoordinateCollection coordCollection = new CoordinateCollection();
for (Double degree = 0; degree < 360; degree += degreeInterval)
{
Coordinate radiusCoordinate = new Coordinate();
radiusCoordinate.X = c.X + (Math.Cos((degree / 360) * 2 * Math.PI) * dbDegreeToMeter * dblRadius);
radiusCoordinate.Y = c.Y + (Math.Cos((degree / 360) * 2 * Math.PI) * dbDegreeToMeter * dblRadius);
coordCollection.Add(radiusCoordinate);
}
return new Polygon(coordCollection);
}
}