Select to view content in your preferred language

Area And Perimeter

4922
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
Chris,

Thanks for the reply.

For testing sake, I started over straight from the SDK example.
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AreasAndLengths

The only code I changed was:

I change the service to use ESRI DECIMAL DEGREEs

  <esri:ArcGISTiledMapServiceLayer ID="StreetMapLayer"
          Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_Street_Map_2D/MapServer" />
         <esri:GraphicsLayer ID="MyGraphicsLayer" />


and I commented out the setting of static world mecator extent.

  private static ESRI.ArcGIS.Client.Projection.WebMercator mercator =
            new ESRI.ArcGIS.Client.Projection.WebMercator();


and

  ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                    new ESRI.ArcGIS.Client.Geometry.Envelope(
                mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)) as MapPoint,
                mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;





Then I changed the code that you told me to change to:

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


Basically I'm drawing a polygon around North America and its stating 0 sq miles and .003 polygon perimeter.

Nathalie
0 Kudos
ChristineZeller
Occasional Contributor
Chris,

I'm not sure how to verify the geometry against the rest service itself?
http://sampleserver3.arcgisonline.co...reasAndLengths
I'm not sure what to put in for polygon and length values.

My problem seems very similar to Nathalie's, I also just took the time to start from scratch but I'm trying to convert to meters and then do the calculation to miles.....unlike Nathalie just going straight to miles and commenting out the meters to miles math conversion.  I'm getting very similar results as Nathalie stated no matter how big I make my polygon I get 0 sq miles and .00? perimeter. 

I can also post my code but at this point like Nathalie I'm trying to work with the bare bones and just using the sdk example. 

I'm commenting out the lines

private static ESRI.ArcGIS.Client.Projection.WebMercator mercator =
            new ESRI.ArcGIS.Client.Projection.WebMercator();

should I be declaring the 4326 projection


Also like Nathalie stated instead of using this service
Url="http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"

I'm using

http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer


I'm still doing

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));


        }

Not Sure what to do.

Thanks
Christine
0 Kudos
ChristineZeller
Occasional Contributor
Nathalie,

Have you made any progress?

Chris,

Do you have any other suggestions based on what Nathalie and I have posted.  By the sounds of it seems like this should be working?

Christine
0 Kudos
JenniferNery
Esri Regular Contributor
You can test if you will get the same results if you made your request directly to the REST service as you would in your SL app, this way...

1. Download Fiddler from: http://www.fiddler2.com/fiddler2/version.asp, if you don't have it already.
2. Copy the query parameters from Fiddler's Inspectors WebForms section (as seen in the attached screenshot).
3. From your browser, go to:  http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer/areasAndLengths and use the same parameters retrieved from step 2.
0 Kudos
ChristineZeller
Occasional Contributor
Jennifer,

Thanks for the reply.  I walked through your example and I was able verify my geometry results against the rest service itself.  I've attached the screen shot.  I'm still getting very small numbers (Zero) or negitive numbers (when hitting the rest itself) and I'm selecting entire countries or even continents. 

It seems like Nathalie and myself are doing the exact samething and getting the exact same results.

Here's my delima/question/request.  We both started from sctrach and are using the SDK example with no other code.  All we are doing are trying to use the ESRI StreetMap World 2D service (http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer), which uses 4326 instead of the World_Street_Map (http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer), which uses the 102100 spatial ref.

In the code behind we are both commenting out the following lines, which seems like it is just constraining the extent and setting the ref.....in our code our ref is defined by the one and only service add in our xaml (spatial 4326).

  ESRI.ArcGIS.Client.Geometry.Envelope initialExtent =
                    new ESRI.ArcGIS.Client.Geometry.Envelope(
                mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-130, 20)) as MapPoint,
                mercator.FromGeographic(
                    new ESRI.ArcGIS.Client.Geometry.MapPoint(-65, 55)) as MapPoint);

            initialExtent.SpatialReference = new SpatialReference(102100);

            MyMap.Extent = initialExtent;



Also like Chris suggest we are both changing the line of code:
GeometryService.AreaAndLengthsAsync(myGraphics), and Chris has verified that myself and Nathalie are both doing it correctly, each are different but both correct.

So it seems like something else is going on.  Has someone else successfully changed the SDK example: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AreasAndLengths to use the 4326 ref.
0 Kudos
NathalieNeagle
Regular Contributor
Christine,
Your last description and explanation was exactly what I keep thinking.  I have not made any progress.  I�??m thinking we are missing some easy thing and sooner than later someone will direct us to the light.
Nathalie
0 Kudos
JenniferNery
Esri Regular Contributor
Try to draw your polygon in clockwise direction instead of counterclockwise or call simplify on the graphic (http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Simplify) before GeometryService.AreaAndLengthsAsync()
0 Kudos
RyanDanford
Emerging Contributor
Nathalie,

I encountered the same problem with a project and found that I could get accurate results by reprojecting the drawn graphic then measuring off the reprojection results. The approach is a bit slower, but you will get the results expected.
0 Kudos
NathalieNeagle
Regular Contributor
Jennifer and Ryan Thanks for the replies!

Nathalie,

I encountered the same problem with a project and found that I could get accurate results by reprojecting the drawn graphic then measuring off the reprojection results. The approach is a bit slower, but you will get the results expected.


Ryan, would you mind sharing your code.  I've had this problem for awhile now and I just can't seem to get it solved.  My experience coding level is low so I'm not sure how to go about what you are suggesting.


Jennifer

It does not matter which way I draw the polygon (clockwise or counterclockwise)  I took a look at the link you post and I really have no clue what to do with that can you point me in a more specific direction.

"Try to draw your polygon in clockwise direction instead of counterclockwise or call simplify on the graphic (http://help.arcgis.com/en/webapi/sil...t.htm#Simplify) before GeometryService.AreaAndLengthsAsync() "
0 Kudos
JenniferNery
Esri Regular Contributor
I ran Fiddler while running our SDK sample on Area and Perimeter and I was able to reproduce the negative Area by drawing the polygon in counter-clockwise direction.  This is without any change to the code. When I drew the polygon in clockwise direction, the Area I get is correct. 

The best way to avoid incorrect values for Area is to call SimplifyAsync() on the Geometry after draw is complete before calling AreaAndLengthAsync().  You can also try to draw in clockwise direction and you should see the difference in values.

This is the link to the Simply sample:
http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#Simplify

Another option is to use the Editor's Add instead of the Draw object, this will ensure that the polygon is simplified before adding to your layer. Look at the Add Polygon button in this sample: http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#EditToolsExplicitSave
If you will be using this approach on GraphicsLayer, the CommandParameter need to be set to the polygon symbol, the GraphicsLayer need to have its ID property set, the button's DataContext need to be set to an Editor with Map property bound to the map that contains this GraphicsLayer, and LayerIDs property set to the ID of the GraphicsLayer that will contain the polygon.
0 Kudos