Пример #1
0
            public void SinglePathReturnsMultiLineString(IPolyline polyline, ILine line, ISpatialReference spatialReference)
            {
                polyline.SetEmpty();
                polyline.SpatialReference = spatialReference;
                ((ISegmentCollection)polyline).AddSegment((ISegment)line);

                var actual   = JsonConvert.SerializeObject(polyline, Formatting.Indented, _sut);
                var expected = $@"{{
  ""type"": ""MultiLineString"",
  ""coordinates"": [
    [
      [
        {line.FromPoint.X.ToJsonString()},
        {line.FromPoint.Y.ToJsonString()}
      ],
      [
        {line.ToPoint.X.ToJsonString()},
        {line.ToPoint.Y.ToJsonString()}
      ]
    ]
  ]
}}";

                JsonAssert.Equal(expected, actual);
            }
Пример #2
0
        public void OnlyCurvesAreGeneralized(GeometryGeoJsonConverter sut, IPolyline polyline, ILine line, ILine otherLine, IPoint extensionPoint, IBezierCurve bezier)
        {
            // Create {otherLine} that is an extension to {line}.
            // This segment must not be simplified during the serialization.
            line.QueryPoint(esriSegmentExtension.esriExtendAtTo, line.Length + line.Length / 2, false, extensionPoint);
            otherLine.PutCoords(line.ToPoint, extensionPoint);

            // Prepare the actual test value.
            polyline.SetEmpty();

            var segments1 = (ISegmentCollection) new PathClass();

            segments1.AddSegment((ISegment)line);
            segments1.AddSegment((ISegment)otherLine);

            var segments2 = (ISegmentCollection) new PathClass();

            segments2.AddSegment((ISegment)bezier);

            ((IGeometryCollection)polyline).AddGeometry((IGeometry)segments1);
            ((IGeometryCollection)polyline).AddGeometry((IGeometry)segments2);

            var actual = JsonConvert.SerializeObject(polyline, Formatting.Indented, sut);

            // It must contain the "mid" point between line.FromPoint and otherLine.ToPoint.
            // If it is missing, the serialization merged the two segments even tho Simplify=false.
            JsonAssert.Contains($@"
[
  {otherLine.FromPoint.X.ToJsonString()},
  {otherLine.FromPoint.Y.ToJsonString()}
]", actual);
        }
Пример #3
0
        public void OneCompletePathWithManyIncompletePathsReturnLinestring(GeometryGeoJsonConverter sut, IPolyline polyline, ILine line, IPoint fromPoint)
        {
            var emptyPath = (IPath) new PathClass();

            var incompleteLine = (ILine) new LineClass();

            incompleteLine.FromPoint = fromPoint;
            var incompletePath = (IPath) new PathClass();

            ((ISegmentCollection)incompletePath).AddSegment((ISegment)incompleteLine);

            // Add some incomplete lines.
            polyline.SetEmpty();
            var pathCol = (IGeometryCollection)polyline;

            pathCol.AddGeometry(emptyPath);
            pathCol.AddGeometry(incompletePath);

            // Add a complete line.
            var completePath = (IPath) new PathClass();

            ((ISegmentCollection)completePath).AddSegment((ISegment)line);
            pathCol.AddGeometry(completePath);

            // Add some more incomplete lines.
            pathCol.AddGeometry((IGeometry)((IClone)emptyPath).Clone());
            pathCol.AddGeometry((IGeometry)((IClone)incompletePath).Clone());

            var actual   = JsonConvert.SerializeObject(polyline, Formatting.Indented, sut);
            var expected = $@"{{
  ""type"": ""LineString"",
  ""coordinates"": [
    [
      {line.FromPoint.X.ToJsonString()},
      {line.FromPoint.Y.ToJsonString()}
    ],
    [
      {line.ToPoint.X.ToJsonString()},
      {line.ToPoint.Y.ToJsonString()}
    ]
  ]
}}
";

            JsonAssert.Equal(expected, actual);
        }
Пример #4
0
        public void ManyPathWithSinglePointsReturnsMultiPoint(GeometryGeoJsonConverter sut, IPolyline polyline, IPoint[] points)
        {
            polyline.SetEmpty();

            var collection = (IGeometryCollection)polyline;

            foreach (var point in points)
            {
                var path = (IPointCollection) new PathClass();
                path.AddPoint(point);

                collection.AddGeometry((IGeometry)path);
            }

            var actual   = JsonConvert.SerializeObject(polyline, Formatting.Indented, sut);
            var expected = "null";

            JsonAssert.Equal(expected, actual);
        }
Пример #5
0
            public void NonTouchingPathsReturnsMultiLineString(IPolyline polyline, ILine line, ILine otherLine)
            {
                var path1 = (ISegmentCollection) new PathClass();

                path1.AddSegment((ISegment)line);

                var path2 = (ISegmentCollection) new PathClass();

                path2.AddSegment((ISegment)otherLine);

                polyline.SetEmpty();
                ((IGeometryCollection)polyline).AddGeometry((IGeometry)path1);
                ((IGeometryCollection)polyline).AddGeometry((IGeometry)path2);

                var actual   = JsonConvert.SerializeObject(polyline, Formatting.Indented, _sut);
                var expected = $@"{{
  ""type"": ""MultiLineString"",
  ""coordinates"": [
    [
      [
        {line.FromPoint.X.ToJsonString()},
        {line.FromPoint.Y.ToJsonString()}
      ],
      [
        {line.ToPoint.X.ToJsonString()},
        {line.ToPoint.Y.ToJsonString()}
      ]
    ],
    [
      [
        {otherLine.FromPoint.X.ToJsonString()},
        {otherLine.FromPoint.Y.ToJsonString()}
      ],
      [
        {otherLine.ToPoint.X.ToJsonString()},
        {otherLine.ToPoint.Y.ToJsonString()}
      ]
    ]
  ]
}}";

                JsonAssert.Equal(expected, actual);
            }