예제 #1
0
        /// <summary>
        /// Reads a LineString or multiple LineString geometries using the specified reader.
        /// </summary>
        /// <typeparam name="TMultipoint"></typeparam>
        /// <typeparam name="TLinestring"></typeparam>
        /// <typeparam name="TPoint"></typeparam>
        /// <param name="reader"></param>
        /// <param name="geometryType"></param>
        /// <param name="ordinates"></param>
        /// <param name="geometryBuilder"></param>
        /// <returns></returns>
        protected static IEnumerable <TLinestring> ReadLinestrings <TMultipoint, TLinestring, TPoint>(
            [NotNull] BinaryReader reader,
            WkbGeometryType geometryType,
            Ordinates ordinates,
            [NotNull] GeometryBuilderBase <TMultipoint, TLinestring, TPoint> geometryBuilder)
        {
            IEnumerable <TLinestring> linestrings;

            if (geometryType == WkbGeometryType.MultiLineString ||
                geometryType == WkbGeometryType.Polygon ||
                geometryType == WkbGeometryType.MultiPolygon)
            {
                linestrings =
                    ReadLinestrings(reader, ordinates, geometryBuilder);
            }

            else if (geometryType == WkbGeometryType.LineString)
            {
                TLinestring linestring = ReadLinestringCore(reader, ordinates, geometryBuilder);

                linestrings = new[] { linestring };
            }
            else
            {
                throw new NotSupportedException(
                          $"Cannot read {geometryType} as lineString or multiple lineStrings.");
            }

            return(linestrings);
        }
예제 #2
0
        /// <summary>
        /// Reads multiple (>1) line strings, including the initial count.
        /// </summary>
        /// <typeparam name="TMultipoint"></typeparam>
        /// <typeparam name="TLinestring"></typeparam>
        /// <typeparam name="TPoint"></typeparam>
        /// <param name="reader"></param>
        /// <param name="ordinates"></param>
        /// <param name="geometryBuilder"></param>
        /// <returns></returns>
        private static IEnumerable <TLinestring> ReadLinestrings <TMultipoint, TLinestring, TPoint>(
            [NotNull] BinaryReader reader,
            Ordinates ordinates,
            [NotNull] GeometryBuilderBase <TMultipoint, TLinestring, TPoint> geometryBuilder)
        {
            int linestringCount = checked ((int)reader.ReadUInt32());

            return(ReadLinestrings(reader, ordinates, linestringCount, geometryBuilder));
        }
예제 #3
0
        private static L ReadLinestringCore <L, P>(BinaryReader reader, Ordinates ordinates,
                                                   GeometryBuilderBase <L, P> geometryBuilder)
        {
            int pointCount = checked ((int)reader.ReadUInt32());

            IPointFactory <P> builder = geometryBuilder.GetPointFactory(ordinates);

            return(geometryBuilder.CreateLinestring(
                       ReadPointsCore(reader, ordinates, builder, pointCount), pointCount));
        }
예제 #4
0
 protected static IEnumerable <L> ReadLinestringsCore <L, P>(
     [NotNull] BinaryReader reader,
     Ordinates ordinates,
     int linestringCount,
     [NotNull] GeometryBuilderBase <L, P> geometryBuilder)
 {
     for (int i = 0; i < linestringCount; i++)
     {
         yield return(ReadLinestringCore(reader, ordinates, geometryBuilder));
     }
 }
예제 #5
0
        protected static TMultipoint ReadMultipointCore <TMultipoint, TLinestring, TPoint>(
            [NotNull] BinaryReader reader,
            Ordinates ordinates,
            int pointCount,
            [NotNull] GeometryBuilderBase <TMultipoint, TLinestring, TPoint> geometryBuilder)
        {
            IPointFactory <TPoint> builder = geometryBuilder.GetPointFactory(ordinates);

            const bool reReadPointTypes = true;

            IEnumerable <TPoint> readPointsCore =
                ReadPointsCore(reader, ordinates, builder, pointCount, reReadPointTypes);

            return(geometryBuilder.CreateMultipoint(readPointsCore, pointCount));
        }
예제 #6
0
        /// <summary>
        /// Reads multiple (>1) line strings, without the initial count.
        /// </summary>
        /// <typeparam name="TMultipoint"></typeparam>
        /// <typeparam name="TLinestring"></typeparam>
        /// <typeparam name="TPoint"></typeparam>
        /// <param name="reader"></param>
        /// <param name="expectedOrdinates"></param>
        /// <param name="linestringCount"></param>
        /// <param name="geometryBuilder"></param>
        /// <returns></returns>
        private static IEnumerable <TLinestring> ReadLinestrings <TMultipoint, TLinestring, TPoint>(
            [NotNull] BinaryReader reader,
            Ordinates expectedOrdinates,
            int linestringCount,
            [NotNull] GeometryBuilderBase <TMultipoint, TLinestring, TPoint> geometryBuilder)
        {
            for (int i = 0; i < linestringCount; i++)
            {
                ReadWkbType(reader, false,
                            out WkbGeometryType geometryType, out Ordinates ordinates);

                Assert.AreEqual(WkbGeometryType.LineString, geometryType,
                                "Unexpected geometry type");

                Assert.AreEqual(expectedOrdinates, ordinates,
                                "Linestring with inconsistent ordinates encountered.");

                yield return(ReadLinestringCore(reader, ordinates, geometryBuilder));
            }
        }