// This is how I do it:
// Here's how I do it creating an XML type output (you can create whatever output you like)
////////////////////////////////////////////////////////////////////////////
// ldblTolerance ; Tolerance for the removal of proximal points
// lbXML ; XML output type:
// true=short xml with attributes
// false=long xml with tags
// lbBrief ; Points in single tag
////////////////////////////////////////////////////////////////////////////
StringBuilder lstrBuilder = new StringBuilder();
string [] LPad = ", , , , , , , , , , ".Split(',');
double ldblTolerance = 0.000010; // For removal of proximal points. Usage: GetPoints()
bool lbXML = true;
bool lbBrief = true;
lstrBuilder.Append("");
if (lGraphic.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon)
{
ESRI.ArcGIS.Client.Geometry.Polygon lPolygon = (ESRI.ArcGIS.Client.Geometry.Polygon) lGraphic.Geometry;
foreach (ESRI.ArcGIS.Client.Geometry.PointCollection lPoints in lPolygon.Rings)
{
lstrBuilder.Append(LPad[6] + "<ring>\n");
lstrBuilder = GetPoints(lstrBuilder, lbXML, lbBrief, ldblTolerance, LPad, lPoints);
lstrBuilder.Append(LPad[6] + "</ring>\n");
}
:
:
:
return lstringBuilder.ToString();
//////////////////////////////////////////////////////////////////////
public static StringBuilder GetPoints(StringBuilder astrBuilder, bool abXML, bool abBrief, double adblTolerance, string[] LPad, ESRI.ArcGIS.Client.Geometry.PointCollection aPoints)
{
MapPoint lprevMapPoint = new MapPoint();
double ldblX, ldblY;
lprevMapPoint.X = 0;
lprevMapPoint.Y = 0;
if (abBrief)
{
astrBuilder.Append(LPad[7] + "<points>");
if (abXML && !abBrief) {astrBuilder.Append("\n");}
}
foreach(MapPoint lMapPoint in aPoints)
{
ldblX = Math.Round(lMapPoint.X, 6); // Math.Round(lMapPoint.X, 6);
ldblY = Math.Round(lMapPoint.Y, 6); // Math.Round(lMapPoint.Y, 6);
if (Math.Abs(ldblX - lprevMapPoint.X) > adblTolerance && Math.Abs(ldblY - lprevMapPoint.Y) > adblTolerance)
{
lprevMapPoint.X = ldblX;
lprevMapPoint.Y = ldblY;
// Brief
if (abBrief)
{
if (abXML) {astrBuilder.Append(ldblX.ToString() + "," + ldblY.ToString() +",");}
else
{
astrBuilder.Append(ldblX.ToString() + ",");
astrBuilder.Append(ldblY.ToString() + "\n");
}
}
else
{
if (abXML) {astrBuilder.Append(LPad[7] + "<point x=\"" + ldblX.ToString() + "\" y=\"" + ldblY.ToString() + "\" />\n");}
else
{
astrBuilder.Append(LPad[7] + "<point>\n");
astrBuilder.Append(LPad[8] + "<x>" + ldblX.ToString() + "</x>\n");
astrBuilder.Append(LPad[8] + "<y>" + ldblY.ToString() + "</y>\n");
astrBuilder.Append(LPad[7] + "</point>\n");
}
}
}
}
if (abBrief)
{
if (abXML && !abBrief) {astrBuilder.Append("\n" + LPad[7]);}
astrBuilder.Append("</points>\n");
}
return astrBuilder;
}