routing icon indicating copy to clipboard operation
routing copied to clipboard

Features/polygon intersection

Open pietervdvn opened this issue 6 years ago • 1 comments

Calculate a polygon intersection with a.IntersectionsWith(b).

Unions and differences are available under a.UnionWith(b) and a.DifferencesWith(b).

The surface area of a polygon can be found with a.SurfaceArea()

pietervdvn avatar Jun 22 '18 09:06 pietervdvn

Overall LGTM 👍

@pietervdvn, @xivk

I think in TestExtensions

        /// <summary>
        /// Loads a test network from geojson.
        /// </summary>
        private static IEnumerable<Itinero.LocalGeo.Coordinate> LoadTestPoints(string geoJson)
        {
            var geoJsonReader = new NetTopologySuite.IO.GeoJsonReader();
            var features = geoJsonReader.Read<FeatureCollection>(geoJson);

            foreach (var feature in features)
            {
                if(feature.Geometry is Point point)
                {
                    yield return new Itinero.LocalGeo.Coordinate((float)point.Coordinate.Y, (float)point.Coordinate.X);
                }
                else if(feature.Geometry is NetTopologySuite.Geometries.Polygon polygon)
                {
                    foreach(NetTopologySuite.Geometries.Coordinate coordinate in polygon.Coordinates)
                    {
                        yield return new Itinero.LocalGeo.Coordinate((float)coordinate.Y, (float)coordinate.X);
                    }
                }
            }
        }

Is needed for your LoadTestPolygon to get a polygon with more than 0 points.

I also don't think I see any validation for Polygon like Coordiate has but I assume that because it's made from Coordiates which must be valid?

Perhaps in Polygon

        /// <summary>
        /// Determines if the instance is valid
        /// </summary>
        /// <returns></returns>
        public bool IsValid()
        {
            //Hopefully no repeated points. (Perhaps a Distinct().Count()) would be able to be used instead
            //CheckTooFewPoints
            return ExteriorRing.Count + InteriorRings.Count >= 4;

            //CheckConsistentArea
            //IsSelfTouchingRingFormingHoleValid -> CheckNoSelfIntersectingRings
            //CheckHolesInShell
            //CheckHolesNotNested
            //CheckConnectedInteriors
        }

Also wanted to note that with the changes in Line that RouterTests.TestBicycleWithCyclenetwork then fails at Assert.IsNotNull(route.Value.From.From.From);

Also PolygonIntersection.FollowAlong

if (i == 0 && j == 1)
            {
                i = i;
            }

this code says when i is 0 and j is 1 set i to i which is already equal to 0....

juliusfriedman avatar May 24 '20 15:05 juliusfriedman