private static IMultiLineString ReadMultiLineString(JsonTextReader jreader) { if (jreader == null) { throw new ArgumentNullException("reader", "A valid JSON reader object is required."); } IMultiLineString lines = null; if (jreader.TokenClass == JsonTokenClass.Array) { jreader.ReadToken(JsonTokenClass.Array); List <ILineString> list = new List <ILineString>(); while (jreader.TokenClass == JsonTokenClass.Array) { list.Add(ReadLineString(jreader)); } jreader.ReadToken(JsonTokenClass.EndArray); lines = new NetTopologySuite.Geometries.MultiLineString(list.ToArray()); } return(lines); }
public static PolyLineM FromGeometryMultiLineString(NetTopologySuite.Geometries.MultiLineString multiLineString) { if (multiLineString == null) { throw new ArgumentNullException(nameof(multiLineString)); } var boundingBox = new BoundingBox2D( multiLineString.EnvelopeInternal.MinX, multiLineString.EnvelopeInternal.MinY, multiLineString.EnvelopeInternal.MaxX, multiLineString.EnvelopeInternal.MaxY ); var lineStrings = multiLineString .Geometries .Cast <NetTopologySuite.Geometries.LineString>() .ToArray(); var offset = 0; var parts = new int[lineStrings.Length]; for (var index = 0; index < lineStrings.Length; index++) { parts[index] = offset; var line = lineStrings[index]; offset += line.NumPoints; } var points = lineStrings .SelectMany(line => line.Coordinates) .Select(coordinate => new Point(coordinate.X, coordinate.Y)) .ToArray(); var measures = multiLineString.GetOrdinates(NetTopologySuite.Geometries.Ordinate.M).ToArray(); return(new PolyLineM(boundingBox, parts, points, measures)); }
public static Messages.RoadSegmentGeometry Translate(NetTopologySuite.Geometries.MultiLineString geometry) { if (geometry == null) { throw new ArgumentNullException(nameof(geometry)); } var toMultiLineString = new Messages.LineString[geometry.NumGeometries]; var lineIndex = 0; foreach (var fromLineString in geometry.Geometries.OfType <NetTopologySuite.Geometries.LineString>()) { var toLineString = new Messages.LineString { Points = new Messages.Point[fromLineString.NumPoints], Measures = fromLineString.GetOrdinates(NetTopologySuite.Geometries.Ordinate.M) }; for (var pointIndex = 0; pointIndex < fromLineString.NumPoints; pointIndex++) { toLineString.Points[pointIndex] = new Messages.Point { X = fromLineString.CoordinateSequence.GetOrdinate(pointIndex, NetTopologySuite.Geometries.Ordinate.X), Y = fromLineString.CoordinateSequence.GetOrdinate(pointIndex, NetTopologySuite.Geometries.Ordinate.Y) }; } toMultiLineString[lineIndex] = toLineString; lineIndex++; } return(new Messages.RoadSegmentGeometry { SpatialReferenceSystemIdentifier = geometry.SRID, MultiLineString = toMultiLineString }); }