Esempio n. 1
0
        public static IGeometry FromFlatbuf(Feature feature, GeometryType type, byte dimensions)
        {
            var coords          = feature.GetCoordsArray();
            var lengths         = feature.GetLengthsArray();
            var ringLengths     = feature.GetRingLengthsArray();
            var ringCounts      = feature.GetRingCountsArray();
            var sequenceFactory = new PackedCoordinateSequenceFactory();

            var factory = new GeometryFactory();

            switch (type)
            {
            case GeometryType.Point:
                return(factory.CreatePoint(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.MultiPoint:
                return(factory.CreateMultiPoint(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.LineString:
                return(factory.CreateLineString(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.MultiLineString:
                return(ParseFlatbufMultiLineString(lengths, coords, dimensions));

            case GeometryType.Polygon:
                return(ParseFlatbufPolygon(ringLengths, coords, dimensions));

            case GeometryType.MultiPolygon:
                return(ParseFlatbufMultiPolygon(lengths, ringLengths, ringCounts, coords, dimensions));

            default: throw new ApplicationException("FromFlatbuf: Unsupported geometry type");
            }
        }
Esempio n. 2
0
        static IPolygon ParseFlatbufPolygon(uint[] ends, double[] coords, byte dimensions)
        {
            if (ends == null)
            {
                return(ParseFlatbufPolygonSingleRing(coords, dimensions));
            }
            var  sequenceFactory = new PackedCoordinateSequenceFactory();
            var  factory         = new GeometryFactory(sequenceFactory);
            var  arraySegment    = new ArraySegment <double>(coords);
            var  linearRings     = new List <ILinearRing>();
            uint offset          = 0;

            for (var i = 0; i < ends.Length; i++)
            {
                var end        = ends[i] << 1;
                var ringCoords = coords.Skip((int)offset).Take((int)end).ToArray();
                var linearRing = factory.CreateLinearRing(sequenceFactory.Create(ringCoords, dimensions));
                linearRings.Add(linearRing);
                offset = end;
            }
            var shell = linearRings.First();
            var holes = linearRings.Skip(1).ToArray();

            return(factory.CreatePolygon(shell, holes));
        }
Esempio n. 3
0
        static IMultiLineString ParseFlatbufMultiLineStringSinglePart(double[] coords, byte dimensions)
        {
            var sequenceFactory = new PackedCoordinateSequenceFactory();
            var factory         = new GeometryFactory(sequenceFactory);
            var lineString      = factory.CreateLineString(sequenceFactory.Create(coords, dimensions));

            return(factory.CreateMultiLineString(new [] { lineString }));
        }
Esempio n. 4
0
        public static IGeometry FromFlatbuf(Geometry geometry, GeometryType type)
        {
            byte dimensions = 2;
            var  factory    = new GeometryFactory();

            if (type == GeometryType.Unknown)
            {
                type = geometry.Type;
            }

            switch (type)
            {
            case GeometryType.MultiPolygon:
                int       partsLength = geometry.PartsLength;
                Polygon[] polygons    = new Polygon[partsLength];
                for (int i = 0; i < geometry.PartsLength; i++)
                {
                    polygons[i] = (Polygon)FromFlatbuf(geometry.Parts(i).Value, GeometryType.Polygon);
                }
                return(factory.CreateMultiPolygon(polygons));
            }

            var coords          = geometry.GetXyArray();
            var ends            = geometry.GetEndsArray();
            var sequenceFactory = new PackedCoordinateSequenceFactory();

            switch (type)
            {
            case GeometryType.Point:
                return(factory.CreatePoint(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.MultiPoint:
                return(factory.CreateMultiPoint(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.LineString:
                return(factory.CreateLineString(sequenceFactory.Create(coords, dimensions)));

            case GeometryType.MultiLineString:
                return(ParseFlatbufMultiLineString(ends, coords, dimensions));

            case GeometryType.Polygon:
                return(ParseFlatbufPolygon(ends, coords, dimensions));

            default: throw new ApplicationException("FromFlatbuf: Unsupported geometry type");
            }
        }
Esempio n. 5
0
        static IPolygon ParseFlatbufPolygonSingleRing(double[] coords, byte dimensions)
        {
            var sequenceFactory = new PackedCoordinateSequenceFactory();
            var factory         = new GeometryFactory(sequenceFactory);
            var shell           = factory.CreateLinearRing(sequenceFactory.Create(coords, dimensions));

            return(factory.CreatePolygon(shell));
        }
        public void TestCopyToSmallerDim()
        {
            var csFactory = new PackedCoordinateSequenceFactory();
            var cs3D      = CreateTestSequence(csFactory, 10, 3);
            var cs2D      = csFactory.Create(10, 2, 0);

            CoordinateSequences.Copy(cs3D, 0, cs2D, 0, cs2D.Count);
            Assert.IsTrue(CoordinateSequences.IsEqual(cs2D, cs3D));
        }
Esempio n. 7
0
        public void TestCopyToLargerDim()
        {
            PackedCoordinateSequenceFactory csFactory = new PackedCoordinateSequenceFactory();
            ICoordinateSequence             cs2D      = CreateTestSequence(csFactory, 10, 2);
            ICoordinateSequence             cs3D      = csFactory.Create(10, 3);

            CoordinateSequences.Copy(cs2D, 0, cs3D, 0, cs3D.Count);
            Assert.IsTrue(CoordinateSequences.IsEqual(cs2D, cs3D));
        }
Esempio n. 8
0
        static IMultiLineString ParseFlatbufMultiLineString(uint[] lengths, double[] coords, byte dimensions)
        {
            if (lengths == null)
            {
                return(ParseFlatbufMultiLineStringSinglePart(coords, dimensions));
            }
            var sequenceFactory = new PackedCoordinateSequenceFactory();
            var factory         = new GeometryFactory(sequenceFactory);
            var arraySegment    = new ArraySegment <double>(coords);

            IList <ILineString> lineStrings = new List <ILineString>();
            uint offset = 0;

            foreach (var length in lengths)
            {
                var lineStringCoords = arraySegment.Skip((int)offset).Take((int)length).ToArray();
                var lineString       = factory.CreateLineString(sequenceFactory.Create(lineStringCoords, dimensions));
                lineStrings.Add(lineString);
                offset += length;
            }
            return(factory.CreateMultiLineString(lineStrings.ToArray()));
        }
Esempio n. 9
0
        static IMultiLineString ParseFlatbufMultiLineString(uint[] ends, double[] coords, byte dimensions)
        {
            if (ends == null)
            {
                return(ParseFlatbufMultiLineStringSinglePart(coords, dimensions));
            }
            var sequenceFactory = new PackedCoordinateSequenceFactory();
            var factory         = new GeometryFactory(sequenceFactory);
            var coordsSpan      = coords.AsSpan();

            IList <ILineString> lineStrings = new List <ILineString>();
            uint offset = 0;

            for (var i = 0; i < ends.Length; i++)
            {
                var end = ends[i] << 1;
                var lineStringCoords = coordsSpan.Slice((int)offset, (int)(end - offset)).ToArray();
                var lineString       = factory.CreateLineString(sequenceFactory.Create(lineStringCoords, dimensions));
                lineStrings.Add(lineString);
                offset = end;
            }
            return(factory.CreateMultiLineString(lineStrings.ToArray()));
        }