Determination of polyline length

586
2
Jump to solution
03-29-2022 05:16 AM
DavidMrázek
Occasional Contributor II

Hello, I have a question. I try to name the polygons according to the location of the points in them. But some have two points with different names, and if they have one and one name, I would like to decide according to which polygon they have a border. This is not the whole problem, but the problem occurs when they have a boundary with more polygons. I would like to do this in such a way that I find the longest border with the second polygon. I know everything to do until it's time to compare the lines. I don't know how to store both the length of the line and its name in the list. Would anyone have advice?

 

Here is the code:

 foreach (var oid in oids)//a list of polygons with multiple identical names by OID
                {
                    QueryFilter qFil = new QueryFilter();
                    qFil.WhereClause = "OBJECTID =" + oid.ToString();
                    var polygonSearch = fcPlochy.Search(qFil);
                    while (polygonSearch.MoveNext())
                    {
                        var feature = polygonSearch.Current as Feature;
                       var geometry=feature.GetShape() as Polygon;
                        var polyline = new PolylineBuilder(geometry).ToGeometry();
                        var spatialQueryInter = new SpatialQueryFilter()
                        {
                            FilterGeometry = geometry,
                            SpatialRelationship = SpatialRelationship.Touches,
                        };
                        TableDefinition tableDefinition1 = fcPlochy.GetDefinition();
                        var polyCursor4 = fcPlochy.Search(spatialQueryInter);
                        int namePolygons = tableDefinition1.FindField(field);
                        while (polyCursor4.MoveNext())//this is how it works for one adjacent polygon
                        {
                            var newFeature = polyCursor4.Current as Feature;
                            var newGeometry = newFeature.GetShape() as Polygon;
                            var polylineNew = new PolylineBuilder(newGeometry).ToGeometry();
                            Row row2 = polyCursor4.Current;
                            Geometry g = GeometryEngine.Instance.Intersection(polyline, polylineNew);
                            Polyline result = g as Polyline;
                            lineLength.Add(result);
                            string namePolygon = row2.GetOriginalValue(namePolygons) as String;
                            feature[newRow] = namePolygon;
                            feature.Store();
                        }
                    }
                }

 

Thank you

David

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi,

You could store the length of the line and its name in the list of Tuple's

var tupleList = new List<Tuple<int, string>>();
tupleList.Add(Tuple.Create( 1, "cow" ));
tupleList.Add(Tuple.Create( 5, "chickens" ));
tupleList.Add(Tuple.Create( 1, "airplane" ));

If your names are unique you could store your information in Dictionary<string, int>

View solution in original post

2 Replies
GKmieliauskas
Esri Regular Contributor

Hi,

You could store the length of the line and its name in the list of Tuple's

var tupleList = new List<Tuple<int, string>>();
tupleList.Add(Tuple.Create( 1, "cow" ));
tupleList.Add(Tuple.Create( 5, "chickens" ));
tupleList.Add(Tuple.Create( 1, "airplane" ));

If your names are unique you could store your information in Dictionary<string, int>

DavidMrázek
Occasional Contributor II

Thank you very much, I was looking for complexities behind it and this is how easy and fast it is, thanks again.

0 Kudos