/// <summary> /// Returns a CoordinateSequence based on the given coordinate sequence; whether or not the /// array is copied is implementation-dependent. /// </summary> /// <param name="coordSeq"></param> /// <returns></returns> public ICoordinateSequence Create(ICoordinateSequence coordSeq) { if (type == PackedType.Double) { return(new PackedDoubleCoordinateSequence(coordSeq.ToCoordinateArray(), dimension)); } return(new PackedFloatCoordinateSequence(coordSeq.ToCoordinateArray(), dimension)); }
public static Point3d?GetCentroid(IList <Point3d> points) { Point3d?result = null; var coordinates = new List <Coordinate>(); foreach (var point in points) { var coordinate = new Coordinate() { X = point.X, Y = point.Y, Z = 0 }; coordinates.Add(coordinate); } ICoordinateSequence coordinateSequence = CoordinateArraySequenceFactory.Instance.Create(coordinates.ToArray()); var geometryF = new DwgWriter(); var polygon = geometryF.GeometryFactory.CreatePolygon(coordinateSequence.ToCoordinateArray()); var coords = Centroid.GetCentroid(polygon); if (coords != null) { result = new Point3d(coords.X, coords.Y, coords.Z); } return(result); }
///** Convience method for STRUCT construction. */ //private STRUCT toSTRUCT( Datum attributes[], String dataType ) // throws SQLException //{ // if( dataType.startsWith("*.")){ // dataType = "DRA."+dataType.substring(2);//TODO here // } // StructDescriptor descriptor = // StructDescriptor.createDescriptor( dataType, connection ); // return new STRUCT( descriptor, connection, attributes ); //} ///** // * Convience method for ARRAY construction. // * <p> // * Compare and contrast with toORDINATE - which treats <code>Double.NaN</code> // * as<code>NULL</code></p> // */ //private ARRAY toARRAY( double doubles[], String dataType ) // throws SQLException //{ // ArrayDescriptor descriptor = // ArrayDescriptor.createDescriptor( dataType, connection ); // return new ARRAY( descriptor, connection, doubles ); //} ///** // * Convience method for ARRAY construction. // */ //private ARRAY toARRAY( int ints[], String dataType ) // throws SQLException //{ // ArrayDescriptor descriptor = // ArrayDescriptor.createDescriptor( dataType, connection ); // return new ARRAY( descriptor, connection, ints ); //} ///** // * Convience method for NUMBER construction. // * <p> // * Double.NaN is represented as <code>NULL</code> to agree // * with JTS use.</p> // */ //private NUMBER toNUMBER( double number ) throws SQLException{ // if( Double.isNaN( number )){ // return null; // } // return new NUMBER( number ); //} /** * reverses the coordinate order * * @param factory * @param sequence * * @return CoordinateSequence reversed sequence */ private ICoordinateSequence reverse(ICoordinateSequenceFactory factory, ICoordinateSequence sequence) { var list = new CoordinateList(sequence.ToCoordinateArray()); list.Reverse(); return(factory.Create(list.ToCoordinateArray())); }
/// <summary> /// /// </summary> /// <returns></returns> protected override Envelope ComputeEnvelopeInternal() { if (IsEmpty) { return(new Envelope()); } //Convert to array, then access array directly, to avoid the function-call overhead //of calling Getter millions of times. ToArray may be inefficient for //non-BasicCoordinateSequence CoordinateSequences. [Jon Aquino] Coordinate[] coordinates = _points.ToCoordinateArray(); double minx = coordinates[0].X; double miny = coordinates[0].Y; double maxx = coordinates[0].X; double maxy = coordinates[0].Y; for (int i = 1; i < coordinates.Length; i++) { minx = minx < coordinates[i].X ? minx : coordinates[i].X; maxx = maxx > coordinates[i].X ? maxx : coordinates[i].X; miny = miny < coordinates[i].Y ? miny : coordinates[i].Y; maxy = maxy > coordinates[i].Y ? maxy : coordinates[i].Y; } return(new Envelope(minx, maxx, miny, maxy)); }
/// <summary> /// /// </summary> /// <param name="coords"></param> /// <param name="parent"></param> /// <returns></returns> protected override ICoordinateSequence TransformCoordinates(ICoordinateSequence coords, IGeometry parent) { var srcPts = coords.ToCoordinateArray(); var newPts = SnapLine(srcPts, _snapPts); return(Factory.CoordinateSequenceFactory.Create(newPts)); }
/// <summary> /// Creates a <see cref="LineString" /> whose coordinates are in the reverse order of this objects. /// </summary> /// <returns>A <see cref="LineString" /> with coordinates in the reverse order.</returns> public ILineString Reverse() { ICoordinateSequence seq = (ICoordinateSequence)points.Clone(); // Personalized implementation using Array.Reverse: maybe it's faster? ICoordinate[] array = seq.ToCoordinateArray(); Array.Reverse(array); return(Factory.CreateLineString(array)); }
/// <inheritdoc cref="GeometryTransformer.TransformCoordinates(ICoordinateSequence, IGeometry)"/> protected override ICoordinateSequence TransformCoordinates(ICoordinateSequence coords, IGeometry parent) { var inputPts = coords.ToCoordinateArray(); var newPts = inputPts.Length == 0 ? new Coordinate[0] : DouglasPeuckerLineSimplifier.Simplify(inputPts, _container.DistanceTolerance); return(Factory.CoordinateSequenceFactory.Create(newPts)); }
protected override ICoordinateSequence TransformCoordinates( ICoordinateSequence coords, IGeometry parent) { var inputPts = coords.ToCoordinateArray(); var newPts = Densifier .DensifyPoints(inputPts, _distanceTolerance, parent.PrecisionModel); // prevent creation of invalid LineStrings if (parent is ILineString && newPts.Length == 1) { newPts = new Coordinate[0]; } return(Factory.CoordinateSequenceFactory.Create(newPts)); }
protected override ICoordinateSequence TransformCoordinates(ICoordinateSequence coords, IGeometry parent) { Coordinate[] inputPts = coords.ToCoordinateArray(); Coordinate[] newPts; if (inputPts.Length == 0) { newPts = new Coordinate[0]; } else { newPts = VWLineSimplifier.Simplify(inputPts, _distanceTolerance); } return(Factory.CoordinateSequenceFactory.Create(newPts)); }
/// <summary> /// Creates a <see cref="LineString" /> whose coordinates are in the reverse order of this objects. /// </summary> /// <returns>A <see cref="LineString" /> with coordinates in the reverse order.</returns> public virtual ILineString Reverse() { ICoordinateSequence seq = (ICoordinateSequence)points.Clone(); // Personalized implementation using Array.Reverse: maybe it's faster? ICoordinate[] array = seq.ToCoordinateArray(); Array.Reverse(array); return(Factory.CreateLineString(array)); /* * // Standard implementation : direct port of JTS code * CoordinateSequences.Reverse(seq); * return Factory.CreateLineString(seq); */ }
private ICoordinateSequence Add(ICoordinateSequence seq1, ICoordinateSequence seq2) { if (seq1 == null) { return(seq2); } if (seq2 == null) { return(seq1); } Coordinate[] c1 = seq1.ToCoordinateArray(); Coordinate[] c2 = seq2.ToCoordinateArray(); Coordinate[] c3 = new Coordinate[c1.Length + c2.Length]; Array.Copy(c1, 0, c3, 0, c1.Length); Array.Copy(c2, 0, c3, c1.Length, c2.Length); return(factory.CoordinateSequenceFactory.Create(c3)); }
/** * Gets the ICoordinateSequence corresponding to a compound element. * * @param idxFirst * the first sub-element of the compound element * @param idxLast * the last sub-element of the compound element * @param sdoGeom * the SdoGeometry that holds the compound element. * @return */ private ICoordinateSequence GetCompoundCSeq(int idxFirst, int idxLast, SdoGeometry sdoGeom) { ICoordinateSequence cs = null; for (int i = idxFirst; i <= idxLast; i++) { // pop off the last element as it is added with the next // coordinate sequence if (cs != null && cs.Count > 0) { Coordinate[] coordinates = cs.ToCoordinateArray(); Coordinate[] newCoordinates = new Coordinate[coordinates.Length - 1]; Array.Copy(coordinates, 0, newCoordinates, 0, coordinates.Length - 1); cs = factory.CoordinateSequenceFactory.Create(newCoordinates); } cs = Add(cs, GetElementCSeq(i, sdoGeom, (i < idxLast))); } return(cs); }
public static Extents3d?GetExtent(IList <Point3d> points) { var coordinates = new List <Coordinate>(); foreach (var point in points) { var coordinate = new Coordinate() { X = point.X, Y = point.Y, Z = 0 }; coordinates.Add(coordinate); } ICoordinateSequence coordinateSequence = CoordinateArraySequenceFactory.Instance.Create(coordinates.ToArray()); var geometryF = new DwgWriter(); var polygon = geometryF.GeometryFactory.CreatePolygon(coordinateSequence.ToCoordinateArray()); var envelop = (Envelope)polygon.Envelope; var extent3D = new Extents3d(new Point3d(envelop.MinX, envelop.MinY, 0), new Point3d(envelop.MaxX, envelop.MaxY, 0)); return(extent3D); }
protected override ICoordinateSequence TransformCoordinates(ICoordinateSequence coords, IGeometry parent) { Coordinate[] inputPts = coords.ToCoordinateArray(); Coordinate[] newPts; if (inputPts.Length == 0) newPts = new Coordinate[0]; else newPts = VWLineSimplifier.Simplify(inputPts, _distanceTolerance); return Factory.CoordinateSequenceFactory.Create(newPts); }
/// <summary> /// /// </summary> /// <param name="coords"></param> /// <param name="parent"></param> /// <returns></returns> protected override ICoordinateSequence TransformCoordinates(ICoordinateSequence coords, IGeometry parent) { Coordinate[] inputPts = coords.ToCoordinateArray(); Coordinate[] newPts = inputPts.Length == 0 ? new Coordinate[0] : DouglasPeuckerLineSimplifier.Simplify(inputPts, _container.DistanceTolerance); return Factory.CoordinateSequenceFactory.Create(newPts); }
/// <summary> /// /// </summary> /// <param name="coords"></param> /// <param name="parent"></param> /// <returns></returns> protected override ICoordinateSequence TransformCoordinates(ICoordinateSequence coords, IGeometry parent) { ICoordinate[] inputPts = coords.ToCoordinateArray(); ICoordinate[] newPts = DouglasPeuckerLineSimplifier.Simplify(inputPts, container.DistanceTolerance); return(factory.CoordinateSequenceFactory.Create(newPts)); }
/// <summary> /// Computes whether a ring defined by a coordinate sequence is oriented counter-clockwise. /// </summary>> /// <remarks> /// <list type="Bullet"> /// <item>The list of points is assumed to have the first and last points equal.</item> /// <item>This will handle coordinate lists which contain repeated points.</item> /// </list> /// <para>This algorithm is only guaranteed to work with valid rings. If the ring is invalid (e.g. self-crosses or touches), the computed result may not be correct.</para> /// </remarks> /// <param name="ring">A coordinate sequence froming a ring</param> /// <returns>true if the ring is oriented <see cref="Orientation.CounterClockwise"/></returns> /// <exception cref="ArgumentException">If there are too few points to determine orientation (<4)</exception> public static bool IsCCW(ICoordinateSequence ring) { return IsCCW(ring.ToCoordinateArray()); }
protected override ICoordinateSequence TransformCoordinates( ICoordinateSequence coords, IGeometry parent) { var inputPts = coords.ToCoordinateArray(); var newPts = Densifier .DensifyPoints(inputPts, _distanceTolerance, parent.PrecisionModel); // prevent creation of invalid linestrings if (parent is ILineString && newPts.Length == 1) { newPts = new Coordinate[0]; } return Factory.CoordinateSequenceFactory.Create(newPts); }
private ICoordinateSequence Add(ICoordinateSequence seq1, ICoordinateSequence seq2) { if (seq1 == null) { return seq2; } if (seq2 == null) { return seq1; } Coordinate[] c1 = seq1.ToCoordinateArray(); Coordinate[] c2 = seq2.ToCoordinateArray(); Coordinate[] c3 = new Coordinate[c1.Length + c2.Length]; Array.Copy(c1, 0, c3, 0, c1.Length); Array.Copy(c2, 0, c3, c1.Length, c2.Length); return factory.CoordinateSequenceFactory.Create(c3); }
/// <summary> /// Computes whether a ring defined by a coordinate sequence is oriented counter-clockwise. /// </summary>> /// <remarks> /// <list type="Bullet"> /// <item>The list of points is assumed to have the first and last points equal.</item> /// <item>This will handle coordinate lists which contain repeated points.</item> /// </list> /// <para>This algorithm is only guaranteed to work with valid rings. If the ring is invalid (e.g. self-crosses or touches), the computed result may not be correct.</para> /// </remarks> /// <param name="ring">A coordinate sequence froming a ring</param> /// <returns>true if the ring is oriented <see cref="Orientation.CounterClockwise"/></returns> /// <exception cref="ArgumentException">If there are too few points to determine orientation (<4)</exception> public static bool IsCCW(ICoordinateSequence ring) { return(IsCCW(ring.ToCoordinateArray())); }
/// <summary> /// /// </summary> /// <param name="coords"></param> /// <param name="parent"></param> /// <returns></returns> protected override ICoordinateSequence TransformCoordinates(ICoordinateSequence coords, IGeometry parent) { ICoordinate[] srcPts = coords.ToCoordinateArray(); ICoordinate[] newPts = SnapLine(srcPts, snapPts); return factory.CoordinateSequenceFactory.Create(newPts); }
///** Convience method for STRUCT construction. */ //private STRUCT toSTRUCT( Datum attributes[], String dataType ) // throws SQLException //{ // if( dataType.startsWith("*.")){ // dataType = "DRA."+dataType.substring(2);//TODO here // } // StructDescriptor descriptor = // StructDescriptor.createDescriptor( dataType, connection ); // return new STRUCT( descriptor, connection, attributes ); //} ///** // * Convience method for ARRAY construction. // * <p> // * Compare and contrast with toORDINATE - which treats <code>Double.NaN</code> // * as<code>NULL</code></p> // */ //private ARRAY toARRAY( double doubles[], String dataType ) // throws SQLException //{ // ArrayDescriptor descriptor = // ArrayDescriptor.createDescriptor( dataType, connection ); // return new ARRAY( descriptor, connection, doubles ); //} ///** // * Convience method for ARRAY construction. // */ //private ARRAY toARRAY( int ints[], String dataType ) // throws SQLException //{ // ArrayDescriptor descriptor = // ArrayDescriptor.createDescriptor( dataType, connection ); // return new ARRAY( descriptor, connection, ints ); //} ///** // * Convience method for NUMBER construction. // * <p> // * Double.NaN is represented as <code>NULL</code> to agree // * with JTS use.</p> // */ //private NUMBER toNUMBER( double number ) throws SQLException{ // if( Double.isNaN( number )){ // return null; // } // return new NUMBER( number ); //} /** * reverses the coordinate order * * @param factory * @param sequence * * @return CoordinateSequence reversed sequence */ private ICoordinateSequence reverse(ICoordinateSequenceFactory factory, ICoordinateSequence sequence) { var list = new CoordinateList(sequence.ToCoordinateArray()); list.Reverse(); return factory.Create(list.ToCoordinateArray()); }
/// <summary> /// Returns a CoordinateSequence based on the given coordinate sequence; whether or not the /// array is copied is implementation-dependent. /// </summary> /// <param name="coordSeq"></param> /// <returns></returns> public ICoordinateSequence Create(ICoordinateSequence coordSeq) { if (type == PackedType.Double) return new PackedDoubleCoordinateSequence(coordSeq.ToCoordinateArray(), dimension); else return new PackedFloatCoordinateSequence(coordSeq.ToCoordinateArray(), dimension); }
private static void PerformTest(ICoordinateSequence sequence) { if (sequence == null) throw new ArgumentNullException("sequence"); Coordinate[] coordinates = sequence.ToCoordinateArray(); NodedSegmentString segmentString = new NodedSegmentString(coordinates, null); Stopwatch watch = new Stopwatch(); NodingValidator validator = new NodingValidator(new[] { segmentString }); validator.CheckValid(); watch.Start(); validator.CheckValid(); watch.Stop(); Console.WriteLine("NodingValidator.CheckValid => ElapsedMilliseconds: {0}", watch.ElapsedMilliseconds); BasicSegmentString segmentStringBasic = new BasicSegmentString(coordinates, null); FastNodingValidator fastValidator = new FastNodingValidator(new[] { segmentStringBasic }); watch.Reset(); watch.Start(); fastValidator.CheckValid(); watch.Stop(); Console.WriteLine("FastNodingValidator.CheckValid => ElapsedMilliseconds: {0}", watch.ElapsedMilliseconds); }