public static SpatialHashSearcher <SegmentIndex> CreateSpatialSearcher(
            MultiLinestring multiLinestring, double?knownAverageSegmentLength = null)
        {
            if (multiLinestring.SegmentCount < _segmentCountThreshold)
            {
                return(null);
            }

            double gridSize;

            if (knownAverageSegmentLength != null)
            {
                gridSize = EstimateOptimalGridSize(knownAverageSegmentLength.Value);
            }
            else
            {
                gridSize =
                    multiLinestring.SegmentCount > 0
                                                ? EstimateOptimalGridSize(multiLinestring.GetLinestrings())
                                                : 100;
            }

            var result = new SpatialHashSearcher <SegmentIndex>(
                multiLinestring.XMin, multiLinestring.YMin,
                gridSize, multiLinestring.SegmentCount, 5);

            Populate(result, multiLinestring);

            return(result);
        }
 private static void Populate(SpatialHashSearcher <int> spatialSearcher,
                              Linestring linestring)
 {
     for (var i = 0; i < linestring.SegmentCount; i++)
     {
         Line3D line = linestring[i];
         spatialSearcher.Add(i, line.XMin, line.YMin, line.XMax, line.YMax);
     }
 }
Example #3
0
 private static void Populate(SpatialHashSearcher <int> spatialSearcher,
                              IPointList pointList)
 {
     for (var i = 0; i < pointList.PointCount; i++)
     {
         IPnt pnt = pointList.GetPoint(i);
         spatialSearcher.Add(i, pnt.X, pnt.Y, pnt.X, pnt.Y);
     }
 }
        public static SpatialHashSearcher <int> CreateSpatialSearcher(
            Linestring forLinestring, double gridSize)
        {
            var result = new SpatialHashSearcher <int>(
                forLinestring.XMin, forLinestring.YMin,
                gridSize, forLinestring.SegmentCount, 5);

            Populate(result, forLinestring);

            return(result);
        }
Example #5
0
        public static SpatialHashSearcher <int> CreateSpatialSearcher <TP>(
            Multipoint <TP> multipoint, double gridSize) where TP : IPnt
        {
            var result = new SpatialHashSearcher <int>(
                multipoint.XMin, multipoint.YMin,
                gridSize, multipoint.PointCount, 5);

            Populate(result, multipoint);

            return(result);
        }
        public static SpatialHashSearcher <T> CreateSpatialSearcher(
            [NotNull] IList <T> values,
            Func <T, EnvelopeXY> getBoundsFunc,
            double gridSize = double.NaN)
        {
            Assert.ArgumentCondition(values.Count > 0, "Empty value list");

            List <EnvelopeXY> valueEnvelopes =
                values.Select(getBoundsFunc).ToList();

            EnvelopeXY fullExtent;
            double     averageEnvLateralLength;

            GetEnvelopeStatistics(valueEnvelopes, out fullExtent,
                                  out averageEnvLateralLength);

            if (double.IsNaN(averageEnvLateralLength))
            {
                if (double.IsNaN(gridSize))
                {
                    throw new ArgumentException(
                              "Cannot derive grid size from values, please provide a grid size > 0.");
                }

                averageEnvLateralLength = gridSize;
            }

            Assert.NotNull(fullExtent);

            double maxTileCount = (fullExtent.Width * fullExtent.Height) /
                                  (averageEnvLateralLength * averageEnvLateralLength);

            if (double.IsNaN(gridSize))
            {
                gridSize = averageEnvLateralLength * 2;
            }

            double estimatedItemsPerTile = maxTileCount / values.Count;

            var result =
                new SpatialHashSearcher <T>(
                    fullExtent.XMin, fullExtent.YMin, gridSize, (int)maxTileCount,
                    estimatedItemsPerTile);

            // populate
            for (int i = 0; i < values.Count; i++)
            {
                result.Add(values[i], valueEnvelopes[i]);
            }

            return(result);
        }
        public static SpatialHashSearcher <SegmentIndex> CreateSpatialSearcher(
            MultiLinestring multiLinestring, double gridSize)
        {
            if (multiLinestring.SegmentCount < _segmentCountThreshold)
            {
                return(null);
            }

            var result = new SpatialHashSearcher <SegmentIndex>(
                multiLinestring.XMin, multiLinestring.YMin,
                gridSize, multiLinestring.SegmentCount, 5);

            Populate(result, multiLinestring);

            return(result);
        }
        private static void Populate(
            SpatialHashSearcher <SegmentIndex> spatialSearcher,
            MultiLinestring multiLinestring)
        {
            for (int i = 0; i < multiLinestring.Count; i++)
            {
                var linestring = multiLinestring.GetLinestring(i);

                for (var j = 0; j < linestring.SegmentCount; j++)
                {
                    Line3D line = linestring[j];
                    spatialSearcher.Add(new SegmentIndex(i, j),
                                        line.XMin, line.YMin, line.XMax, line.YMax);
                }
            }
        }