Select to view content in your preferred language

Area And Perimeter

4425
26
10-09-2010 10:31 AM
NathalieNeagle
Regular Contributor
I'm using this example and it works great  in the example with projection 102100 but I'm using projection 4326 WGS 1984 esridecimaldegrees and my numbers are way off can someone tell what I need to change
buthttp://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AreasAndLengths

I think it is here  but not sure

   private void GeometryService_AreasAndLengthsCompleted(object sender, AreasAndLengthsEventArgs args)
        {
            //TODO: Geometry service not returning correct values, area unit seems invalid, may need to use data in 
            //planar coordinate space

            // convert results from meters into miles and sq meters into sq miles for our display
            double miles = args.Results.Lengths[0] * 0.0006213700922;
            double sqmi = Math.Abs(args.Results.Areas[0]) * 0.0000003861003;
            ResponseTextBlock.Text = String.Format("Polygon area: {0} sq. miles\nPolygon perimeter: {1} miles.", Math.Round(sqmi, 3), Math.Round(miles, 3));
        }
0 Kudos
26 Replies
NathalieNeagle
Regular Contributor
I'm still in need of the question I posted eailer but no I ran into another problem so I was hoping if someone was kind enough to answer one maybe they have the knowledge to do both.

So I've implemented the "area and perimeter" (http://help.arcgis.com/en/webapi/silverlight/2.1/samples/start.htm#AreasAndLengths) and the "Line Length" (http://help.arcgis.com/en/webapi/silverlight/2.1/samples/start.htm#Lengths)
I've add a button to clear the graphics and switch back and fourth between the two but I can't seem to figure out how to get out of them.  I mean what do I need to call to get back to the normal mouse clicks....so the left mouse click stops drawing line or polys and can pan or zoom (like the default mouse actions.).....

Thanks
0 Kudos
NathalieNeagle
Regular Contributor
I'm still in need of the question I posted eailer but no I ran into another problem so I was hoping if someone was kind enough to answer one maybe they have the knowledge to do both.

So I've implemented the "area and perimeter" (http://help.arcgis.com/en/webapi/silverlight/2.1/samples/start.htm#AreasAndLengths) and the "Line Length" (http://help.arcgis.com/en/webapi/silverlight/2.1/samples/start.htm#Lengths)
I've add a button to clear the graphics and switch back and fourth between the two but I can't seem to figure out how to get out of them.  I mean what do I need to call to get back to the normal mouse clicks....so the left mouse click stops drawing line or polys and can pan or zoom (like the default mouse actions.).....

Thanks



I just figured this out a second after I posted this question.  All I did was

 MyDrawObject.IsEnabled = false;


I'm still hoping someone can help me out with polygon area mis-calculations.

Thanks
NN
0 Kudos
NathalieNeagle
Regular Contributor
I'm using this example and it works great  in the example with projection 102100 but I'm using projection 4326 WGS 1984 esridecimaldegrees and my numbers are way off can someone tell what I need to change
buthttp://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AreasAndLengths

I think it is here  but not sure

   private void GeometryService_AreasAndLengthsCompleted(object sender, AreasAndLengthsEventArgs args)
        {
            //TODO: Geometry service not returning correct values, area unit seems invalid, may need to use data in 
            //planar coordinate space

            // convert results from meters into miles and sq meters into sq miles for our display
            double miles = args.Results.Lengths[0] * 0.0006213700922;
            double sqmi = Math.Abs(args.Results.Areas[0]) * 0.0000003861003;
            ResponseTextBlock.Text = String.Format("Polygon area: {0} sq. miles\nPolygon perimeter: {1} miles.", Math.Round(sqmi, 3), Math.Round(miles, 3));
        }



It seems like the perimeter area code is converting from meters to miles and sq miles and I need to convert decimal degrees to miles and sq miles.  I tried to change the caluclation but it doesn't work

double miles = args.Results.Lengths[0] * 0.0006213700922;
            double sqmi = Math.Abs(args.Results.Areas[0]) * 0.0000003861003;

Has anyone ran into this problem and solved it.  I would be super greatful.

Thanks
Nathalie
0 Kudos
ChristineZeller
Occasional Contributor
I'm having the same issue as Nathalie and I'm stuck.
I've also implemented the Area and Perimeter tool and I�??m also using the WGS 1984 projection (spatial ref 4326, units esriDecimalDegrees).  Can someone help Nathalie and me out and  let us know what to change to calculate a somewhat accurate area and line lengths
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AreasAndLengths

Thanks
Christine
0 Kudos
ChristopherHill
Deactivated User
Hello,

When you are calling the GeometryService.AreaAndLengthsAsync() method are you passing the units of measurement you want returned? The unit of measurement is defined using a Enumeration of type LinearUnit. there are parameters for length unit and area unit that you can pass to the function. if you do not pass any paramters the area and lengths will return in units of Spatial Reference (in your case degrees)

example:

GeometryService.AreaAndLengthsAsync(myGraphics,LinearUnit.Meters,LinearUnit.Meters,null);

so if you are just calling GeometryService.AreaAndLengthsAsync(myGraphics) you are going to get area and lengths in degrees.

AreaAndLengthsAsync(IList<Graphic> graphics,LinearUnit lengthUnit,LinearUnit areaUnit, object userToken)
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Geom...

LinearUnit Enum
http://help.arcgis.com/en/webapi/silverlight/apiref/ESRI.ArcGIS.Client~ESRI.ArcGIS.Client.Tasks.Line...
0 Kudos
NathalieNeagle
Regular Contributor
Hey Chris,

Thanks for your post so I'm think I'm really close.  I'm still getting really small numbers so I'm not sure if I'm missing something.

Here's what i'm doing.



        private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            ESRI.ArcGIS.Client.Geometry.Polygon polygon = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon;
            polygon.SpatialReference = MyMap.SpatialReference;
            Graphic graphic = new Graphic()
            {
                Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol,
                Geometry = polygon,
            };

            GeometryService geometryService =
                new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
            geometryService.AreasAndLengthsCompleted += GeometryService_AreasAndLengthsCompleted;
            geometryService.Failed += GeometryService_Failed;

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.Graphics.Add(graphic);

            List<Graphic> graphicList = new List<Graphic>();
            graphicList.Add(graphic);

 geometryService.AreasAndLengthsAsync(graphicList, LinearUnit.SurveyMile, LinearUnit.SurveyMile, null);

        }





        private void GeometryService_AreasAndLengthsCompleted(object sender, AreasAndLengthsEventArgs args)
           {

       ResponseTextBlock.Text = String.Format("Polygon area: {0} sq. miles\nPolygon perimeter: {1} miles.", Math.Round(args.Results.Areas[0], 3), Math.Round(args.Results.Lengths[0], 3));
        }





Nathalie
0 Kudos
ChristineZeller
Occasional Contributor
Yea I'm still getting a really small number.  I tried it slightly different than Nathalie but sounds like the same results.  Do you know what I am missing.


 private void MyDrawObject_DrawComplete(object sender, DrawEventArgs args)
        {
            ESRI.ArcGIS.Client.Geometry.Polygon polygon = args.Geometry as ESRI.ArcGIS.Client.Geometry.Polygon;
            polygon.SpatialReference = MyMap.SpatialReference;
            Graphic graphic = new Graphic()
            {
                Symbol = LayoutRoot.Resources["DefaultFillSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol,
                Geometry = polygon,
            };

            GeometryService geometryService =
                new GeometryService("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer");
            geometryService.AreasAndLengthsCompleted += GeometryService_AreasAndLengthsCompleted;
            geometryService.Failed += GeometryService_Failed;

            GraphicsLayer graphicsLayer = MyMap.Layers["MyGraphicsLayer"] as GraphicsLayer;
            graphicsLayer.Graphics.Add(graphic);

            List<Graphic> graphicList = new List<Graphic>();
            graphicList.Add(graphic);


           



            geometryService.AreasAndLengthsAsync(graphicList,LinearUnit.Meter, LinearUnit.Meter, null);

          

                 
                   }

        private void GeometryService_AreasAndLengthsCompleted(object sender, AreasAndLengthsEventArgs args)

        {
            //TODO: Geometry service not returning correct values, area unit seems invalid, may need to use data in 
            //planar coordinate space

               // convert results from meters into miles and sq meters into sq miles for our display
            double miles = args.Results.Lengths[0] * 0.0006213700922;
            double sqmi = Math.Abs(args.Results.Areas[0]) * 0.0000003861003;
            ResponseTextBlock.Text = String.Format("Polygon area: {0} sq. miles\nPolygon perimeter: {1} miles.", Math.Round(sqmi, 3), Math.Round(miles, 3));

 
        }





0 Kudos
NathalieNeagle
Regular Contributor
Christine, 
Did you make any more progress.  I'm still stuck.
Nathalie
0 Kudos
ChristopherHill
Deactivated User
Hi,

Both code samples are correct. Let me ask a few questions to pin point the problem you are both having.

Is the problem you are now having an issue with the lengths and area being returned do not seem to be the correct units? or are they correct units, but just seem to be off?

example: You request LinearUnit.Meters and it still returns Degrees? or You request LinearUnit.Meters and units are correct just the distances are off? 

have you tried verifying your geometry against the rest service itself?
http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/areasAndLengths

do the areas and lengths return the same values when you test against the REST service directly?
0 Kudos