Select to view content in your preferred language

save layer to xml file

6472
15
07-22-2010 12:13 AM
LedonneJuan
Emerging Contributor
hi, i'm looking for a layer to xml file and load xml file as graphic layer but found nothing. somebody help me please.

thanks
0 Kudos
15 Replies
SujaSudhan
Deactivated User
A very useful post, thanks!

Is there a way to filter the graphics by current extent and then add only the filtered graphics to the xml?  My original graphics in the graphics layer do not come from REST service, so I can't do a query to filter them (or can I?).

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.

Appreciate any guidance.

Thanks.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
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.

Something like:

var graphicsInCurrentExtent = graphicsLayer.Graphics.Where(g => g.Geometry.Extent.Intersects(MyMap.Extent)).ToList();
0 Kudos
SujaSudhan
Deactivated User
Something like:

var graphicsInCurrentExtent = graphicsLayer.Graphics.Where(g => g.Geometry.Extent.Intersects(MyMap.Extent)).ToList();


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.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
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.


'Where' is a .net LINQ method (documentation). To enable it, add : 'using System.Linq' at the beginning of your C# file.
0 Kudos
SujaSudhan
Deactivated User
'Where' is a .net LINQ method (documentation). To enable it, add : 'using System.Linq' at the beginning of your C# file.


Thanks Dominique. I sure need to take a deep look at the LINQ!!!
0 Kudos
BehnamAtazadeh
Deactivated User
Hi. I can serialize the graphics layer without attribute information but when I add attributes to my graphics layer, the graphics layer are not serialized and this error "Object does not match target type." happens in the this  line in the GraphicsLayerExtension class. can somebody help me how to solve this? Here is my code:

         GraphicsLayer myGraphicsLayer = MyMap.Layers["myGraphicLayer"] as GraphicsLayer;
          
              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 }))
                      {
                          myGraphicsLayer.Graphics.SerializeGraphics(writer);
                          writer.Close();
                      }
                      fileStream.Close();
                  }
              }
0 Kudos