/// <summary> /// /// </summary> /// <param name="g0"></param> public GeometryGraphOperation(IGeometry g0) { ComputationPrecision = new PrecisionModel(g0.PrecisionModel); Arg = new GeometryGraph[1]; Arg[0] = new GeometryGraph(0, g0); }
public static bool TestHelper(string wkt) { PrecisionModel pm = new PrecisionModel(1, 0, 0); GeometryFactory fact = new GeometryFactory(pm, 0); //read wkt Geometry a = new GeometryWKTReader(fact).Create(wkt); //write wkb FileStream fs = new FileStream("TestFile.wkb", FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); GeometryWKBWriter bWriter = new GeometryWKBWriter(bw, fact); bWriter.Write(a, WKBByteOrder.Ndr); bw.Close(); fs.Close(); //read wkb fs = new FileStream("TestFile.wkb", FileMode.Open); byte[] bytes = new byte[fs.Length]; for(int i = 0; i < fs.Length; i++) { bytes[i] = (byte)fs.ReadByte(); } GeometryWKBReader bReader = new GeometryWKBReader(fact); Geometry geom = bReader.Create(bytes); fs.Close(); //write to wkt & compare with original text. bool results = ( Compare.WktStrings(wkt,a.toText())); return results; }
/// <summary> /// /// </summary> /// <param name="precisionModel"></param> /// <param name="quadrantSegments"></param> public OffsetCurveBuilder(PrecisionModel precisionModel, int quadrantSegments) { _precisionModel = precisionModel; // compute intersections in full precision, to provide accuracy // the points are rounded as they are inserted into the curve line _li = new RobustLineIntersector(); int limitedQuadSegs = quadrantSegments < 1 ? 1 : quadrantSegments; _filletAngleQuantum = Math.PI / 2.0 / limitedQuadSegs; }
/// <summary> /// Creates a <see cref="GeometryWKTReader">GeometryWKTReader</see> that creates objects using the given <b>GeometryFactory</b>. /// </summary> /// <param name="factory">The <b>GeometryFactory</b> used to create geometries.</param> public GeometryWKTReader(GeometryFactory factory) { if (factory == null) { throw new ArgumentNullException("factory"); } _factory = factory; _precisionModel = factory.getPrecisionModel(); }
/// <summary>Reduces precision pointwise, then snap-rounds. /// <para/> /// Note that output set may not contain non-unique linework /// (and thus cannot be used as input to Polygonizer directly). /// <c>UnaryUnion</c> is one way to make the linework unique. /// </summary> /// <param name="geom">A Geometry containing linework to node</param> /// <param name="scaleFactor">The precision model scale factor to use</param> /// <returns>The noded, snap-rounded linework</returns> public static IGeometry SnapRoundLines( IGeometry geom, double scaleFactor) { var pm = new PrecisionModel(scaleFactor); var gsr = new GeometrySnapRounder(pm); gsr.LineworkOnly = true; var snapped = gsr.Execute(geom); return(snapped); }
public GeometryFactory(PrecisionModel precisionModel, CoordinateType type, int dimension) { m_objPrecisionModel = precisionModel; m_enumCoordinateType = type; if (dimension < 2) { dimension = 2; } m_nCoordinateDimension = dimension; }
public void TestWriteLargeNumbers3() { PrecisionModel precisionModel = new PrecisionModel(1E9); GeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0); var point1 = geometryFactory.CreatePoint(new Coordinate(123456789012345678000000E9d, 10E9)); Assert.AreEqual(123456789012345690000000000000000d, point1.X); Assert.AreEqual(10000000000d, point1.Y); Assert.AreNotEqual("POINT (123456789012345690000000000000000 10000000000)", point1.AsText()); Assert.AreEqual("POINT (123456789012346000000000000000000 10000000000)", point1.AsText()); }
/// <summary> /// Initializes a new instance of the GeometryGraph class. /// </summary> public GeometryGraph(int argIndex, Geometry parentGeometry) { _argIndex = argIndex; _parentGeometry = parentGeometry; if (parentGeometry != null) { _precisionModel = parentGeometry.PrecisionModel; _SRID = parentGeometry.GetSRID(); Add(parentGeometry); } } // public GeometryGraph( int argIndex, Geometry parentGeometry )
/// <summary> /// Initializes a new instance of the <see cref="GrahamScanAlgorithm" /> class. /// </summary> /// <param name="source">The source coordinates.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> protected GrahamScanAlgorithm(IList <Coordinate> source, PrecisionModel precisionModel) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } _source = source; _hasResult = false; PrecisionModel = precisionModel ?? PrecisionModel.Default; }
public NetTopologySuiteTypeHandlerResolverFactory( CoordinateSequenceFactory?coordinateSequenceFactory, PrecisionModel?precisionModel, Ordinates handleOrdinates, bool geographyAsDefault) { _coordinateSequenceFactory = coordinateSequenceFactory ?? NtsGeometryServices.Instance.DefaultCoordinateSequenceFactory;; _precisionModel = precisionModel ?? NtsGeometryServices.Instance.DefaultPrecisionModel; _handleOrdinates = handleOrdinates == Ordinates.None ? _coordinateSequenceFactory.Ordinates : handleOrdinates; _geographyAsDefault = geographyAsDefault; }
public void TestReadLargeNumbers() { var precisionModel = new PrecisionModel(1E9); var geometryFactory = new GeometryFactory(precisionModel, 0); var reader = new WKTReader(geometryFactory); var point1 = reader.Read("POINT (123456789.01234567890 10)"); var point2 = geometryFactory.CreatePoint(new Coordinate(123456789.01234567890, 10)); Assert.AreEqual(point1.Coordinate.X, point2.Coordinate.X, 1E-7); Assert.AreEqual(point1.Coordinate.Y, point2.Coordinate.Y, 1E-7); }
public void TestReadLargeNumbers() { var precisionModel = new PrecisionModel(1E9); var geometryFactory = new GeometryFactory(precisionModel, 0); var reader = new WKTReader(geometryFactory); var point1 = ((Point)reader.Read("POINT (123456789.01234567890 10)")).CoordinateSequence; var point2 = geometryFactory.CreatePoint(new Coordinate(123456789.01234567890, 10)).CoordinateSequence; Assert.That(point1.GetOrdinate(0, Ordinate.X), Is.EqualTo(point2.GetOrdinate(0, Ordinate.X)).Within(1E-7)); Assert.That(point1.GetOrdinate(0, Ordinate.Y), Is.EqualTo(point2.GetOrdinate(0, Ordinate.Y)).Within(1E-7)); }
/// <summary> /// This method computes the actual value of the intersection point. /// To obtain the maximum precision from the intersection calculation, /// the coordinates are normalized by subtracting the minimum /// ordinate values (in absolute value). This has the effect of /// removing common significant digits from the calculation to /// maintain more bits of precision. /// </summary> /// <param name="p1"></param> /// <param name="p2"></param> /// <param name="q1"></param> /// <param name="q2"></param> /// <returns></returns> private Coordinate Intersection(Coordinate p1, Coordinate p2, Coordinate q1, Coordinate q2) { Coordinate n1 = new Coordinate(p1); Coordinate n2 = new Coordinate(p2); Coordinate n3 = new Coordinate(q1); Coordinate n4 = new Coordinate(q2); Coordinate normPt = new Coordinate(); NormalizeToEnvCentre(n1, n2, n3, n4, normPt); Coordinate intPt = HCoordinate.Intersection(n1, n2, n3, n4); intPt.X += normPt.X; intPt.Y += normPt.Y; /* * * MD - May 4 2005 - This is still a problem. Here is a failure case: * * LINESTRING (2089426.5233462777 1180182.3877339689, 2085646.6891757075 1195618.7333999649) * LINESTRING (1889281.8148903656 1997547.0560044837, 2259977.3672235999 483675.17050843034) * int point = (2097408.2633752143, 1144595.8008114607) */ if (!IsInSegmentEnvelopes(intPt)) { Trace.WriteLine("Intersection outside segment envelopes: " + intPt); } /* * // disabled until a better solution is found * if (!IsInSegmentEnvelopes(intPt)) * { * Trace.WriteLine("first value outside segment envelopes: " + intPt); * * IteratedBisectionIntersector ibi = new IteratedBisectionIntersector(p1, p2, q1, q2); * intPt = ibi.Intersection; * } * if (!IsInSegmentEnvelopes(intPt)) * { * Trace.WriteLine("ERROR - outside segment envelopes: " + intPt); * * IteratedBisectionIntersector ibi = new IteratedBisectionIntersector(p1, p2, q1, q2); * Coordinate testPt = ibi.Intersection; * } */ if (PrecisionModel != null) { PrecisionModel.MakePrecise(intPt); } return(intPt); }
/// <summary> /// Initializes a new instance of the <see cref="GeometryList{T}" /> class. /// </summary> /// <param name="capacity">The number of elements that the list can initially store.</param> /// <param name="precisionModel">The precision model.</param> /// <param name="referenceSystem">The reference system.</param> /// <param name="metadata">The metadata.</param> /// <exception cref="System.ArgumentOutOfRangeException">The capacity is less than 0.</exception> public GeometryList(Int32 capacity, PrecisionModel precisionModel, IReferenceSystem referenceSystem, IDictionary <String, Object> metadata) : base(precisionModel, referenceSystem, metadata) { if (capacity < 0) { throw new ArgumentOutOfRangeException("capacity", "The capacity is less than 0."); } _geometries = new T[capacity]; _size = 0; _version = 0; }
/// <summary> /// Inserts a coordinate into the linear ring at the specified index. /// </summary> /// <param name="index">The zero-based index at which the coordinate should be inserted.</param> /// <param name="coordinate">The coordinate.</param> /// <exception cref="System.ArgumentOutOfRangeException"> /// The index is less than 0. /// or /// Index is greater than the number of coordinates. /// </exception> public override void Insert(Int32 index, Coordinate coordinate) { if (index == 0) // insertion of new starting coordinate { _coordinates[_coordinates.Count - 1] = PrecisionModel.MakePrecise(coordinate); base.Insert(0, coordinate); } else // insertion of new inner coordinate { base.Insert(index, PrecisionModel.MakePrecise(coordinate)); } }
public void TestML() { { const double scale = 2.0E10; var precisionModel = new PrecisionModel(scale); var gs = new NtsGeometryServices(precisionModel, 0); //var geometryFactory = gs.CreateGeometryFactory(); var reader = new WKTReader(gs); var lineStringA = (LineString) reader.Read("LINESTRING (-93.40178610435 -235.5437531975, -401.24229900825 403.69365857925)"); var lineStringB = (LineString) reader.Read("LINESTRING (-50.0134121926 -145.44686640725, -357.8539250965 493.7905453695)"); var lineStringC = (LineString) reader.Read("LINESTRING (-193.8964147753 -30.64653554935, -186.68866383205 -34.1176054623)"); var middlePoint = (Point)reader.Read("POINT (-203.93366864454998 174.171839481125)"); var lineStrings = new List <LineString>(); lineStrings.Add(lineStringA); lineStrings.Add(lineStringB); lineStrings.Add(lineStringC); var noder = new GeometryNoder(precisionModel); var nodedLineStrings = noder.Node(lineStrings.ToArray()); double shortestDistanceToPointBeforeNoding = double.MaxValue; foreach (var lineString in lineStrings) { shortestDistanceToPointBeforeNoding = Math.Min(lineString.Distance(middlePoint), shortestDistanceToPointBeforeNoding); } double shortestDistanceToPointAfterNoding = double.MaxValue; foreach (var lineString in nodedLineStrings) { shortestDistanceToPointAfterNoding = Math.Min(lineString.Distance(middlePoint), shortestDistanceToPointAfterNoding); } double difference = Math.Abs(shortestDistanceToPointAfterNoding - shortestDistanceToPointBeforeNoding); TestContext.WriteLine("Scale: {0}", scale); TestContext.WriteLine("Distance to point before noding: {0}", shortestDistanceToPointBeforeNoding); TestContext.WriteLine("Distance to point after noding: {0}", shortestDistanceToPointAfterNoding); TestContext.WriteLine("Difference is {0} and should be lesser than {1}", difference, 1.0 / scale); const double roughTolerance = 10.0; Assert.IsTrue(difference < roughTolerance, "this difference should should be lesser than " + 1.0 / scale); } }
/// <summary> /// Initializes a new instance of the <see cref="ShamosHoeyAlgorithm" /> class. /// </summary> /// <param name="source">The collection of coordinates representing multiple line strings.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public ShamosHoeyAlgorithm(IEnumerable <IEnumerable <Coordinate> > source, PrecisionModel precisionModel) { if (source == null) { throw new ArgumentNullException(nameof(source)); } this.PrecisionModel = precisionModel ?? PrecisionModel.Default; this.eventQueue = new PresortedEventQueue(source); this.sweepLine = new SweepLine(source, precisionModel); this.hasResult = false; }
public virtual void Intersection(string wktA, string wktB, PrecisionModel pm) { Console.WriteLine("Running example using Precision Model = " + pm); var fact = new GeometryFactory(pm); var wktRdr = new WKTReader(fact); var A = wktRdr.Read(wktA); var B = wktRdr.Read(wktB); var C = A.Intersection(B); Console.WriteLine("A intersection B = " + C); }
/// <summary> /// Initializes a new instance of the <see cref="ShamosHoeyAlgorithm" /> class. /// </summary> /// <param name="source">The collection of coordinates representing multiple line strings.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public ShamosHoeyAlgorithm(IEnumerable <IBasicLineString> source, PrecisionModel precisionModel = null) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } PrecisionModel = precisionModel ?? PrecisionModel.Default; _eventQueue = new PresortedEventQueue(source.Select(lineString => lineString == null ? null : lineString.Coordinates)); _sweepLine = new SweepLine(source.Select(hole => hole.Coordinates), precisionModel); _hasResult = false; }
/// <summary> /// Initializes a new instance of the <see cref="ShamosHoeyAlgorithm" /> class. /// </summary> /// <param name="source">The line string.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public ShamosHoeyAlgorithm(IBasicLineString source, PrecisionModel precisionModel = null) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } PrecisionModel = precisionModel ?? PrecisionModel.Default; _eventQueue = new PresortedEventQueue(source.Coordinates); _sweepLine = new SweepLine(source.Coordinates, precisionModel); _hasResult = false; }
public void large_decimals_are_formatted_properly() { const string expected = "123456789012345680"; const decimal m = 123456789012345680; PrecisionModel precisionModel = new PrecisionModel(1E9); var formatter = CreateFormatter(precisionModel); string format = "0." + StringOfChar('#', formatter.NumberDecimalDigits); string actual = m.ToString(format, formatter); Assert.That(actual, Is.EqualTo(expected)); }
private static void PreciseCoordinateTester(PrecisionModel pm, double x1, double y1, double x2, double y2) { var p = new Coordinate(x1, y1); pm.MakePrecise(p); var pPrecise = new Coordinate(x2, y2); Assert.IsTrue(p.Equals2D(pPrecise), "Expected {0}, but got {1}", pPrecise, p); }
public virtual void Intersection(string wktA, string wktB, PrecisionModel pm) { Console.WriteLine("Running example using Precision Model = " + pm); var gs = new NtsGeometryServices(pm); var wktRdr = new WKTReader(gs); var A = wktRdr.Read(wktA); var B = wktRdr.Read(wktB); var C = A.Intersection(B); Console.WriteLine("A intersection B = " + C); }
/// <summary> /// Add a hole to the polygon. /// </summary> /// <param name="hole">The hole.</param> /// <exception cref="System.ArgumentNullException">The hole is null.</exception> public virtual void AddHole(IEnumerable <Coordinate> hole) { if (hole == null) { throw new ArgumentNullException("hole", "The hole is null."); } _holes.Add(Factory.CreateLinearRing(hole.Select(coordinate => PrecisionModel.MakePrecise(coordinate)))); _holes[_holes.Count - 1].GeometryChanged += new EventHandler(Hole_GeometryChanged); // add event handler OnGeometryChanged(); }
public GeometryPrecisionReducerTest() { pmFloat = new PrecisionModel(); pmFixed1 = new PrecisionModel(1); reducer = new GeometryPrecisionReducer(pmFixed1); reducerKeepCollapse = new GeometryPrecisionReducer(pmFixed1); gfFloat = new GeometryFactory(pmFloat, 0); reader = new WKTReader(gfFloat); reducerKeepCollapse.RemoveCollapsedComponents = false; }
/// <summary> /// Runs a ScaledNoder on input. /// Input vertices should be rounded to precision model. /// </summary> /// <param name="geom"></param> /// <param name="scaleFactor"></param> /// <returns>The noded geometry</returns> public static Geometry ScaledNoding(Geometry geom, double scaleFactor) { var segs = CreateSegmentStrings(geom); var fixedPM = new PrecisionModel(scaleFactor); var noder = new ScaledNoder(new MCIndexSnapRounder(new PrecisionModel(1.0)), fixedPM.Scale); noder.ComputeNodes(segs); var nodedSegStrings = noder.GetNodedSubstrings(); return(SegmentStringUtil.ToGeometry(nodedSegStrings, geom.Factory)); }
public void Setup() { this.defaultModel = new PrecisionModel(); this.floatingModel = new PrecisionModel(PrecisionModelType.Floating); this.floatingSingleModel = new PrecisionModel(PrecisionModelType.FloatingSingle); this.fixedLargeModel1 = new PrecisionModel(1000); this.fixedLargeModel2 = new PrecisionModel(1000000000000); this.fixedSmallModel1 = new PrecisionModel(0.001); this.fixedSmallModel2 = new PrecisionModel(0.000000000001); this.values = Enumerable.Range(1, 28).Select(value => Math.Pow((Double)value / 2, (value / 2) * ((value % 2 == 0) ? 1 : -1))).ToArray(); }
public void Test2() { IDbConnection connection = Global.GetEPSGDatabaseConnection(); PrecisionModel pm = new PrecisionModel(100.0, 0.0, 0.0); CoordinateTransformationEPSGFactory CTfactory = new CoordinateTransformationEPSGFactory(connection); ICoordinateTransformation UKNationalGrid1 = CTfactory.CreateFromTransformationCode("1681"); GeometryFactory geometryFactory = new GeometryFactory(pm, 4326); string wkt = "POINT ( -1 50 )"; Assertion.AssertEquals("Point 1", true, Compare2(wkt, "POINT (471659.59 11644.49)", geometryFactory, UKNationalGrid1)); }
public override void StartRun(int npts) { _sineStar = SineStarFactory.Create(new Coordinate(OriginX, OriginY), Size, npts, NumberOfArms, ArmRatio); double scale = npts / Size; var pm = new PrecisionModel(scale); _sinePolyCrinkly = GeometryPrecisionReducer.Reduce(_sineStar, pm); Console.WriteLine(); Console.WriteLine($"Running with # pts {_sinePolyCrinkly.NumPoints}"); ////if (npts <= 1000) Console.WriteLine(_sineStar); }
public abstract int GetLength(Geometry geometry); //length in 16bit words public static Envelope GetEnvelopeExternal(PrecisionModel precisionModel, Envelope envelope) { // get envelopse in external coordinates Coordinate min = new Coordinate(envelope.MinX, envelope.MinY); Coordinate max = new Coordinate(envelope.MaxX, envelope.MaxY); min = precisionModel.ToExternal(min); max = precisionModel.ToExternal(max); Envelope bounds = new Envelope(min.X, max.X, min.Y, max.Y); return(bounds); }
/// <summary> /// Tests if the geometry envelopes are disjoint, or empty. /// The disjoint test must take into account the precision model /// being used, since geometry coordinates may shift under rounding. /// </summary> /// <param name="a">The A operand geometry</param> /// <param name="b">The B operand geometry</param> /// <param name="pm">The precision model to use</param> /// <returns><c>true</c> if the geometry envelopes are disjoint or empty</returns> private static bool IsEnvDisjoint(Geometry a, Geometry b, PrecisionModel pm) { if (IsEmpty(a) || IsEmpty(b)) { return(true); } if (pm == null || pm.IsFloating) { return(a.EnvelopeInternal.Disjoint(b.EnvelopeInternal)); } return(IsDisjoint(a.EnvelopeInternal, b.EnvelopeInternal, pm)); }
/// <summary> /// Initializes a new instance of the <see cref="BentleyOttmannAlgorithm" /> class. /// </summary> /// <param name="source">The coordinates of the line string.</param> /// <param name="precisionModel">The precision model.</param> /// <exception cref="System.ArgumentNullException">The source is null.</exception> public BentleyOttmannAlgorithm(IList <Coordinate> source, PrecisionModel precisionModel = null) { if (source == null) { throw new ArgumentNullException("source", "The source is null."); } _source = source; PrecisionModel = precisionModel ?? PrecisionModel.Default; _eventQueue = new EventQueue(source); _sweepLine = new SweepLine(source, PrecisionModel); _hasResult = false; }
public void TestWriteLargeNumbers1() { IPrecisionModel precisionModel = new PrecisionModel(1E9); IGeometryFactory geometryFactory = new GeometryFactory(precisionModel, 0); var point1 = geometryFactory.CreatePoint(new Coordinate(123456789012345678d, 10E9)); Assert.AreEqual(123456789012345680d, point1.X); Assert.AreEqual(10000000000d, point1.Y); string actual = point1.AsText(); Assert.AreNotEqual("POINT (123456789012345680 10000000000)", actual); Assert.AreEqual("POINT (123456789012346000 10000000000)", actual); }
public static Geometry MCIndexNodingWithPrecision(Geometry geom, double scaleFactor) { var fixedPM = new PrecisionModel(scaleFactor); LineIntersector li = new RobustLineIntersector(); li.PrecisionModel = fixedPM; INoder noder = new MCIndexNoder(new IntersectionAdder(li)); noder.ComputeNodes(SegmentStringUtil.ExtractNodedSegmentStrings(geom)); return(SegmentStringUtil.ToGeometry(noder.GetNodedSubstrings(), geom.Factory)); }
/// <summary> /// Test getting and setting the properties /// </summary> public void Test_MultipleRead() { PrecisionModel pm = new PrecisionModel(1,0,0); GeometryFactory geometryFactory = new GeometryFactory(pm,-1); string filename= Global.GetUnitTestRootDirectory()+@"\IO\Shapefile\Testfiles\statepop.shp"; // tests two readers reading the file as the same time. Geotools.IO.ShapefileReader shpFile = new Geotools.IO.ShapefileReader(filename, geometryFactory); Geotools.IO.ShapefileReader shpFile2 = new Geotools.IO.ShapefileReader(filename, geometryFactory); foreach(object row in shpFile) { Assertion.AssertNotNull(row); foreach(object row2 in shpFile2) { Assertion.AssertNotNull(row2); } } }
public void Test_DataGrid() { PrecisionModel pm = new PrecisionModel(100000,0,0); GeometryFactory geometryFactory = new GeometryFactory(pm,-1); string filename= Global.GetUnitTestRootDirectory()+@"\IO\Shapefile\Testfiles\statepop"; ShapefileDataReader shpDataReader = Geotools.IO.Shapefile.CreateDataReader(filename, geometryFactory); // make sure the datagrid gets the column headings. DataGrid grid = new DataGrid(); grid.DataSource = shpDataReader; grid.DataBind(); TextWriter tempWriter = new StringWriter(); grid.RenderControl(new HtmlTextWriter(tempWriter)); string html = tempWriter.ToString(); bool same = Compare.CompareAgainstString(Global.GetUnitTestRootDirectory()+@"\IO\Shapefile\Testfiles\ExpectedDataGridDataReader.txt",html); Assertion.AssertEquals("Datagrid properties",true,same); }
/// <summary> /// Imports a shapefile into a database table. /// </summary> /// <remarks> /// This method assumes a table has already been crated in the database. /// Calling this method does not close the connection that is passed in. /// </remarks> /// <param name="filename"></param> /// <param name="connectionstring"></param> /// <param name="tableName"></param> /// <returns></returns> public static int ImportShapefile(string filename, string connectionstring, string tableName) { using (SqlConnection connection = new SqlConnection(connectionstring)) { int rowsAdded = -1; PrecisionModel pm = new PrecisionModel(); GeometryFactory geometryFactory = new GeometryFactory(pm, -1); DataTable shpDataTable = Topology.IO.Shapefile.CreateDataTable(filename, tableName, geometryFactory); string createTableSql = CreateDbTable(shpDataTable, true); SqlCommand createTableCommand = new SqlCommand(createTableSql, connection); connection.Open(); createTableCommand.ExecuteNonQuery(); string sqlSelect = String.Format("select * from {0}", tableName); SqlDataAdapter selectCommand = new SqlDataAdapter(sqlSelect, connection); // use a data adaptor - saves donig the inserts ourselves SqlDataAdapter dataAdapter = new SqlDataAdapter(); dataAdapter.SelectCommand = new SqlCommand(sqlSelect, connection); SqlCommandBuilder custCB = new SqlCommandBuilder(dataAdapter); DataSet ds = new DataSet(); // fill dataset dataAdapter.Fill(ds, shpDataTable.TableName); // copy rows from our datatable to the empty table in the DataSet int i = 0; foreach (DataRow row in shpDataTable.Rows) { DataRow newRow = ds.Tables[0].NewRow(); newRow.ItemArray = row.ItemArray; //gotcha! - new row still needs to be added to the table. //NewRow() just creates a new row with the same schema as the table. It does //not add it to the table. ds.Tables[0].Rows.Add(newRow); i++; } // update all the rows in batch rowsAdded = dataAdapter.Update(ds, shpDataTable.TableName); int iRows = shpDataTable.Rows.Count; Debug.Assert(rowsAdded != iRows, String.Format("{0} of {1] rows were added to the database.", rowsAdded, shpDataTable.Rows.Count)); return rowsAdded; } }
/// <summary> /// Initializes a new instance of the GeometrySVGWriter class. /// </summary> public GeometrySVGWriter(PrecisionModel precisionModel) : this(precisionModel,"",5) { }
/// <summary> /// Initializes a new instance of the <see cref="IteratedNoder"/> class. /// </summary> /// <param name="pm"></param> public IteratedNoder(PrecisionModel pm) { _li = new RobustLineIntersector(); _li.PrecisionModel = pm; }
/// <summary> /// Converts a Coordinate to Point Text format then Appends it to the writer. /// </summary> /// <param name="coordinate">The Coordinate to process.</param> /// <param name="level"></param> /// <param name="writer">The output stream writer to Append to.</param> /// <param name="precisionModel">The PrecisionModel to use to convert from a precise /// coordinate to an external coordinate.</param> protected void AppendPointText(Coordinate coordinate, int level, StringWriter writer, PrecisionModel precisionModel) { if (coordinate == null) { writer.Write("EMPTY"); } else { writer.Write("("); AppendCoordinate(coordinate, writer, precisionModel); writer.Write(")"); } }
/// <summary> /// Converts a Coordinate to <Point> format, then Appends /// it to the writer. /// </summary> /// <param name="coordinate">The Coordinate to process.</param> /// <param name="writer">The output writer to Append to.</param> /// <param name="precisionModel">The PrecisionModel to use to convert /// from a precise coordinate to an external coordinate</param> protected void AppendCoordinate(Coordinate coordinate, StringWriter writer, PrecisionModel precisionModel) { precisionModel.makePrecise(coordinate); writer.Write("{0} {1}", WriteNumber(coordinate.x), WriteNumber(coordinate.y)); }
/// <summary> /// Initializes a new instance of the <see cref="NtsProvider"/> class /// using the given <paramref name="precisionModel"/>. /// </summary> /// <param name="precisionModel"> /// The <see cref="NetTopologySuite.Geometries.PrecisionModel"/> /// to use for define the precision of the geometry operations. /// </param> /// <seealso cref="NetTopologySuite.Geometries.PrecisionModel"/> /// <seealso cref="NetTopologySuite.Geometries.GeometryFactory"/> protected internal NtsProvider(PrecisionModel precisionModel) { _geometryFactory = new GeometryFactory(precisionModel); }
public void Test_TestConstructor() { PrecisionModel pm = new PrecisionModel(100000,0,0); GeometryFactory geometryFactory = new GeometryFactory(pm,-1); string filename= Global.GetUnitTestRootDirectory()+@"\IO\Shapefile\Testfiles\statepop"; ShapefileDataReader shpDataReader = Geotools.IO.Shapefile.CreateDataReader(filename, geometryFactory); int i=0; //for( i=0;i<shpDataReader.FieldCount;i++) //{ // Console.WriteLine(i+" "+shpDataReader.GetName(i) +" " +shpDataReader.GetFieldType(i)); //} Assertion.AssertEquals("Dbase header: Num records", 49, shpDataReader.RecordCount); Assertion.AssertEquals("Dbase header: Num fields", 253, shpDataReader.FieldCount); Assertion.AssertEquals("Field 1: name", "STATE_NAME", shpDataReader.GetName(1)); Assertion.AssertEquals("Field 1: name", typeof(string), shpDataReader.GetFieldType(1)); Assertion.AssertEquals("Field 252: name", "SAMP_POP", shpDataReader.GetName(252)); Assertion.AssertEquals("Field 252: name", typeof(double), shpDataReader.GetFieldType(252)); // note alaska and hawaii are missing - hence 48 states not 50. i=0; foreach(object columnValues in shpDataReader) { if (columnValues==null) { Assertion.Fail("columnValues should not be null."); } if (i==0) { Assertion.AssertEquals("Row1: STATE_NAME:","Illinois", shpDataReader.GetString(1)); Assertion.AssertEquals("Row1: STATE_FIPS:","17", shpDataReader.GetValue(2)); Assertion.AssertEquals("Row1: SAMP_POP", 1747776.0, shpDataReader.GetDouble(252)); } if (i==48) { Assertion.AssertEquals("Row1: STATE_NAME:","Washington", shpDataReader.GetString(1)); Assertion.AssertEquals("Row1: STATE_FIPS:","53", shpDataReader.GetValue(2)); Assertion.AssertEquals("Row1: SAMP_POP", 736744.0, shpDataReader.GetDouble(252)); } i++; } Assertion.AssertEquals("49 Records",49,i); // try opening the file again, to make sure file is not locked from previous reader. ShapefileDataReader shpDataReader2 = Geotools.IO.Shapefile.CreateDataReader(filename, geometryFactory); i=0; while (shpDataReader2.Read()) { if (i==0) { Assertion.AssertEquals("Row1: STATE_NAME:","Illinois", shpDataReader2.GetString(1)); Assertion.AssertEquals("Row1: STATE_FIPS:","17", shpDataReader2.GetValue(2)); Assertion.AssertEquals("Row1: SAMP_POP", 1747776.0, shpDataReader2.GetDouble(252)); } if (i==48) { Assertion.AssertEquals("Row1: STATE_NAME:","Washington", shpDataReader2.GetString(1)); Assertion.AssertEquals("Row1: STATE_FIPS:","53", shpDataReader2.GetValue(2)); Assertion.AssertEquals("Row1: SAMP_POP", 736744.0, shpDataReader2.GetDouble(252)); } i++; } Assertion.AssertEquals("49 Records",49,i); }
/// <summary> /// Initializes a new instance of the <see cref="McIndexSnapRounder"/> class. /// </summary> /// <param name="pm">The <see cref="PrecisionModel" /> to use.</param> public McIndexSnapRounder(PrecisionModel pm) { _li = new RobustLineIntersector(); _li.PrecisionModel = pm; _scaleFactor = pm.Scale; }
/// <summary> /// /// </summary> /// <param name="precisionModel"></param> public OffsetCurveBuilder(PrecisionModel precisionModel) : this(precisionModel, DEFAULT_QUADRANT_SEGMENTS) { }
public GeometrySVGWriter(PrecisionModel precisionModel, string xmlNamespace, int decimalPlaces) { _formatterString = CreateFormatter(decimalPlaces); _namespace = xmlNamespace; _precisionModel = precisionModel; }
/// <summary> /// Creates the <c>NumberFormatInfo</c> used to write <c>double</c>s /// with a sufficient number of decimal places. /// </summary> /// <param name="precisionModel"> /// The <c>PrecisionModel</c> used to determine /// the number of decimal places to write. /// </param> /// <returns> /// A <c>NumberFormatInfo</c> that write <c>double</c> /// s without scientific notation. /// </returns> private static NumberFormatInfo CreateFormatter(PrecisionModel precisionModel) { // the default number of decimal places is 16, which is sufficient // to accomodate the maximum precision of a double. int decimalPlaces = precisionModel.MaximumSignificantDigits; // specify decimal separator explicitly to avoid problems in other locales NumberFormatInfo nfi = new NumberFormatInfo(); nfi.NumberDecimalSeparator = "."; nfi.NumberDecimalDigits = decimalPlaces; nfi.NumberGroupSeparator = String.Empty; nfi.NumberGroupSizes = new int[] { }; return nfi; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleSnapRounder"/> class. /// </summary> /// <param name="pm">The <see cref="PrecisionModel" /> to use.</param> public SimpleSnapRounder(PrecisionModel pm) { li = new RobustLineIntersector(); li.PrecisionModel = pm; scaleFactor = pm.Scale; }
/// <summary> /// Converts a Coordinate to <Point Tagged Text> format, /// then Appends it to the writer. /// </summary> /// <param name="coordinate">the <code>Coordinate</code> to process</param> /// <param name="writer">the output writer to Append to</param> /// <param name="precisionModel">the PrecisionModel to use to convert /// from a precise coordinate to an external coordinate</param> protected void AppendPointTaggedText(Coordinate coordinate, TextWriter writer, PrecisionModel precisionModel) { if (this._cssClass!="") { writer.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "<{5}circle class=\"{0}\" style=\"{1}\" cx=\"{2}\" cy=\"{3}\" r=\"{4}\"/>",_cssClass,_style,WriteNumber(coordinate.x),WriteNumber(coordinate.y),_radius,_namespace)); } else { writer.WriteLine(String.Format(System.Globalization.CultureInfo.InvariantCulture, "<{4}circle style=\"{0}\" cx=\"{1}\" cy=\"{2}\" r=\"{3}\"/>",_style,WriteNumber(coordinate.x),WriteNumber(coordinate.y),_radius,_namespace)); } }
/// <summary> /// Initializes a new instance of the <see cref="NtsProvider"/> class /// from another <see cref="SharpMap.Data.Providers.IProvider" />. /// </summary> /// <param name="provider"> /// The base <see cref="SharpMap.Data.Providers.IProvider"/> /// from witch initialize the <see cref="NtsProvider"/> instance. /// </param> /// <param name="precisionModel"> /// The <see cref="NetTopologySuite.Geometries.PrecisionModel"/> /// to use for define the precision of the geometry operations. /// </param> /// <seealso cref="NetTopologySuite.Geometries.PrecisionModel"/> /// <seealso cref="NetTopologySuite.Geometries.GeometryFactory"/> public NtsProvider(IProvider provider, PrecisionModel precisionModel) : this(precisionModel) { BuildFromProvider(provider); }
/// <summary> /// Converts a Coordinate to <Point Tagged Text> format, /// then Appends it to the writer. /// </summary> /// <param name="coordinate">the <code>Coordinate</code> to process</param> /// <param name="level"></param> /// <param name="writer">the output writer to Append to</param> /// <param name="precisionModel">the PrecisionModel to use to convert /// from a precise coordinate to an external coordinate</param> protected void AppendPointTaggedText(Coordinate coordinate, int level, StringWriter writer, PrecisionModel precisionModel) { writer.Write("POINT "); AppendPointText(coordinate, level, writer, precisionModel); }
/// <summary> /// Initializes a new instance of the <see cref="NtsProvider"/> class /// from another <see cref="SharpMap.Data.Providers.IProvider" />. /// </summary> /// <param name="provider"> /// The base <see cref="SharpMap.Data.Providers.IProvider"/> /// from witch initialize the <see cref="NtsProvider"/> instance. /// </param> /// <param name="operation"> /// The <see cref="GeometryOperationDelegate"/> to apply /// to all geometry elements in the <paramref name="provider"/>. /// </param> /// <param name="precisionModel"> /// The <see cref="NetTopologySuite.Geometries.PrecisionModel"/> /// to use for define the precision of the geometry operations. /// </param> /// <seealso cref="NetTopologySuite.Geometries.PrecisionModel"/> /// <seealso cref="NetTopologySuite.Geometries.GeometryFactory"/> public NtsProvider(IProvider provider, GeometryOperationDelegate operation, PrecisionModel precisionModel) : this(provider, precisionModel) { operation(_features); }
public void Test_TestGets() { PrecisionModel pm = new PrecisionModel(1,0,0); GeometryFactory geometryFactory = new GeometryFactory(pm,-1); string filename= Global.GetUnitTestRootDirectory()+@"\IO\Shapefile\Testfiles\statepop"; ShapefileDataReader shpDataReader = Geotools.IO.Shapefile.CreateDataReader(filename, geometryFactory); // note alaska and hawaii are missing - hence 48 states not 50. // tests GetValues(). object[] values = new object[shpDataReader.FieldCount]; foreach(object columnValues in shpDataReader) { if (columnValues==null) { Assertion.Fail("columnValues should have data."); } // get values using GetValue() for(int i = 0; i < shpDataReader.FieldCount; i++) { values[i] = shpDataReader.GetValue(i); } // get values using GetValues() object[] values2=new object[shpDataReader.FieldCount]; shpDataReader.GetValues(values2); // ensure they are both the same. for(int i = 0; i < shpDataReader.FieldCount; i++) { Assertion.AssertEquals("Values "+i, values[i], values2[i]); } } }
public void Test_TestRead() { PrecisionModel pm = new PrecisionModel(100000,0,0); GeometryFactory geometryFactory = new GeometryFactory(pm,-1); //DataSets can be enumerated thru, or you can use Read(). This one tests the read; string filename= Global.GetUnitTestRootDirectory()+@"\IO\Shapefile\Testfiles\statepop"; ShapefileDataReader shpDataReader = Geotools.IO.Shapefile.CreateDataReader(filename, geometryFactory); int i=0; while (shpDataReader.Read()) { i++; } Assertion.AssertEquals("Read using Read()",49,i); }
/// <summary> /// Constructs a GeometryFactory that generates Geometries having the given /// <c>PrecisionModel</c> and spatial-reference ID, and the default CoordinateSequence /// implementation. /// </summary> /// <param name="precisionModel">The PrecisionModel to use.</param> /// <param name="SRID">The SRID to use.</param> public GeometryFactory(PrecisionModel precisionModel, int SRID) : this(precisionModel, SRID, GetDefaultCoordinateSequenceFactory()) { }
/// <summary> /// Returns an <b>Envelope</b> in external coordinates. /// </summary> /// <param name="precisionModel">The <b>PrecisionModel</b> used to create the <b>Envelope</b>.</param> /// <param name="envelope">The <b>Envelope</b> to transform.</param> /// <returns>An <b>Envelope</b> in external coordinates</returns> public static Envelope GetEnvelopeExternal(PrecisionModel precisionModel, Envelope envelope) { return new Envelope(envelope.getMinX(), envelope.getMaxX(), envelope.getMinY(), envelope.getMaxY()); }
/// <summary> /// /// </summary> /// <param name="precisionModel"></param> /// <returns></returns> private static INoder GetNoder(PrecisionModel precisionModel) { // otherwise use a fast (but non-robust) noder LineIntersector li = new RobustLineIntersector(); li.PrecisionModel = precisionModel; McIndexNoder noder = new McIndexNoder(new IntersectionAdder(li)); return noder; }
/// <summary> /// /// </summary> /// <param name="precisionDigits"></param> private void BufferFixedPrecision(int precisionDigits) { double sizeBasedScaleFactor = PrecisionScaleFactor(argGeom, distance, precisionDigits); PrecisionModel fixedPM = new PrecisionModel(sizeBasedScaleFactor); // don't change the precision model of the Geometry, just reduce the precision SimpleGeometryPrecisionReducer reducer = new SimpleGeometryPrecisionReducer(fixedPM); IGeometry reducedGeom = reducer.Reduce(argGeom); BufferBuilder bufBuilder = new BufferBuilder(); bufBuilder.WorkingPrecisionModel = fixedPM; bufBuilder.QuadrantSegments = quadrantSegments; // this may throw an exception, if robustness errors are encountered resultGeometry = bufBuilder.Buffer(reducedGeom, distance); }
/// <summary> /// /// </summary> /// <param name="bufferSegStrList"></param> /// <param name="precisionModel"></param> private void ComputeNodedEdges(IList bufferSegStrList, PrecisionModel precisionModel) { INoder noder = GetNoder(precisionModel); noder.ComputeNodes(bufferSegStrList); IList nodedSegStrings = noder.GetNodedSubstrings(); foreach (object obj in nodedSegStrings) { SegmentString segStr = (SegmentString)obj; Label oldLabel = (Label)segStr.Data; Edge edge = new Edge(segStr.Coordinates, new Label(oldLabel)); InsertEdge(edge); } }
/// <summary> /// /// </summary> /// <param name="pm"></param> public SimpleGeometryPrecisionReducer(PrecisionModel pm) { _newPrecisionModel = pm; }