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");
            }
        }
Beispiel #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));
        }
Beispiel #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 }));
        }
Beispiel #4
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));
        }
Beispiel #6
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));
        }
        public void TestOrdinates(
            [Values(2, 3, 4)] int dimension,
            [Values(Ordinates.XY, Ordinates.XYZ, Ordinates.XYZM)] Ordinates ordinates)
        {
            var factory = new PackedCoordinateSequenceFactory(
                PackedCoordinateSequenceFactory.PackedType.Double,
                dimension);

            Assert.AreEqual(ordinates, factory.Ordinates);
        }
Beispiel #8
0
        public void TestRunPtInRing4d()
        {
            var cs = new PackedCoordinateSequenceFactory(PackedCoordinateSequenceFactory.PackedType.Double)
                     .Create(new double[] {
                0.0, 0.0, 0.0, 0.0,
                10.0, 0.0, 0.0, 0.0,
                5.0, 10.0, 0.0, 0.0,
                0.0, 0.0, 0.0, 0.0
            }, 4, 1);

            Assert.AreEqual(Location.Interior, RayCrossingCounter.LocatePointInRing(new Coordinate(5.0, 2.0), cs));
        }
        // Use map to restore M values on the coordinate array
        private CoordinateSequence restoreDim4(CoordinateSequence cs, Dictionary <Coordinate, Double> map)
        {
            CoordinateSequence seq = new PackedCoordinateSequenceFactory(PackedCoordinateSequenceFactory.PackedType.Double).Create(cs.Count, 4);

            for (int i = 0; i < cs.Count; i++)
            {
                seq.SetOrdinate(i, 0, cs.GetOrdinate(i, 0));
                seq.SetOrdinate(i, 1, cs.GetOrdinate(i, 1));
                seq.SetOrdinate(i, 2, cs.GetOrdinate(i, 2));
                Double d = map[cs.GetCoordinate(i)];
                seq.SetOrdinate(i, 3, d == null ? Double.NaN : d);
            }
            return(seq);
        }
Beispiel #10
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");
            }
        }
        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()));
        }
Beispiel #12
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()));
        }
        static IMultiPolygon ParseFlatbufMultiPolygon(uint[] lengths, uint[] ringLengths, uint[] ringCounts, double[] coords, byte dimensions)
        {
            var sequenceFactory = new PackedCoordinateSequenceFactory();
            var factory         = new GeometryFactory(sequenceFactory);
            var polygons        = new List <IPolygon>();

            if (lengths == null)
            {
                var polygon = ParseFlatbufPolygon(ringLengths, coords, dimensions);
                polygons.Add(polygon);
            }
            else
            {
                var  arraySegment = new ArraySegment <double>(coords);
                uint offset       = 0;
                uint ringOffset   = 0;
                for (int i = 0; i < lengths.Length; i++)
                {
                    var    length           = lengths[i];
                    var    ringCount        = ringCounts[i];
                    uint[] ringLengthSubset = null;
                    if (ringCount > 1)
                    {
                        var ringLengthsSegment = new ArraySegment <uint>(ringLengths).Skip((int)ringOffset).Take((int)ringCount).ToArray();
                        ringLengthSubset = ringLengths;
                    }
                    ringOffset += ringCount;

                    var linearRingCoords = arraySegment.Skip((int)offset).Take((int)length).ToArray();
                    var polygon          = ParseFlatbufPolygon(ringLengthSubset, linearRingCoords, dimensions);
                    polygons.Add(polygon);
                    offset += length;
                }
            }

            return(factory.CreateMultiPolygon(polygons.ToArray()));
        }