private static void ReadPointTest(PositionData data, CoordinateSystem coordinateSystem) { var target = new CallSequenceLoggingPipeline(); new GmlReader(target).ReadGeography(ExpectedPointGml(data, coordinateSystem)); PointPipelineBaseline(coordinateSystem, data).VerifyPipeline(target); }
public void Verify(CallSequenceLoggingPipeline expectedPipeline) { List<KeyValuePair<PipelineMethod, object>> expectedCalls = expectedPipeline.methodCalls; List<KeyValuePair<PipelineMethod, object>> actualCalls = this.methodCalls; SpatialTestUtils.AssertEqualContents(expectedCalls, actualCalls); }
public void ReadEmptyGeography_MultiPolygon() { var target = new CallSequenceLoggingPipeline(); new GmlReader(target).ReadGeography(ExpectedEmptyGml(SpatialType.MultiPolygon, CoordinateSystem.DefaultGeography)); MultiPolygonPipelineBaseline(CoordinateSystem.DefaultGeography, null).VerifyPipeline(target); }
public void Verify(CallSequenceLoggingPipeline expectedPipeline) { List <KeyValuePair <PipelineMethod, object> > expectedCalls = expectedPipeline.methodCalls; List <KeyValuePair <PipelineMethod, object> > actualCalls = this.methodCalls; SpatialTestUtils.AssertEqualContents(expectedCalls, actualCalls); }
public void Merge(CallSequenceLoggingPipeline target, bool keepAllSetCrsCalls = false) { // when merging two pipeline calls, the inner SetCoordinateSystem shouldn't be // merged. This is primarily used for constructing expected pipeline calls for collection types // from individual member types. Add a flag to this if another usage requires the full pipeline to be merged. this.methodCalls.AddRange(target.methodCalls.Where(kvp => keepAllSetCrsCalls || (kvp.Key != PipelineMethod.GeographySetCoordinateSystem && kvp.Key != PipelineMethod.GeometrySetCoordinateSystem))); }
private static void ReadCollectionTest(bool buildAsList) { var coordinateSystem = CoordinateSystem.Geography(0); PositionData[] data = { new PositionData(10, 10), new PositionData(20, 20) }; var payloadBuilder = new StringBuilder(); payloadBuilder.Append(GmlShapeElement("MultiGeometry", coordinateSystem.EpsgId)); BuildMultiGml(buildAsList ? "geometryMembers" : "geometryMember", buildAsList, payloadBuilder, data, (o, b) => BuildPointGml(o, b, null)); payloadBuilder.Append(GmlEndElement("MultiGeometry")); var xel = XElement.Parse(payloadBuilder.ToString()); var reader = xel.CreateReader(); ICommonLoggingPipeline expected = new GeographyLoggingPipeline(false); expected.SetCoordinateSystem(coordinateSystem); expected.BeginShape(SpatialType.Collection); expected.BeginShape(SpatialType.Point); expected.BeginFigure(10, 10, null, null); expected.EndFigure(); expected.EndShape(); expected.BeginShape(SpatialType.Point); expected.BeginFigure(20, 20, null, null); expected.EndFigure(); expected.EndShape(); expected.EndShape(); var target = new CallSequenceLoggingPipeline(); new GmlReader(target).ReadGeography(reader); expected.VerifyPipeline(target); }
private static void ReadMultiPolygonTest(CoordinateSystem coordinateSystem, params PositionData[][][] data) { var baseline = MultiPolygonPipelineBaseline(coordinateSystem, data); var target = new CallSequenceLoggingPipeline(); new GmlReader(target).ReadGeography(ExpectedMultiPolygonGml(data, coordinateSystem, true)); baseline.VerifyPipeline(target); target = new CallSequenceLoggingPipeline(); new GmlReader(target).ReadGeography(ExpectedMultiPolygonGml(data, coordinateSystem, false)); baseline.VerifyPipeline(target); }
public void ReadFullGlobe() { var target = new CallSequenceLoggingPipeline(); new GmlReader(target).ReadGeography(ExpectedFullGlobeGml(CoordinateSystem.DefaultGeography)); ICommonLoggingPipeline expected = new GeographyLoggingPipeline(false); expected.SetCoordinateSystem(CoordinateSystem.DefaultGeography); expected.BeginShape(SpatialType.FullGlobe); expected.EndShape(); expected.VerifyPipeline(target); }
private static void ReadPolygonTest(CoordinateSystem coordinateSystem, params PositionData[][] data) { var baseline = PolygonPipelineBaseline(coordinateSystem, data); var target = new CallSequenceLoggingPipeline(); // <LineString><posList>x1 y1 x2 y2 ...</posList></LineString> new GmlReader(target).ReadGeography(ExpectedPolygonGml(data, coordinateSystem, BuildPosList)); baseline.VerifyPipeline(target); target = new CallSequenceLoggingPipeline(); // <LineString><pos>x1 y1</pos><pos>x2 y2 ...</pos></LineString> new GmlReader(target).ReadGeography(ExpectedPolygonGml(data, coordinateSystem, BuildPosArray)); baseline.VerifyPipeline(target); target = new CallSequenceLoggingPipeline(); // <LineString><pointProperty><pos>x1 y1</pos></pointProperty><pointProperty><pos>x2 y2 ...</pos></pointProperty></LineString> new GmlReader(target).ReadGeography(ExpectedPolygonGml(data, coordinateSystem, BuildPointMembers)); baseline.VerifyPipeline(target); }
public GeometryLoggingPipeline() { this.pipeline = new CallSequenceLoggingPipeline(); this.drawGeometry = pipeline; }
public GeographyPipe(CallSequenceLoggingPipeline logger) { this.logger = logger; }
/// <summary> /// Creates a new instance of the GeographyLoggingPipeline. /// </summary> /// <param name="reverseCoordinates"> /// True if calls to BeginFigure and AddLine should reverse the first two coordinates before logging the call. /// </param> public GeographyLoggingPipeline(bool reverseCoordinates) { this.reverseCoordinates = reverseCoordinates; this.pipeline = new CallSequenceLoggingPipeline(); this.drawGeography = pipeline; }
private static void TestReadMethod(SpatialType spatialType, List<object> coordinates, bool isGeography, Func<List<object>, bool, ICommonLoggingPipeline> getExpectedPipeline) { int expectedPropertyCount; var jsonObject = GetGeoJson(spatialType, coordinates, out expectedPropertyCount); var expectedPipeline = getExpectedPipeline(coordinates, isGeography); var actualPipeline = new CallSequenceLoggingPipeline(); var geoJsonObjectReader = new GeoJsonObjectReader(actualPipeline); if (isGeography) { geoJsonObjectReader.ReadGeography(jsonObject); } else { geoJsonObjectReader.ReadGeometry(jsonObject); } expectedPipeline.VerifyPipeline(actualPipeline); }
private static void TestReadMethod(SpatialType[] spatialType, List<object>[] coordinates, bool isGeography, Func<Func<List<Object>, bool, ICommonLoggingPipeline>[], List<object>[], bool, ICommonLoggingPipeline> getExpectedPipeline, Func<List<Object>, bool, ICommonLoggingPipeline>[] innerGetExpectedPipeline) { // used for Collections int expectedPropertyCount; int epsgId = isGeography ? CoordinateSystem.DefaultGeography.EpsgId.Value : CoordinateSystem.DefaultGeometry.EpsgId.Value; var jsonObject = GetGeoJson(spatialType, coordinates, out expectedPropertyCount, epsgId); var expectedPipeline = getExpectedPipeline(innerGetExpectedPipeline, coordinates, isGeography); var actualPipeline = new CallSequenceLoggingPipeline(); var geoJsonObjectReader = new GeoJsonObjectReader(actualPipeline); if (isGeography) { geoJsonObjectReader.ReadGeography(jsonObject); } else { geoJsonObjectReader.ReadGeometry(jsonObject); } expectedPipeline.VerifyPipeline(actualPipeline); }
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); }
public void VerifyPipeline(CallSequenceLoggingPipeline actualPipeline) { actualPipeline.Verify(pipeline); }
private static void TestInvalidCrs(object crsMembers, string error) { var members = new Dictionary<string, object> { { GeoJsonConstants.TypeMemberName, GetGeoJsonTypeName(SpatialType.Point) }, { GeoJsonConstants.CrsMemberName, crsMembers } }; var actualPipeline = new CallSequenceLoggingPipeline(); SpatialTestUtils.VerifyExceptionThrown<ParseErrorException>(() => SendToPipeline(members, actualPipeline, false), error); }
private void TestSendToPipelineCollection(bool isGeography) { var members = new Dictionary<string, object>(); members.Add(GeoJsonConstants.TypeMemberName, GetGeoJsonTypeName(SpatialType.Collection)); var collectionItems = new List<IDictionary<string, object>>(); collectionItems.Add(GetJsonMembers(SpatialType.LineString, arrayOfMultiplePositions, null)); collectionItems.Add(GetJsonMembers(SpatialType.Polygon, arrayOfArrayMultipleElements, null)); members.Add(GeoJsonConstants.GeometriesMemberName, collectionItems.ConvertAll((o) => (object)o)); var actualPipeline = new CallSequenceLoggingPipeline(); SendToPipeline(members, actualPipeline, isGeography); var expectedPipeline = GetExpectedCollectionPipeline( new Func<List<object>, bool, ICommonLoggingPipeline>[] {GetExpectedLineStringPipeline, GetExpectedPolygonPipeline}, new[] {arrayOfMultiplePositions, arrayOfArrayMultipleElements}, isGeography); expectedPipeline.VerifyPipeline(actualPipeline); }
private static CallSequenceLoggingPipeline ExecuteSendToPipeline(SpatialType spatialType, IEnumerable<object> coordinates, bool isGeography = true, IDictionary<string, object> crs = null) { var members = GetJsonMembers(spatialType, coordinates, crs); var actualPipeline = new CallSequenceLoggingPipeline(); SendToPipeline(members, actualPipeline, isGeography); return actualPipeline; }
public void ErrorOnMissingCoordinatesMember() { var members = new Dictionary<string, object>(); members.Add(GeoJsonConstants.TypeMemberName, GetGeoJsonTypeName(SpatialType.LineString)); var pipeline = new CallSequenceLoggingPipeline(); // This error should occur regardless of if the pipeline is geography or geometry, so just pick one. var isGeography = true; SpatialTestUtils.VerifyExceptionThrown<ParseErrorException>(() => SendToPipeline(members, pipeline, isGeography), Strings.GeoJsonReader_MissingRequiredMember("coordinates")); }
public void SendToPipelineCollectionWhichResetsCrsInSubType() { var members = new Dictionary<string, object>(); var crs = CreateCrsMembersWithName(GeoJsonConstants.CrsValuePrefix + ":54321"); members.Add(GeoJsonConstants.TypeMemberName, GetGeoJsonTypeName(SpatialType.Collection)); members.Add(GeoJsonConstants.CrsMemberName, crs); var collectionItems = new List<IDictionary<string, object>> { GetJsonMembers(SpatialType.LineString, arrayOfMultiplePositions, crs), GetJsonMembers(SpatialType.Polygon, arrayOfArrayMultipleElements, crs) }; members.Add(GeoJsonConstants.GeometriesMemberName, collectionItems.ConvertAll((o) => (object)o)); var actualPipeline = new CallSequenceLoggingPipeline(); SendToPipeline(members, actualPipeline, true); var expectedPipeline = GetExpectedCollectionPipeline( new Func<List<object>, bool, ICommonLoggingPipeline>[] { (positions, isGeography) => GetExpectedPipeline( SpatialType.LineString, isGeography ? CoordinateSystem.Geography(54321) : CoordinateSystem.Geometry(54321), isGeography, (pipeline) => WritePositionArrayToPipeline(positions, pipeline)), (positions, isGeography) => GetExpectedPipeline( SpatialType.Polygon, isGeography ? CoordinateSystem.Geography(54321) : CoordinateSystem.Geometry(54321), isGeography, (pipeline) => WriteArrayOfPositionArrayToPipeline(positions, pipeline)) }, new[] {arrayOfMultiplePositions, arrayOfArrayMultipleElements}, true, true, CoordinateSystem.Geography(54321)); expectedPipeline.VerifyPipeline(actualPipeline); }
public void SendToPipelineCollectionEmpty() { var members = new Dictionary<string, object>(); var crs = CreateCrsMembersWithName(GeoJsonConstants.CrsValuePrefix + ":54321"); members.Add(GeoJsonConstants.TypeMemberName, GetGeoJsonTypeName(SpatialType.Collection)); members.Add(GeoJsonConstants.CrsMemberName, crs); members.Add(GeoJsonConstants.GeometriesMemberName, new List<object>()); var actualPipeline = new CallSequenceLoggingPipeline(); SendToPipeline(members, actualPipeline, true); var expectedPipeline = GetExpectedCollectionPipeline( new Func<List<object>, bool, ICommonLoggingPipeline>[0], new List<object>[0], true, true, CoordinateSystem.Geography(54321)); expectedPipeline.VerifyPipeline(actualPipeline); }
public void SendToPipeline_CrsSpecified() { var expectedPipeline = new CallSequenceLoggingPipeline(); var geoPipeline = expectedPipeline.GeometryPipeline; geoPipeline.SetCoordinateSystem(CoordinateSystem.Geometry(54321)); geoPipeline.BeginGeometry(SpatialType.Point); geoPipeline.BeginFigure(new GeometryPosition(1, 2, null, null)); geoPipeline.EndFigure(); geoPipeline.EndGeometry(); var crsMembers = CreateCrsMembersWithName(GeoJsonConstants.CrsValuePrefix + ":54321"); var actualPipeline = ExecuteSendToPipeline(SpatialType.Point, new List<object> {1.0, 2.0}, false, crsMembers); expectedPipeline.Verify(actualPipeline); }
public void ErrorOnMissingTypeMember() { var properties = new Dictionary<string, object>(); properties.Add(GeoJsonConstants.CoordinatesMemberName, position2D); var pipeline = new CallSequenceLoggingPipeline(true); // This error should occur regardless of if the pipeline is geography or geometry, so just pick one. var isGeography = true; SpatialTestUtils.VerifyExceptionThrown<ParseErrorException>(() => SendToPipeline(properties, pipeline, isGeography), Strings.GeoJsonReader_MissingRequiredMember("type")); }
private static CallSequenceLoggingPipeline ExecuteSendToPipeline(Dictionary<string, object> input, bool isGeography = true, IDictionary<string, object> crs = null) { var actualPipeline = new CallSequenceLoggingPipeline(); SendToPipeline(input, actualPipeline, isGeography); return actualPipeline; }