Beispiel #1
0
        public override IDictionary <string, object> Write(ISpatial value)
        {
            GeoJsonObjectWriter writer = new GeoJsonObjectWriter();

            value.SendTo(new ForwardingSegment((SpatialPipeline)writer));
            return(writer.JsonObject);
        }
        public void GeoJsonSimpleRoundTripTest()
        {
            var position = new GeographyPosition(12, 34, -12, -34);
            var coordinateSystem = CoordinateSystem.Geography(54321);

            var writer =  new GeoJsonObjectWriter();
            GeographyPipeline pipeline = (SpatialPipeline)writer;

            pipeline.SetCoordinateSystem(coordinateSystem);
            pipeline.BeginGeography(SpatialType.Point);
            pipeline.BeginFigure(position);
            pipeline.EndFigure();
            pipeline.EndGeography();

            var actualPipeline = new CallSequenceLoggingPipeline();
            var reader = new GeoJsonObjectReader(actualPipeline);
            reader.ReadGeography(writer.JsonObject);

            var expectedPipeline = new CallSequenceLoggingPipeline();

            // TODO: move the set of calls back into a delegate if the APIs come back together
            expectedPipeline.GeographyPipeline.SetCoordinateSystem(coordinateSystem);
            expectedPipeline.GeographyPipeline.BeginGeography(SpatialType.Point);
            expectedPipeline.GeographyPipeline.BeginFigure(position);
            expectedPipeline.GeographyPipeline.EndFigure();
            expectedPipeline.GeographyPipeline.EndGeography();

            actualPipeline.Verify(expectedPipeline);
        }
        private static void WriteGeoJsonTest(Action<TypeWashedPipeline> pipelineCalls, IDictionary<String, Object> expectedJsonObject, bool isGeometry, CoordinateSystem crs)
        {
            var w = new GeoJsonObjectWriter();
            TypeWashedPipeline p = isGeometry ?
                (TypeWashedPipeline)new TypeWashedToGeographyLongLatPipeline(new ForwardingSegment(w))
                : new TypeWashedToGeometryPipeline(new ForwardingSegment(w));

            p.SetCoordinateSystem(crs.EpsgId.Value);
            pipelineCalls(p);

            var actualObject = w.JsonObject;

            AddCoordinateSystem(expectedJsonObject, crs);
            AssertJsonObjectEquals(expectedJsonObject, actualObject);
        }