private List <ILineString> SplitLines(List <ILineString> itmLineStings) { var splitLines = new List <ILineString>(); foreach (var itmLineSting in itmLineStings) { var numberOfDividesForPoints = (itmLineSting.Coordinates.Length - 1) / _options.MaxNumberOfPointsPerLine; var numberOfDividesForLength = (int)(itmLineSting.Length / _options.MaxLengthPerLine); var numberOfDivides = Math.Max(numberOfDividesForPoints, numberOfDividesForLength); if (numberOfDivides == 0) { splitLines.Add(itmLineSting); continue; } var maxNumberOfPointsPerLine = Math.Max(1, (itmLineSting.Coordinates.Length - 1) / numberOfDivides); for (int segmentIndex = 0; segmentIndex <= numberOfDivides; segmentIndex++) { if (itmLineSting.Coordinates.Length - segmentIndex * maxNumberOfPointsPerLine <= 1) { continue; } var splitLineToAdd = _geometryFactory.CreateLineString(itmLineSting.Coordinates .Skip(segmentIndex * maxNumberOfPointsPerLine) .Take(maxNumberOfPointsPerLine + 1).ToArray()); splitLines.Add(splitLineToAdd); } } return(splitLines); }
/// <inheritdoc/> public List <ILineString> SplitSelfLoops(ILineString gpxLine, double closestPointTolerance) { var lines = new List <ILineString>(); var reversedGpxLine = ReverseLine(gpxLine); int coordinateIndex = 0; while (coordinateIndex < reversedGpxLine.Coordinates.Length) { var indexOfClosingLine = GetClosingLoopIndex(reversedGpxLine, coordinateIndex, closestPointTolerance); if (indexOfClosingLine == -1) { coordinateIndex++; continue; } AddLineString(lines, reversedGpxLine.Coordinates.Take(indexOfClosingLine).ToArray()); var reminingPoints = reversedGpxLine.Coordinates.Skip(indexOfClosingLine).ToArray(); reversedGpxLine = reminingPoints.Length > 1 ? _geometryFactory.CreateLineString(reminingPoints) : _geometryFactory.CreateLineString(new Coordinate[0]); coordinateIndex = 0; } AddLineString(lines, reversedGpxLine.Coordinates); lines = lines.Select(ReverseLine).ToList(); lines.Reverse(); return(lines); }
public static IReadOnlyList <MultiLineStringEntity> CreateMultiLineStringEntities(IGeometryFactory factory) => new[] { new MultiLineStringEntity { Id = 1, MultiLineString = factory.CreateMultiLineString( new[] { factory.CreateLineString( new[] { new Coordinate(0, 0), new Coordinate(0, 1) }), factory.CreateLineString( new[] { new Coordinate(1, 0), new Coordinate(1, 1) }) }) }, new MultiLineStringEntity { Id = 2, MultiLineString = null } };
private ILineString ReadLine(int dim, int lrsDim, SdoGeometry sdoGeom) { bool lrs = sdoGeom.LRS > 0; var info = sdoGeom.ElemArray; ICoordinateSequence cs = null; int i = 0; while (i < info.Length) { // NOTE: No compounds yet. //if (info.getElementType(i).isCompound()) //{ // int numCompounds = info.getNumCompounds(i); // cs = Add(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom)); // i += 1 + numCompounds; //} //else //{ cs = Add(cs, GetElementCSeq(i, sdoGeom, false)); i++; //} } //ILineString ls = // lrs // ? (LineString)factory.CreateMultiLineString(cs) // : factory.CreateLineString(cs); ILineString ls = factory.CreateLineString(cs); ls.SRID = (int)sdoGeom.Sdo_Srid; return(ls); }
private IGeometry BuildGrid() { var lines = new ILineString[_numLines * 2]; int index = 0; for (int i = 0; i < _numLines; i++) { Coordinate p0 = new Coordinate(GetRandOrdinate(), 0); Coordinate p1 = new Coordinate(GetRandOrdinate(), GridWidth); ILineString line = _geomFactory.CreateLineString(new [] { p0, p1 }); lines[index++] = line; } for (int i = 0; i < _numLines; i++) { Coordinate p0 = new Coordinate(0, GetRandOrdinate()); Coordinate p1 = new Coordinate(GridWidth, GetRandOrdinate()); ILineString line = _geomFactory.CreateLineString(new [] { p0, p1 }); lines[index++] = line; } IMultiLineString ml = _geomFactory.CreateMultiLineString(lines); _grid = ml.Buffer(_lineWidth); var wktWriter = new WKTWriter(2) { Formatted = true, MaxCoordinatesPerLine = 6 }; if (Verbose) { Console.WriteLine(wktWriter.Write(_grid)); } return(_grid); }
private void HandleTwoLinesCase(GpxProlongerExecutorInput input, SegmentWithLines segment, List <ILineString> linesToProlong) { var bothLinesAreInList = linesToProlong.Contains(segment.Start.Line) && linesToProlong.Contains(segment.End.Line); if (bothLinesAreInList && segment.Start.Line.Coordinates.Last().Distance(segment.Start.Coordinate) < input.MinimalDistance && segment.End.Line.Coordinates.First().Distance(segment.End.Coordinate) < input.MinimalDistance) { linesToProlong.Remove(segment.Start.Line); linesToProlong.Remove(segment.End.Line); linesToProlong.Add(_geometryFactory.CreateLineString( segment.Start.Line.Coordinates .Concat(segment.OriginalCoordinates) .Concat(segment.End.Line.Coordinates) .Distinct() .ToArray())); } else if (!AddSegmentToLine(segment.Start.Line, segment, linesToProlong, input.MinimalDistance)) { if (!AddSegmentToLine(segment.End.Line, segment, linesToProlong, input.MinimalDistance)) { linesToProlong.Add(CreateLineString(segment.StartProjected, segment.OriginalCoordinates, segment.EndProjected)); } } }
private ILineString ReadLine(int dim, int lrsDim, SdoGeometry sdoGeom) { bool lrs = sdoGeom.LRS > 0; decimal[] info = sdoGeom.ElemArray; ICoordinateSequence cs = null; int i = 0; while (i < info.Length) { if (info.getElementType(i).isCompound()) { int numCompounds = info.getNumCompounds(i); cs = Add(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom)); i += 1 + numCompounds; } else { cs = Add(cs, GetElementCSeq(i, sdoGeom, false)); i++; } } LineString ls = lrs ? factory.createMLineString(cs) : factory.CreateLineString(cs); ls.SRID = (int)sdoGeom.Sdo_Srid; return(ls); }
/// <summary> /// Converts the GML element to line string. /// </summary> /// <param name="element">The GML element of the line string.</param> /// <param name="factory">The geometry factory.</param> /// <returns>The converted line string.</returns> private static ILineString ToLineString(XElement element, IGeometryFactory factory) { if (element.Elements() == null) { return(factory.CreateLineString()); } List <Coordinate> coordinates = new List <Coordinate>(); foreach (XElement innerElement in element.Elements()) { switch (innerElement.Name.LocalName) { case "coordinates": return(factory.CreateLineString(ConvertCoordinates(innerElement))); case "posList": return(factory.CreateLineString(ConvertPosList(innerElement, GetDimension(element, innerElement)))); case "coord": coordinates.Add(ConvertCoordinate(innerElement.Value.Split(','))); break; } } return(factory.CreateLineString(coordinates)); }
private IMultiLineString ReadMultiLine(SdoGeometry sdoGeom) { int[] elements = sdoGeom.ElemArrayOfInts; ILineString[] lines = new ILineString[sdoGeom.ElemArray.Length / ElementTupleSize]; int i = 0; while (i < elements.Length / ElementTupleSize) { ICoordinateSequence cs = null; if (GetElementType(elements, i) == (int)SdoGeometryTypes.ETYPE_COMPOUND.FOURDIGIT) { int numCompounds = GetNumCompounds(elements, i); cs = AppendCoordinateSequence(cs, GetCompoundCSeq(i + 1, i + numCompounds, sdoGeom)); ILineString line = _factory.CreateLineString(cs); lines[i] = line; i += 1 + numCompounds; } else { cs = AppendCoordinateSequence(cs, GetElementCoordinateSequence(i, sdoGeom, false)); ILineString line = _factory.CreateLineString(cs); lines[i] = line; i++; } } IMultiLineString mls = _factory.CreateMultiLineString(lines); mls.SRID = (int)sdoGeom.Sdo_Srid; return(mls); }
/// <summary> /// /// </summary> /// <param name="computer"></param> private void BuildEdges(ComputeWeightDelegate computer) { if (strings.Count < 2) { throw new TopologyException("you must specify two or more geometries to build a graph"); } // Counts the number of edges in the set we pass to this method. int numberOfEdgesInLines = 0; foreach (ILineString str in strings) { int edges = str.Coordinates.GetUpperBound(0); numberOfEdgesInLines += edges; } // Double values because we use also reversed edges... if (bidirectional) { numberOfEdgesInLines *= 2; } consts = new Dictionary <IEdge <Coordinate>, double>(numberOfEdgesInLines); foreach (ILineString line in strings) { // A line has to have at least two dimensions int bound = line.Coordinates.GetUpperBound(0); if (bound > 0) { for (int counter = 0; counter < bound; counter++) { // Prepare a segment Coordinate src = line.Coordinates[counter]; Coordinate dst = line.Coordinates[counter + 1]; // Here we calculate the weight of the edge ILineString lineString = factory.CreateLineString( new[] { src, dst, }); double weight = computer(lineString); // Add the edge IEdge <Coordinate> localEdge = new Edge <Coordinate>(src, dst); graph.AddEdge(localEdge); consts.Add(localEdge, weight); if (!bidirectional) { continue; } // Add the reversed edge IEdge <Coordinate> localEdgeRev = new Edge <Coordinate>(dst, src); graph.AddEdge(localEdgeRev); consts.Add(localEdgeRev, weight); } } } }
#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) #pragma warning restore CS0809 // Obsolete member overrides non-obsolete member { reader.Read(); if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "type")) { throw new ArgumentException("invalid tokentype: " + reader.TokenType); } reader.Read(); if (reader.TokenType != JsonToken.String) { throw new ArgumentException("invalid tokentype: " + reader.TokenType); } GeoJsonObjectType geometryType = (GeoJsonObjectType)Enum.Parse(typeof(GeoJsonObjectType), (string)reader.Value); switch (geometryType) { case GeoJsonObjectType.Point: Coordinate coordinate = _geoJsonSerializer.Deserialize <Coordinate>(reader); return(_factory.CreatePoint(coordinate)); case GeoJsonObjectType.LineString: Coordinate[] coordinates = _geoJsonSerializer.Deserialize <Coordinate[]>(reader); return(_factory.CreateLineString(coordinates)); case GeoJsonObjectType.Polygon: List <Coordinate[]> coordinatess = _geoJsonSerializer.Deserialize <List <Coordinate[]> >(reader); return(CreatePolygon(coordinatess)); case GeoJsonObjectType.MultiPoint: coordinates = _geoJsonSerializer.Deserialize <Coordinate[]>(reader); return(_factory.CreateMultiPoint(coordinates)); case GeoJsonObjectType.MultiLineString: coordinatess = _geoJsonSerializer.Deserialize <List <Coordinate[]> >(reader); List <ILineString> strings = new List <ILineString>(); for (int i = 0; i < coordinatess.Count; i++) { strings.Add(_factory.CreateLineString(coordinatess[i])); } return(_factory.CreateMultiLineString(strings.ToArray())); case GeoJsonObjectType.MultiPolygon: List <List <Coordinate[]> > coordinatesss = _geoJsonSerializer.Deserialize <List <List <Coordinate[]> > >(reader); List <IPolygon> polygons = new List <IPolygon>(); foreach (List <Coordinate[]> coordinateses in coordinatesss) { polygons.Add(CreatePolygon(coordinateses)); } return(_factory.CreateMultiPolygon(polygons.ToArray())); case GeoJsonObjectType.GeometryCollection: List <IGeometry> geoms = _geoJsonSerializer.Deserialize <List <IGeometry> >(reader); return(_factory.CreateGeometryCollection(geoms.ToArray())); } return(null); }
private static void PerformTest(double value) { IGeometryFactory factory = GeometryFactory.Default; ILineString ls1 = factory.CreateLineString(new Coordinate[] { new Coordinate(0, 0), new Coordinate(50, 50) }); ILineString ls2 = factory.CreateLineString(new Coordinate[] { new Coordinate(10, value), new Coordinate(10, -value) }); IGeometry result = ls1.Intersection(ls2); IGeometry expected = factory.CreatePoint(new Coordinate(10, 10)); Assert.That(result, Is.EqualTo(expected)); }
private void HandleSelfClosingCase(GpxProlongerExecutorInput input, LineAndCoordinate current, LineAndCoordinate next, List <ILineString> linesToProlong) { var lengthIndexedLine = new LengthIndexedLine(current.Line); var closestCoordinateCurrentIndex = lengthIndexedLine.Project(current.Coordinate); var closestCoordinateNextIndex = lengthIndexedLine.Project(next.Coordinate); var segment = lengthIndexedLine.ExtractLine(closestCoordinateCurrentIndex, closestCoordinateNextIndex); var coordinates = segment.Coordinates.Concat(new[] { segment.Coordinates.First() }).ToArray(); if (coordinates.Length < 4) { return; } var polygon = new Polygon(new LinearRing(coordinates)); if (polygon.Area < input.MinimalAreaSize) { return; } var currentCoordinate = lengthIndexedLine.ExtractPoint(closestCoordinateCurrentIndex); var nextCoordinate = lengthIndexedLine.ExtractPoint(closestCoordinateNextIndex); if (!AddCoordinate(current.Line, currentCoordinate, nextCoordinate, linesToProlong, input.MinimalDistance)) { linesToProlong.Add(_geometryFactory.CreateLineString(new[] { currentCoordinate, nextCoordinate })); } }
private List <ILineString> IncreaseGpxDensity(List <ILineString> gpxItmLines) { var denseGpxLines = new List <ILineString>(); foreach (var gpxItmLine in gpxItmLines.Where(l => l.Coordinates.Length > 0)) { var coordinates = gpxItmLine.Coordinates.ToList(); for (int coordinateIndex = 0; coordinateIndex < coordinates.Count - 1; coordinateIndex++) { var currentCoordinate = coordinates[coordinateIndex]; var nextCoordinate = coordinates[coordinateIndex + 1]; if (currentCoordinate.Distance(nextCoordinate) > 2 * _options.MaxDistanceToExisitngLineForMerge) { var directionSegment = new LineSegment(currentCoordinate, nextCoordinate); var coordinate = directionSegment.PointAlong((_options.MaxDistanceToExisitngLineForMerge) / (2.0 * directionSegment.Length)); coordinates.Insert(coordinateIndex + 1, coordinate); } else if (currentCoordinate.Distance(nextCoordinate) > _options.MaxDistanceToExisitngLineForMerge) { var middle = new Coordinate((currentCoordinate.X + nextCoordinate.X) / 2.0, (currentCoordinate.Y + nextCoordinate.Y) / 2.0); coordinates.Insert(coordinateIndex + 1, middle); } } denseGpxLines.Add(_geometryFactory.CreateLineString(coordinates.ToArray())); } return(denseGpxLines); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { reader.Read(); if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "geometries")) { throw new Exception(); } reader.Read(); if (reader.TokenType != JsonToken.StartArray) { throw new Exception(); } reader.Read(); List <IGeometry> geoms = new List <IGeometry>(); while (reader.TokenType != JsonToken.EndArray) { JObject obj = (JObject)serializer.Deserialize(reader); GeoJsonObjectType geometryType = (GeoJsonObjectType)Enum.Parse(typeof(GeoJsonObjectType), obj.Value <string>("type")); switch (geometryType) { case GeoJsonObjectType.Point: geoms.Add(_factory.CreatePoint(ToCoordinate(obj.Value <JArray>("coordinates")))); break; case GeoJsonObjectType.LineString: geoms.Add(_factory.CreateLineString(ToCoordinates(obj.Value <JArray>("coordinates")))); break; case GeoJsonObjectType.Polygon: geoms.Add(CreatePolygon(ToListOfCoordinates(obj.Value <JArray>("coordinates")))); break; case GeoJsonObjectType.MultiPoint: geoms.Add(_factory.CreateMultiPoint(ToCoordinates(obj.Value <JArray>("coordinates")))); break; case GeoJsonObjectType.MultiLineString: geoms.Add(CreateMultiLineString(ToListOfCoordinates(obj.Value <JArray>("coordinates")))); break; case GeoJsonObjectType.MultiPolygon: geoms.Add(CreateMultiPolygon(ToListOfListOfCoordinates(obj.Value <JArray>("coordinates")))); break; case GeoJsonObjectType.GeometryCollection: throw new NotSupportedException(); } reader.Read(); } return(geoms); }
/// <summary> /// /// </summary> /// <param name="geom"></param> /// <param name="parent"></param> /// <returns></returns> protected virtual IGeometry TransformLinearRing(ILinearRing geom, IGeometry parent) { ICoordinateSequence seq = TransformCoordinates(geom.CoordinateSequence, geom); int seqSize = seq.Count; // ensure a valid LinearRing if (seqSize > 0 && seqSize < 4 && !preserveType) { return(factory.CreateLineString(seq)); } return(factory.CreateLinearRing(seq)); }
public void TestWriteLineString() { Coordinate[] coordinates = { new Coordinate(10, 10, 0), new Coordinate(20, 20, 0), new Coordinate(30, 40, 0) }; var lineString = _factory.CreateLineString(coordinates); Assert.AreEqual("LINESTRING (10 10, 20 20, 30 40)", _writer.Write(lineString)); }
public void Setup() { factory = GeometryFactory.Fixed; a = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(100, 0), new Coordinate(200, 100), new Coordinate(200, 200), }); b = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(100, 100), new Coordinate(200, 200), }); c = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(0, 100), new Coordinate(100, 200), new Coordinate(200, 200), }); d = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(300, 0), new Coordinate(300, 200), new Coordinate(150, 200), new Coordinate(150, 300), }); e = factory.CreateLineString(new ICoordinate[] { new Coordinate(100, 300), new Coordinate(150, 300), new Coordinate(200, 300), }); result = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(300, 0), new Coordinate(300, 200), new Coordinate(150, 200), new Coordinate(150, 300), }); revresult = result.Reverse(); start = a.StartPoint; end = d.EndPoint; }
private ILineString RemoveSpikesFromLineString(ILineString geom, IGeometryFactory factory, bool ring = false) { var seq = geom.CoordinateSequence; if (geom.Length < 3) { return(factory.CreateLineString(seq)); } //seq = RemoveSpikesFromSequence(geom.CoordinateSequence, factory.CoordinateSequenceFactory); return(ring ? factory.CreateLinearRing(seq) : factory.CreateLineString(seq)); }
public static IGeometry AngleBisectors(IGeometry g) { Coordinate[] pts = TrianglePts(g); Triangle t = new Triangle(pts[0], pts[1], pts[2]); Coordinate cc = t.InCentre(); IGeometryFactory geomFact = FunctionsUtil.GetFactoryOrDefault(g); ILineString[] line = new ILineString[3]; line[0] = geomFact.CreateLineString(new[] { pts[0], cc }); line[1] = geomFact.CreateLineString(new[] { pts[1], cc }); line[2] = geomFact.CreateLineString(new[] { pts[2], cc }); return(geomFact.CreateMultiLineString(line)); }
private ILineString ToItmLineString(IEnumerable <wptType> waypoints) { var coordinates = waypoints.Select(wptType => _wgs84ItmMathTransform.Transform(new Coordinate((double)wptType.lon, (double)wptType.lat))); var nonDuplicates = new List <Coordinate>(); foreach (var coordinate in coordinates) { if (nonDuplicates.Count <= 0 || !nonDuplicates.Last().Equals2D(coordinate)) { nonDuplicates.Add(coordinate); } } return(_geometryFactory.CreateLineString(nonDuplicates.ToArray())); }
private ILineString ToItmLineString(IEnumerable <GpxWaypoint> waypoints) { var coordinates = waypoints.Select(waypoint => _wgs84ItmMathTransform.Transform(new Coordinate(waypoint.Longitude, waypoint.Latitude))) .Select(c => new Coordinate(Math.Round(c.X, 1), Math.Round(c.Y, 1))); var nonDuplicates = new List <Coordinate>(); foreach (var coordinate in coordinates) { if (nonDuplicates.Count <= 0 || !nonDuplicates.Last().Equals2D(coordinate)) { nonDuplicates.Add(coordinate); } } return(_geometryFactory.CreateLineString(nonDuplicates.ToArray())); }
/// <summary> /// Function to read a <see cref="ILineString"/> or <see cref="IMultiLineString"/> from a ShapeFile stream using the specified <paramref name="reader"/>. /// </summary> /// <param name="reader">The reader to use</param> /// <param name="ordinates">The ordinates to read</param> /// <returns>The read lineal geometry</returns> protected IGeometry ReadLineString(BinaryReader reader, Ordinates ordinates) { /*var bbox = */ ReadBoundingBox(reader); // Jump boundingbox var numParts = ReadNumParts(reader); var numPoints = ReadNumPoints(reader); var indexParts = ReadIndexParts(reader, numParts, numPoints); var buffer = new CoordinateBuffer(numPoints, ShapeFileConstants.NoDataBorder, true); ReadCoordinates(reader, numPoints, indexParts, ordinates, buffer); if (numParts == 1) return _factory.CreateLineString(buffer.ToSequence()); return CreateMultiLineString(buffer.ToSequences()); }
private void AddLine(CoordinateList line) { Coordinate[] array = line.ToCoordinateArray(); ILineString ls = _factory.CreateLineString(array); _lines.Add(ls); }
/// <summary> /// Computes the <see cref="IMultiLineString" /> representation of the WKB. /// </summary> /// <param name="geometryBytes">The WKB representation of the geometry.</param> /// <param name="byteOrder">The byte-order of the conversion.</param> /// <param name="geometryModel">The geometry model of the conversion.</param> /// <param name="factory">The factory used for geometry production.</param> /// <returns>The <see cref="IMultiLineString" /> representation of the geometry.</returns> private static IMultiLineString ComputeMultiLineString(Byte[] geometryBytes, ByteOrder byteOrder, GeometryModel geometryModel, IGeometryFactory factory) { Int32 coordinateSize = (geometryModel == GeometryModel.Spatial3D) ? 24 : 16; Int32 lineStringCount = EndianBitConverter.ToInt32(geometryBytes, 5, byteOrder); ILineString[] lineStrings = new ILineString[lineStringCount]; Int32 lineStringStartIndex = 9; for (Int32 i = 0; i < lineStringCount; i++) { Int32 coordinateCount = EndianBitConverter.ToInt32(geometryBytes, lineStringStartIndex, byteOrder); lineStringStartIndex += 4; Coordinate[] coordinates = new Coordinate[coordinateCount]; for (Int32 byteIndex = lineStringStartIndex, coordinateIndex = 0; coordinateIndex < coordinateCount; byteIndex += coordinateSize, coordinateIndex++) { coordinates[coordinateIndex] = new Coordinate(EndianBitConverter.ToDouble(geometryBytes, byteIndex, byteOrder), EndianBitConverter.ToDouble(geometryBytes, byteIndex + 8, byteOrder), geometryModel == GeometryModel.Spatial3D ? EndianBitConverter.ToDouble(geometryBytes, byteIndex + 16, byteOrder) : 0); } lineStrings[i] = factory.CreateLineString(coordinates); } return(factory.CreateMultiLineString(lineStrings)); }
public IGeometry Edit(IGeometry geometry, IGeometryFactory factory) { var linearRing = geometry as ILinearRing; if (linearRing != null) { return(factory.CreateLinearRing(EditSequence( (linearRing).CoordinateSequence, geometry))); } var lineString = geometry as ILineString; if (lineString != null) { return(factory.CreateLineString(EditSequence( (lineString).CoordinateSequence, geometry))); } var point = geometry as IPoint; if (point != null) { return(factory.CreatePoint(EditSequence( (point).CoordinateSequence, geometry))); } return(geometry); }
public IGeometry Edit(IGeometry geometry, IGeometryFactory targetFactory) { if (geometry is ILinearRing) { var cs = ((ILinearRing)geometry).CoordinateSequence; var edit = Edit(cs, geometry, targetFactory); return(targetFactory.CreateLinearRing(edit)); } if (geometry is ILineString) { var cs = ((ILineString)geometry).CoordinateSequence; var edit = Edit(cs, geometry, targetFactory); return(targetFactory.CreateLineString(edit)); } if (geometry is IPoint) { var cs = ((IPoint)geometry).CoordinateSequence; var edit = Edit(cs, geometry, targetFactory); return(targetFactory.CreatePoint(edit)); } return(geometry); }
public IGeometry Edit(IGeometry geometry, IGeometryFactory targetFactory) { var coordinates = geometry.Coordinates; if (geometry is LinearRing) { var edit = Edit(coordinates, geometry); return(targetFactory.CreateLinearRing(edit)); } if (geometry is LineString) { var edit = Edit(coordinates, geometry); return(targetFactory.CreateLineString(edit)); } if (geometry is Point) { var edit = Edit(coordinates, geometry); var coordinate = edit.Length > 0 ? edit[0] : null; return(targetFactory.CreatePoint(coordinate)); } return(geometry); }
private IGeometry ReadLineString(OgrGeometryType type, OgrGeometry geom) { var count = geom.GetPointCount(); var dimension = geom.GetCoordinateDimension(); var cs = _factory.CoordinateSequenceFactory.Create(count, dimension); if (dimension > 2) { for (var i = 0; i < cs.Count; i++) { cs.SetOrdinate(i, Ordinate.X, geom.GetX(i)); cs.SetOrdinate(i, Ordinate.Y, geom.GetY(i)); cs.SetOrdinate(i, Ordinate.Z, geom.GetZ(i)); } } else { for (var i = 0; i < cs.Count; i++) { cs.SetOrdinate(i, Ordinate.X, geom.GetX(i)); cs.SetOrdinate(i, Ordinate.Y, geom.GetY(i)); } } return(_factory.CreateLineString(cs)); }
private void ProcessLineStringGeometry(LineString f) { var pGeom = _geometryFactory.CreateLineString( f.Coordinates.Select(crd => new Coordinate(crd.Longitude, crd.Latitude)).ToArray()); AddGeometryToCollection(f.GetParent <Placemark>(), pGeom); }
private ILineString BuildLineString() { var seq = _coordinateBuffer.ToSequence(_factory.CoordinateSequenceFactory); return(_factory.CreateLineString(seq)); //return _factory.CreateLineString(_coordinates.ToArray()); }
private static IGeometry CreateLine(IGeometryFactory factory, Size size) { return factory.CreateLineString( new [] { new Coordinate(2, 2), new Coordinate(0.3f * size.Width, 0.5*size.Height), new Coordinate(0.65f * size.Width, 0.5*size.Height+1), new Coordinate(size.Width -4, size.Height -4), }); }
public void Setup() { factory = GeometryFactory.Fixed; // Build sample geometries a = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(100, 0), new Coordinate(200, 100), new Coordinate(200, 200), }); b = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(100, 100), new Coordinate(200, 200), }); c = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(0, 100), new Coordinate(100, 200), new Coordinate(200, 200), }); d = factory.CreateLineString(new ICoordinate[] { new Coordinate(0, 0), new Coordinate(300, 0), new Coordinate(300, 200), new Coordinate(150, 200), new Coordinate(150, 300), }); e = factory.CreateLineString(new ICoordinate[] { new Coordinate(100, 300), new Coordinate(150, 300), new Coordinate(200, 300), }); start = a.StartPoint; end = d.EndPoint; }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); type = (ShapeGeometryType) Enum.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString()); if (type == ShapeGeometryType.NullShape) return geometryFactory.CreateMultiLineString(null); if (!(type == ShapeGeometryType.LineString || type == ShapeGeometryType.LineStringM || type == ShapeGeometryType.LineStringZ || type == ShapeGeometryType.LineStringZM)) throw new ShapefileException("Attempting to load a non-arc as arc."); // Read and for now ignore bounds. int bblength = GetBoundingBoxLength(); bbox = new double[bblength]; for (; bbindex < 4; bbindex++) { double d = file.ReadDouble(); bbox[bbindex] = d; } int numParts = file.ReadInt32(); int numPoints = file.ReadInt32(); int[] partOffsets = new int[numParts]; for (int i = 0; i < numParts; i++) partOffsets[i] = file.ReadInt32(); ILineString[] lines = new ILineString[numParts]; for (int part = 0; part < numParts; part++) { int start, finish, length; start = partOffsets[part]; if (part == numParts - 1) finish = numPoints; else finish = partOffsets[part + 1]; length = finish - start; CoordinateList points = new CoordinateList(); points.Capacity = length; for (int i = 0; i < length; i++) { double x = file.ReadDouble(); double y = file.ReadDouble(); ICoordinate external = new Coordinate(x, y); geometryFactory.PrecisionModel.MakePrecise(external); points.Add(external); } ILineString line = geometryFactory.CreateLineString(points.ToArray()); lines[part] = line; } geom = geometryFactory.CreateMultiLineString(lines); GrabZMValues(file); return geom; }
/// <summary> /// Converts a collection of <see cref="ISegmentString"/>s into a <see cref="IGeometry"/>. /// The geometry will be either a <see cref="ILineString"/> /// or a <see cref="IMultiLineString"/> (possibly empty). /// </summary> /// <param name="segStrings">A collection of <see cref="ISegmentString"/>.</param> /// <param name="geomFact">A geometry factory</param> /// <returns>A <see cref="ILineString"/> or a <see cref="IMultiLineString"/>.</returns> public static IGeometry ToGeometry(IList<ISegmentString> segStrings, IGeometryFactory geomFact) { ILineString[] lines = new ILineString[segStrings.Count]; int index = 0; foreach (ISegmentString ss in segStrings) { ILineString line = geomFact.CreateLineString(ss.Coordinates); lines[index++] = line; } if (lines.Length == 1) return lines[0]; return geomFact.CreateMultiLineString(lines); }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); ShapeGeometryTypes shapeType = (ShapeGeometryTypes)Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString()); if( ! ( shapeType == ShapeGeometryTypes.LineString || shapeType == ShapeGeometryTypes.LineStringM || shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM )) throw new ShapefileException("Attempting to load a non-arc as arc."); //read and for now ignore bounds. double[] box = new double[4]; for (int i = 0; i < 4; i++) { double d= file.ReadDouble(); box[i] =d; } int numParts = file.ReadInt32(); int numPoints = file.ReadInt32(); int[] partOffsets = new int[numParts]; for (int i = 0; i < numParts; i++) partOffsets[i] = file.ReadInt32(); ILineString[] lines = new ILineString[numParts]; int start, finish, length; for (int part = 0; part < numParts; part++) { start = partOffsets[part]; if (part == numParts - 1) finish = numPoints; else finish = partOffsets[part + 1]; length = finish - start; CoordinateList points = new CoordinateList(); points.Capacity=length; ICoordinate external; for (int i = 0; i < length; i++) { external = new Coordinate(file.ReadDouble(),file.ReadDouble()); geometryFactory.PrecisionModel.MakePrecise( external); points.Add(external); } lines[part] = geometryFactory.CreateLineString(points.ToArray()); } return geometryFactory.CreateMultiLineString(lines); }
/// <summary> /// Transforms a <see cref="LineString" /> object. /// </summary> /// <param name="factory"></param> /// <param name="l"></param> /// <param name="transform"></param> /// <returns></returns> public static ILineString TransformLineString(IGeometryFactory factory, ILineString l, IMathTransform transform) { try { ICoordinate[] coords = ExtractCoordinates(l, transform); return factory.CreateLineString(coords); } catch { return null; } }
private static ILineString CreateWKBLineString(BinaryReader reader, WkbByteOrder byteOrder, IGeometryFactory factory) { var arrPoint = ReadCoordinates(reader, byteOrder); return factory.CreateLineString(arrPoint); }
private static void generateLines(IGeometryFactory geometryFactory, ICollection<IGeometry> geometry, Random rndGen) { ICoordinateSequenceFactory coordinateSequenceFactory = geometryFactory.CoordinateSequenceFactory; ICoordinateFactory coordinateFactory = geometryFactory.CoordinateFactory; ICoordinateSequence coords = coordinateSequenceFactory.Create(CoordinateDimensions.Two); Int32 lineCount = rndGen.Next(10, 100); for (Int32 lineIndex = 0; lineIndex < lineCount; lineIndex++) { Int32 vertexCount = rndGen.Next(4, 15); ICoordinate coordinate = coordinateFactory.Create(rndGen.NextDouble() * 1000, rndGen.NextDouble() * 1000); coords.Add(coordinate); for (Int32 vertexIndex = 0; vertexIndex < vertexCount; vertexIndex++) { ICoordinate next = coordinateFactory.Create(coordinate[Ordinates.X] + rndGen.Next(-50, 50), coordinate[Ordinates.Y] + rndGen.Next(-50, 50)); coords.Add(next); coordinate = next; } ILineString line = geometryFactory.CreateLineString(coords); geometry.Add(line); } }
/// <summary> /// /// </summary> /// <param name="geometry"></param> /// <param name="factory"></param> /// <returns></returns> public virtual IGeometry Edit(IGeometry geometry, IGeometryFactory factory) { if (geometry is LinearRing) return factory.CreateLinearRing(Edit(geometry.Coordinates, geometry)); if (geometry is LineString) return factory.CreateLineString(Edit(geometry.Coordinates, geometry)); if (geometry is Point) { IList<Coordinate> newCoordinates = Edit(geometry.Coordinates, geometry); return factory.CreatePoint((newCoordinates.Count > 0) ? newCoordinates[0] : null); } return geometry; }
public IGeometry ToGeometry(IGeometryFactory geomFactory) { if (IsNull) { return geomFactory.CreatePoint((ICoordinateSequence)null); } Coordinate px00 = new Coordinate(_minX, _minA - _minX); Coordinate px01 = new Coordinate(_minX, _minX - _minB); Coordinate px10 = new Coordinate(_maxX, _maxX - _maxB); Coordinate px11 = new Coordinate(_maxX, _maxA - _maxX); Coordinate py00 = new Coordinate(_minA - _minY, _minY); Coordinate py01 = new Coordinate(_minY + _maxB, _minY); Coordinate py10 = new Coordinate(_maxY + _minB, _maxY); Coordinate py11 = new Coordinate(_maxA - _maxY, _maxY); IPrecisionModel pm = geomFactory.PrecisionModel; pm.MakePrecise(px00); pm.MakePrecise(px01); pm.MakePrecise(px10); pm.MakePrecise(px11); pm.MakePrecise(py00); pm.MakePrecise(py01); pm.MakePrecise(py10); pm.MakePrecise(py11); CoordinateList coordList = new CoordinateList(); coordList.Add(px00, false); coordList.Add(px01, false); coordList.Add(py10, false); coordList.Add(py11, false); coordList.Add(px11, false); coordList.Add(px10, false); coordList.Add(py01, false); coordList.Add(py00, false); if (coordList.Count == 1) { return geomFactory.CreatePoint(px00); } Coordinate[] pts; if (coordList.Count == 2) { pts = coordList.ToCoordinateArray(); return geomFactory.CreateLineString(pts); } // must be a polygon, so add closing point coordList.Add(px00, false); pts = coordList.ToCoordinateArray(); return geomFactory.CreatePolygon(geomFactory.CreateLinearRing(pts), null); }
/// <summary> /// Creates a LineString using the next token in the stream. /// </summary> /// <param name="tokenizer">Tokenizer over a stream of text in Well-known Text format. The next /// tokens must form a LineString Text.</param> /// <param name="factory">The factory to create the result geometry</param> /// <returns>Returns a LineString specified by the next token in the stream.</returns> /// <remarks> /// ParseException is thrown if an unexpected token is encountered. /// </remarks> private static ILineString ReadLineStringText(WktStreamTokenizer tokenizer, IGeometryFactory factory) { return factory.CreateLineString(GetCoordinates(tokenizer)); }
/// <summary> /// Transforms a <see cref="GeoAPI.Geometries.ILineString"/>. /// </summary> /// <param name="l">LineString to transform</param> /// <param name="from">Source Projection</param> /// <param name="to">Target Projection</param> /// <param name="toFactory">The factory to create geometries for <paramref name="to"/></param> /// <returns>Transformed LineString</returns> public static ILineString TransformLineString(ILineString l, ProjectionInfo from, ProjectionInfo to, IGeometryFactory toFactory) { try { var toSeq = TransformSequence(l.CoordinateSequence, from, to, toFactory.CoordinateSequenceFactory); return toFactory.CreateLineString(toSeq); } catch { return null; } }
/// <summary> /// Creates an empty result geometry of the appropriate dimension, /// based on the given overlay operation and the dimensions of the inputs. /// The created geometry is always an atomic geometry, /// not a collection. /// <para/> /// The empty result is constructed using the following rules: /// <list type="Bullet"> /// <item><see cref="SpatialFunction.Intersection"/> - result has the dimension of the lowest input dimension</item> /// <item><see cref="SpatialFunction.Union"/> - result has the dimension of the highest input dimension</item> /// <item><see cref="SpatialFunction.Difference"/> - result has the dimension of the left-hand input</item> /// <item><see cref="SpatialFunction.SymDifference"/> - result has the dimension of the highest input dimension /// (since symDifference is the union of the differences).</item> /// </list> /// </summary> /// <param name="overlayOpCode">The overlay operation being performed</param> /// <param name="a">An input geometry</param> /// <param name="b">An input geometry</param> /// <param name="geomFact">The geometry factory being used for the operation</param> /// <returns>An empty atomic geometry of the appropriate dimension</returns> public static IGeometry CreateEmptyResult(SpatialFunction overlayOpCode, IGeometry a, IGeometry b, IGeometryFactory geomFact) { IGeometry result = null; switch (ResultDimension(overlayOpCode, a, b)) { case Dimension.False: result = geomFact.CreateGeometryCollection(new IGeometry[0]); break; case Dimension.Point: result = geomFact.CreatePoint((Coordinate)null); break; case Dimension.Curve: result = geomFact.CreateLineString((Coordinate[])null); break; case Dimension.Surface: result = geomFact.CreatePolygon(null, null); break; } return result; }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="totalRecordLength">Total length of the record we are about to read</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, int totalRecordLength, IGeometryFactory geometryFactory) { int totalRead = 0; var type = (ShapeGeometryType)ReadInt32(file, totalRecordLength, ref totalRead); if (type == ShapeGeometryType.NullShape) return geometryFactory.CreateMultiLineString(null); if (type != ShapeType) throw new ShapefileException(string.Format("Encountered a '{0}' instead of a '{1}'", type, ShapeType)); // Read and for now ignore bounds. int bblength = GetBoundingBoxLength(); boundingBox = new double[bblength]; for (; boundingBoxIndex < 4; boundingBoxIndex++) { double d = ReadDouble(file, totalRecordLength, ref totalRead); boundingBox[boundingBoxIndex] = d; } int numParts = ReadInt32(file, totalRecordLength, ref totalRead); int numPoints = ReadInt32(file, totalRecordLength, ref totalRead); int[] partOffsets = new int[numParts]; for (int i = 0; i < numParts; i++) partOffsets[i] = ReadInt32(file, totalRecordLength, ref totalRead); var lines = new List<ILineString>(numParts); var buffer = new CoordinateBuffer(numPoints, NoDataBorderValue, true); var pm = geometryFactory.PrecisionModel; for (var part = 0; part < numParts; part++) { var start = partOffsets[part]; var finish = part == numParts - 1 ? numPoints : partOffsets[part + 1]; var length = finish - start; for (var i = 0; i < length; i++) { var x = pm.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead)); var y = pm.MakePrecise(ReadDouble(file, totalRecordLength, ref totalRead)); buffer.AddCoordinate(x, y); } buffer.AddMarker(); } // Trond Benum: We have now read all the parts, let's read optional Z and M values // and populate Z in the coordinate before we start manipulating the segments // We have to track corresponding optional M values and set them up in the // Geometries via ICoordinateSequence further down. GetZMValues(file, totalRecordLength, ref totalRead, buffer); var sequences = new List<ICoordinateSequence>(buffer.ToSequences(geometryFactory.CoordinateSequenceFactory)); for (var s = 0; s < sequences.Count; s++) { var points = sequences[s]; //Skip garbage input data with 0 points if (points.Count < 1) continue; var createLineString = true; if (points.Count == 1) { switch (GeometryInstantiationErrorHandling) { case GeometryInstantiationErrorHandlingOption.ThrowException: break; case GeometryInstantiationErrorHandlingOption.Empty: sequences[s] = geometryFactory.CoordinateSequenceFactory.Create(0, points.Ordinates); break; case GeometryInstantiationErrorHandlingOption.TryFix: sequences[s] = AddCoordinateToSequence(points, geometryFactory.CoordinateSequenceFactory, points.GetOrdinate(0, Ordinate.X), points.GetOrdinate(0, Ordinate.Y), points.GetOrdinate(0, Ordinate.Z), points.GetOrdinate(0, Ordinate.M)); break; case GeometryInstantiationErrorHandlingOption.Null: createLineString = false; break; } } if (createLineString) { // Grabs m values if we have them var line = geometryFactory.CreateLineString(points); lines.Add(line); } } geom = (lines.Count != 1) ? (IGeometry)geometryFactory.CreateMultiLineString(lines.ToArray()) : lines[0]; return geom; }
/// <summary> /// Gets the line for the specified index /// </summary> /// <returns>A LineString or MultiLineString geometry created from this shape.</returns> protected IGeometry FromLine(IGeometryFactory factory) { if (factory == null) factory = Geometry.DefaultFactory; var lines = new List<IBasicLineString>(); foreach (var part in _shapeRange.Parts) { var coords = GetCoordinates(part); lines.Add(factory.CreateLineString(coords)); } if (lines.Count == 1) return (IGeometry)lines[0]; return factory.CreateMultiLineString(lines.ToArray()); }
/// <summary> /// Reads a stream and converts the shapefile record to an equilivent geometry object. /// </summary> /// <param name="file">The stream to read.</param> /// <param name="geometryFactory">The geometry factory to use when making the object.</param> /// <returns>The Geometry object that represents the shape file record.</returns> public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory) { int shapeTypeNum = file.ReadInt32(); ShapeGeometryTypes shapeType = (ShapeGeometryTypes)Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString()); if (shapeType == ShapeGeometryTypes.NullShape) return null; if( ! ( shapeType == ShapeGeometryTypes.LineString || shapeType == ShapeGeometryTypes.LineStringM || shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM )) throw new ShapefileException("Attempting to load a non-arc as arc."); //read and for now ignore bounds. double[] box = new double[4]; for (int i = 0; i < 4; i++) { double d= file.ReadDouble(); box[i] =d; } int numParts = file.ReadInt32(); int numPoints = file.ReadInt32(); int[] partOffsets = new int[numParts]; for (int i = 0; i < numParts; i++) partOffsets[i] = file.ReadInt32(); ILineString[] lines = new ILineString[numParts]; int start, finish, length; for (int part = 0; part < numParts; part++) { start = partOffsets[part]; if (part == numParts - 1) finish = numPoints; else finish = partOffsets[part + 1]; length = finish - start; CoordinateList points = new CoordinateList(); points.Capacity=length; ICoordinate external; for (int i = 0; i < length; i++) { external = new Coordinate(file.ReadDouble(),file.ReadDouble()); geometryFactory.PrecisionModel.MakePrecise( external); points.Add(external); } if (numPoints < 2) lines[part] = geometryFactory.CreateLineString(null as Topology.Geometries.ICoordinate[]); else lines[part] = geometryFactory.CreateLineString(points.ToArray()); } //If we have Z-coordinates, read them.. if (shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM) { //z-Bounds double zMin = file.ReadDouble(); double zMax = file.ReadDouble(); for (int part = 0; part < numParts; part++) { start = partOffsets[part]; if (part == numParts - 1) finish = numPoints; else finish = partOffsets[part + 1]; length = finish - start; for (int i = 0; i < length; i++) { double val = file.ReadDouble(); if (numPoints > 1) { lines[part].Coordinates[i].Z = val; } } } } //If we have M-coordinates, read them.. if (shapeType == ShapeGeometryTypes.LineStringM || shapeType == ShapeGeometryTypes.LineStringZM) { //m-Bounds double mMin = file.ReadDouble(); double mMax = file.ReadDouble(); for (int part = 0; part < numParts; part++) { start = partOffsets[part]; if (part == numParts - 1) finish = numPoints; else finish = partOffsets[part + 1]; length = finish - start; for (int i = 0; i < length; i++) { double val = file.ReadDouble(); //dont store.. } } } return geometryFactory.CreateMultiLineString(lines); }
/// <summary> /// Gets the line for the specified index /// </summary> /// <returns>A LineString or MultiLineString geometry created from this shape.</returns> protected IGeometry FromLine(IGeometryFactory factory) { if (factory == null) factory = Geometry.DefaultFactory; List<IBasicLineString> lines = new List<IBasicLineString>(); foreach (PartRange part in _shapeRange.Parts) { int i = part.StartIndex; List<Coordinate> coords = new List<Coordinate>(); foreach (Vertex d in part) { Coordinate c = new Coordinate(d.X, d.Y); coords.Add(c); if (M != null && M.Length > 0) c.M = M[i]; if (Z != null && Z.Length > 0) c.Z = Z[i]; i++; } lines.Add(factory.CreateLineString(coords)); } if (lines.Count == 1) return (IGeometry)lines[0]; return factory.CreateMultiLineString(lines.ToArray()); }
private ILineString ReprojectLineString(IGeometryFactory factory, ILineString line, ISpatialReference @from, ISpatialReference to, bool lineString = true) { return lineString ? factory.CreateLineString(Reproject(line.CoordinateSequence, from, to)) : factory.CreateLinearRing(Reproject(line.CoordinateSequence, from, to)); }
private static void GenerateLines(IGeometryFactory factory, ICollection<IGeometry> geometry, Random rndGen) { var numLines = rndGen.Next(10, 100); for (var lineIndex = 0; lineIndex < numLines; lineIndex++) { var numVerticies = rndGen.Next(4, 15); var vertices = new GeoPoint[numVerticies]; var lastPoint = new GeoPoint(rndGen.NextDouble()*1000, rndGen.NextDouble()*1000); vertices[0] = lastPoint; for (var vertexIndex = 1; vertexIndex < numVerticies; vertexIndex++) { var nextPoint = new GeoPoint(lastPoint.X + rndGen.Next(-50, 50), lastPoint.Y + rndGen.Next(-50, 50)); vertices[vertexIndex] = nextPoint; lastPoint = nextPoint; } geometry.Add(factory.CreateLineString(vertices)); } }
private static ILineal RandomLinealZ(IGeometryFactory geometryFactory) { switch (Random.Next(0, 2)) { case 0: return geometryFactory.CreateLineString(RandomCoordinatesZ(geometryFactory, 2, 10)); case 1: var ls = new ILineString[Random.Next(2, 5)]; for (int i = 0; i < ls.Length; i++) ls[i] = geometryFactory.CreateLineString(RandomCoordinatesZ(geometryFactory, 2, 15)); return geometryFactory.CreateMultiLineString(ls); } return geometryFactory.CreateLineString(RandomCoordinatesZ(geometryFactory, 2, 10)); }
internal static NTSLineString ToNTSLineString(Geometries.LineString geom, IGeometryFactory factory) { NTSCoordinate[] coordinates = new NTSCoordinate[geom.NumPoints]; int index = 0; foreach (Geometries.Point point in geom.Vertices) coordinates[index++] = ToNTSCoordinate(point, factory); return factory.CreateLineString(coordinates) as NTSLineString; }
/// <summary> /// /// </summary> /// <param name="geometry"></param> /// <param name="factory"></param> /// <returns></returns> public IGeometry Edit(IGeometry geometry, IGeometryFactory factory) { if (geometry is ILinearRing) return factory.CreateLinearRing(Edit(geometry.Coordinates, geometry)); if (geometry is ILineString) return factory.CreateLineString(Edit(geometry.Coordinates, geometry)); if (geometry is Point) { ICoordinate[] newCoordinates = Edit(geometry.Coordinates, geometry); return factory.CreatePoint((newCoordinates.Length > 0) ? newCoordinates[0] : null); } return geometry; }
private static IGeometry ToLinestring(IGeometryFactory factory, Ordinates ordinates, List<Tuple<Coordinate, double>> tuples) { var seq = factory.CoordinateSequenceFactory.Create(tuples.Count, ordinates); for (var i = 0; i < tuples.Count; i++) { seq.SetOrdinate(i, Ordinate.X, tuples[i].Item1.X); seq.SetOrdinate(i, Ordinate.Y, tuples[i].Item1.Y); seq.SetOrdinate(i, Ordinate.Z, tuples[i].Item1.Z); seq.SetOrdinate(i, Ordinate.M, tuples[i].Item2); } var lineString = factory.CreateLineString(seq); tuples.Clear(); return lineString; }
/// <summary> /// Transforms a <see cref="GeoAPI.Geometries.ILineString"/>. /// </summary> /// <param name="l">LineString to transform</param> /// <param name="transform">MathTransform</param> /// <param name="targetFactory">The factory to create the target geometry</param> /// <returns>Transformed LineString</returns> public static ILineString TransformLineString(ILineString l, IMathTransform transform, IGeometryFactory targetFactory) { try { return targetFactory.CreateLineString(TransformCoordinates(l.Coordinates, transform)); } catch { return null; } }
private IGeometry ToNodedLines(ICollection<ISegmentString> segStrings, IGeometryFactory geomFact) { var lines = new List<IGeometry>(); foreach (NodedSegmentString nss in segStrings) { // skip collapsed lines if (nss.Count < 2) continue; //Coordinate[] pts = getCoords(nss); var pts = nss.NodeList.GetSplitCoordinates(); lines.Add(geomFact.CreateLineString(pts)); } return geomFact.BuildGeometry(lines); }
/// <summary> /// Creates a <c>LineString</c> using the next token in the stream. /// </summary> /// <param name="tokens"> /// Tokenizer over a stream of text in Well-known Text /// format. The next tokens must form a <LineString Text. /// </param> /// <param name="factory"> </param> /// <returns> /// A <c>LineString</c> specified by the next /// token in the stream.</returns> private ILineString ReadLineStringText(IEnumerator<Token> tokens, IGeometryFactory factory) { return factory.CreateLineString(GetCoordinates(tokens, false)); }
private static GeoAPI.Geometries.ILineString ReadLineString(byte[] geom, ref int idx, bool isLittleEndian, IGeometryFactory factory) { double[] adfTuple = new double[2]; int nPointCount; int iPoint; nPointCount = ReadUInt32(geom, ref idx, isLittleEndian); if (nPointCount < 0 || nPointCount > Int32.MaxValue / (2 * 8)) throw new ApplicationException("Currupt SpatialLite geom"); List<GeoAPI.Geometries.Coordinate> pts = new List<GeoAPI.Geometries.Coordinate>(); for (iPoint = 0; iPoint < nPointCount; iPoint++) { pts.Add(ReadPoint(geom, ref idx, isLittleEndian)); } return factory.CreateLineString(pts.ToArray()); }
/// <summary> /// Creates a LineString with the same coordinates as this segment /// </summary> /// <param name="geomFactory">the geometery factory to use</param> /// <returns>A LineString with the same geometry as this segment</returns> public ILineString ToGeometry(IGeometryFactory geomFactory) { return geomFactory.CreateLineString(new[] { _p0, _p1 }); }
/// <summary> /// Creates a <c>LineString</c> using the next token in the stream. /// </summary> /// <param name="tokens"> /// Tokenizer over a stream of text in Well-known Text /// format. The next tokens must form a <LineString Text. /// </param> /// <param name="factory"> </param> /// <returns> /// A <c>LineString</c> specified by the next /// token in the stream.</returns> private ILineString ReadLineStringText(IEnumerator<Token> tokens, IGeometryFactory factory) { var hasZ = false; var coords = GetCoordinates(tokens, false, ref hasZ); return factory.CreateLineString(ToSequence(hasZ, coords)); }