Select to view content in your preferred language

Spatial Analysis tool for calculating length of polyline

1232
4
10-31-2010 07:21 AM
yatendrajaiswal
Emerging Contributor
Hi,
Please some one share how to write code for my requirement in ArcGIS Desktop.
My requirement
-To calculate lenghth of a polyline(with conditions)
-My polyline is passing(Overlaping) through diffrent polygons.
- I want to calculate length of polyline seperatly crossing on each polygon(overlaped lenght of polyline in each polygon)  .
I have three Polygon layers and one polyline.
polyline is passing through each polygon layers.
please share some ideas.
0 Kudos
4 Replies
RichardFairhurst
MVP Alum
Hi,
Please some one share how to write code for my requirement in ArcGIS Desktop.
My requirement
-To calculate lenghth of a polyline(with conditions)
-My polyline is passing(Overlaping) through diffrent polygons.
- I want to calculate length of polyline seperatly crossing on each polygon(overlaped lenght of polyline in each polygon)  .
I have three Polygon layers and one polyline.
polyline is passing through each polygon layers.
please share some ideas.


To get the help you need, please tell us the version you are programming for (9.2, 9.3.1, 10), minimum license level that the program must support (ArcView, ArcEditor, ArcInfo) and the preferred programming language you want it writen in (VBA, VB .Net, C .Net, etc).
0 Kudos
yatendrajaiswal
Emerging Contributor
To get the help you need, please tell us the version you are programming for (9.2, 9.3.1, 10), minimum license level that the program must support (ArcView, ArcEditor, ArcInfo) and the preferred programming language you want it writen in (VBA, VB .Net, C .Net, etc).


Hi,
Thanks for reply
Its for ArcInfo 9.2 in C#...
0 Kudos
ChrisWelch
Emerging Contributor
I don't know how to do it, but I would try figuring out at which vertex the line snaps to a polygon and summing the distance between vertices until you get to another point where it snaps.

So if it enters at vertex 20 and exits at 25, sum the distance from 20-25.

Just a thought.
0 Kudos
yatendrajaiswal
Emerging Contributor
Hope This Helps
In This example onle road layer and 2 polygon layers are on map.
user selecting road on map.
loop through selected roads.
using spatial filter find  intersected polygons with road
loop through all intersected polygon.
using topological operator to get intersected road in each polygon and its lenght

display result

{
IEnumFeature penum;
IFeature Polyfeat;
IPolyline ppoly;
ISpatialFilter psp;
int linelen;
int polygon1len;

int polygon2len;


penum = mxd.FocusMap.FeatureSelection as IEnumFeature;
Polyfeat = penum.Next();

while (Polyfeat != null)
            {
                if (Polyfeat.Class.AliasName == "ROAD")
                 {

                    ppoly = Polyfeat.Shape as IPolyline;
                    MessageBox.Show("Road = " + ppoly.Length);
                    psp = new SpatialFilter();
                    psp.Geometry = ppoly;
                    psp.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                    for (int i = 0; i <= mxd.FocusMap.LayerCount - 1; i++)
                    {
                        IFeatureLayer polylayer = mxd.FocusMap.get_Layer(i) as  
                            ESRI.ArcGIS.Carto.FeatureLayer;
                        IFeatureClass polyclass = polylayer.FeatureClass;
                        if (polyclass.ShapeType == esriGeometryType.esriGeometryPolygon)
                        {
                            IFeatureCursor polycur = polyclass.Search(psp, false);
                            IFeature polyfeat = polycur.NextFeature();
                            while (polyfeat != null)
                            {
                                //ITopologicalOperator polytopoop = polyfeat.Shape;
                                ITopologicalOperator lineoperat = ppoly as ITopologicalOperator;
                                IGeometry linegeom = lineoperat.Intersect(polyfeat.Shape, esriGeometryDimension.esriGeometry1Dimension);
                                IPolyline newpoly = linegeom as IPolyline;
                                if (polyfeat.Class.AliasName == "Polygon1")
                                {
                                    polygon1len += newpoly.Length;
                                }
                                else
                                {
                                    polygon2len += newpoly.Length;
                                }
                                linelen += newpoly.Length;
                                //MessageBox.Show("" + newpoly.Length);

                                polyfeat = polycur.NextFeature();
                            }

                        }
                    }
    MessageBox.Show("Road name = " + ppoly.Length + ", INTERSECTION LEN = " + linelen + ", Polygon1 " + polygon1len + "(" + (polygon1len * 100) / linelen + "%) , Polygon2 len " + polygon2len    + "(" + (polygon2len * 100) / linelen + "%)");

                }
                Polyfeat = penum.Next();
                linelen = 0;
                polygon1len = 0;
                polygon2len = 0;
            }
}



Thanks & Regards
Jassi...
0 Kudos