'Where' is a .net LINQ method (documentation). To enable it, add : 'using System.Linq' at the beginning of your C# file.
Thanks for the quick reply. However, there is no "Where" property to the Graphics on the above code line. I am still struggling to find a method to filter a graphics layer, so any pointers will be useful.
Something like:var graphicsInCurrentExtent = graphicsLayer.Graphics.Where(g => g.Geometry.Extent.Intersects(MyMap.Extent)).ToList();
var graphicsInCurrentExtent = graphicsLayer.Graphics.Where(g => g.Geometry.Extent.Intersects(MyMap.Extent)).ToList();
In summary, How to filter the features in a graphics layer? I only want graphics in the current extent to be written to the xml.
I've attached C# code allowing XML serialization/deserialization of Graphics.It's developed as an extension of GraphicsLayer:So, in WPF, you can serialize to a file with code like:
string dataFile = @graphics.xml; using (XmlWriter writer = XmlWriter.Create(dataFile, new XmlWriterSettings() { Indent = true })) { myGraphicsLayer.SerializeGraphics(writer); writer.Close(); }
myGraphicsLayer.ClearGraphics(); using (XmlReader reader = XmlReader.Create(dataFile)) { myGraphicsLayer.DeserializeGraphics(reader); reader.Close(); }
<?xml version="1.0" encoding="utf-8"?> <Graphics xmlns:sys="http://www.w3.org/2001/XMLSchema" xmlns:esri="http://schemas.datacontract.org/2004/07/ESRI.ArcGIS.Client.Geometry" xmlns:col="http://schemas.datacontract.org/2004/07/System.Collections.Generic" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/ESRI.ArcGIS.Client.Samples"> <Graphic> <Attributes> <Attribute> <col:key>OBJECTID</col:key> <col:value i:type="sys:int">1</col:value> </Attribute> <Attribute> <col:key>Name</col:key> <col:value i:type="sys:string">Graphic1</col:value> </Attribute> </Attributes> <Geometry i:type="esri:Polygon"> <esri:spatialReference> <esri:wkid>4326</esri:wkid> </esri:spatialReference> <esri:rings> <esri:points> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>120.039</esri:x> <esri:y>-20.303</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>142.539</esri:x> <esri:y>-7.0137</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>163.281</esri:x> <esri:y>-13.923</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>172.773</esri:x> <esri:y>-35.174</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>173.594</esri:x> <esri:y>-43.18</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>121.797</esri:x> <esri:y>-36.032</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>120.039</esri:x> <esri:y>-20.303</esri:y> </esri:point> </esri:points> </esri:rings> </Geometry> </Graphic> <Graphic> <Attributes> <Attribute> <col:key>OBJECTID</col:key> <col:value i:type="sys:int">2</col:value> </Attribute> <Attribute> <col:key>Name</col:key> <col:value i:type="sys:string">Graphic2</col:value> </Attribute> </Attributes> <Geometry i:type="esri:Polygon"> <esri:spatialReference i:nil="true" /> <esri:rings> <esri:points> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>130.039</esri:x> <esri:y>-20.303</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>152.539</esri:x> <esri:y>-7.0137</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>173.281</esri:x> <esri:y>-13.923</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>179.773</esri:x> <esri:y>-35.174</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>179.594</esri:x> <esri:y>-43.18</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>131.797</esri:x> <esri:y>-36.032</esri:y> </esri:point> <esri:point> <esri:spatialReference i:nil="true" /> <esri:x>130.039</esri:x> <esri:y>-20.303</esri:y> </esri:point> </esri:points> </esri:rings> </Geometry> </Graphic> </Graphics>
string dataFile = @graphics.xml; using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication()) { using (IsolatedStorageFileStream fileStream = store.CreateFile(dataFile)) { using (XmlWriter writer = XmlWriter.Create(fileStream, new XmlWriterSettings() { Indent = true })) { graphicsLayer.SerializeGraphics(writer); writer.Close(); } fileStream.Close(); }�??
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.