Select to view content in your preferred language

Spatial Query on two or more polygons for line feautures double counting....

1262
5
07-23-2012 01:27 PM
MosesAsuquo
Deactivated User
Hello all,

I am developing a silverlight application that calculates the lengths of all the line features (pipes) in one or more polygons. I am using both the spatial query task and the attribute query task to accomplish the task. In order words, i first get the geometry of the polygons in the first attribute query task and then use those returned geometries in the 2nd a spatial query task. Every thing works fine except that I'm getting double counting on line features (pipes) that crosses two polygons as a result my total length of line features is more due to double counting; this is because the default is using INTERSECTS instead of CONTAINS. Is there a functionality in arcgis for silverlight API that will automatically assign an intersecting line feature to one of the polygons based on the line's midpoint? This will help eliminate the double counting.

Please help! Any helpful suggestion will be much appreciated.

Thanks in advance.
0 Kudos
5 Replies
DominiqueBroux
Esri Frequent Contributor
this is because the default is using INTERSECTS instead of CONTAINS


You can set the SpatialRelationShip to define the spatial relationship to be applied while performning the query. 'Intersects' is the default but that can be changed.

That being said it's probably not that useful in your case since the lines crossing 2 polygons would no more be counted (instead of being double counted).

It's depending on your need.
For a line crossing 2 polygons, do you want to count the total line length with one polygon (e.g based on the line midpoind) or to split the length in 2 parts, one for each polygon?

In the second case, you can use the Intersect method of a geometry service that will clip your lines based on your polygon. You can then count the total length based on the clipped lines.

In the first case, you can also use the Intersect method but just to know if the midpoint of the line is inside the polygon and then affect the line length accordingly.

Hope this helps.
0 Kudos
MosesAsuquo
Deactivated User
Hi Dominique,

Oh, nice. Thanks a lot. The embedded link you provided is helpful. It appears i have more options from the different possible enum values of the SpatialRelationship:

Member                                           Description
esriSpatialRelContains             Part or all of a feature from feature class 1 is contained within a feature from feature class 2.
esriSpatialRelCrosses             The feature from feature class 1 crosses a feature from feature class 2.
esriSpatialRelEnvelopeIntersects The envelope of feature class 1 intersects with the envelope of feature class 2.
esriSpatialRelIndexIntersects     The envelope of the query feature class intersects the index entry for the target feature class.
esriSpatialRelIntersects             Part of a feature from feature class 1 is contained in a feature from feature class 2.
esriSpatialRelOverlaps             Features from feature class 1 overlap features in feature class 2.
esriSpatialRelRelation             Indicates that a spatial relationship function will be used.
esriSpatialRelTouches             The feature from feature class 1 touches the border of a feature from feature class 2.
esriSpatialRelWithin             The feature from feature class 1 is completely enclosed by the feature from feature class 2. 


I will like to implement the first case. if the midpoint of the line feature is inside one of the polygons it should count it as belonging to that polygon and not count it again as belonging to the other polygon even though the line feature intersects with both polygons. What i want is to calculate the total length of all the line features in a polygon (or it could be several polygons on the map based on the user selection). Here is a code snippet from the call to the QueryTask:

  private void QueryTaskService(Selection sel, ESRI.ArcGIS.Client.Geometry.Geometry geometry)
        {
            string serviceURL;

            if (GravityMain.Target == PipeQueryBuilder.AddIns.MyDatabaseService.Table.SSGRAVITYMAIN_MV)
                serviceURL = "http://mkgistempd01/ArcGIS/rest/services/RIVER/Sanitary_map/MapServer/62";
            else if (GravityMain.Target == PipeQueryBuilder.AddIns.MyDatabaseService.Table.SSPRESSURIZEDMAIN_MV)
                serviceURL = "http://mkgistempd01/ArcGIS/rest/services/RIVER/Sanitary_map/MapServer/64";
            else if (GravityMain.Target == PipeQueryBuilder.AddIns.MyDatabaseService.Table.SWGRAVITYMAIN_MV)
                serviceURL = "http://mkgistempd01/ArcGIS/rest/services/RIVER/Storm_map/MapServer/62";
            else
                serviceURL = "http://mkgistempd01/ArcGIS/rest/services/RIVER/Storm_map/MapServer/63";

            QueryTask queryTask = new QueryTask(serviceURL);
            queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted;
            queryTask.Failed += QueryTask_Failed;

            Query query = new ESRI.ArcGIS.Client.Tasks.Query();
            query.OutFields.Add("*");
            query.Geometry = geometry;
            query.SpatialRelationship = SpatialRelationship.esriSpatialRelIntersects;
            query.Where = form.constructWHERECLAUSE(sel);

            // Return geometry with result features
            query.ReturnGeometry = true;
            query.OutSpatialReference = MapApplication.Current.Map.SpatialReference;

            queryTask.ExecuteAsync(query, GravityMain._gMain.BoundaryGeometries[geometry]);
        }


I have just added the query.SpatialRelationship = SpatialRelationship.esriSpatialRelIntersects line of code but how do i specify that it uses the midpoint of the line feature as you explained in the first case using intersect??

Thanks again for the lead.
0 Kudos
MosesAsuquo
Deactivated User
Oh ,Dominique, how about what if i wanted to use the endpoint of the line features (pipes). In order words, which ever polygon the endpoint of the line feature falls, that line should be counted as belonging to that polygon and thereby avoiding double counting. How would one implement that in code??

Thanks again in advance.
0 Kudos
DominiqueBroux
Esri Frequent Contributor
My suggestion is :
  1) Do a query with Intersects relationship (i.e the default). This query will return all lines that could be counted for the polygon
  2) From the list of lines, create a list of points that will be used as reference for each line (i.e the midpoint, or the end point or whatever depending on your need).
  3) Use an intersect task to get the insersection between the polygon and this list of points. This task returns a list of graphics (the exact same number than in the initial list) but if a point doesn't intersect the polygon, the returned graphic will have a null geometry and extent.
  4) Sum the line length for each line that has a corresponding non null graphic.
0 Kudos
MosesAsuquo
Deactivated User
Thank you... I will implement this and let you know. I understand the idea and the steps.

Thanks.
0 Kudos