/// <summary> /// Tests a regular polygon /// </summary> public void TestArea1() { string wkt = "POLYGON(( 5 5, 10 5, 10 10, 5 10, 5 5))"; Polygon polygon = (Polygon)_gf.CreateFromWKT(wkt); double area = polygon.GetArea(); Assertion.AssertEquals("Polygon area", 25.0, area); }
public static bool TestHelper(string wkt) { PrecisionModel pm = new PrecisionModel(1, 0, 0); GeometryFactory fact = new GeometryFactory(pm, 0); //read wkt Geometry a = (Geometry)fact.CreateFromWKT(wkt); //write wkb FileStream fs = new FileStream("TestFile.wkb", FileMode.Create); BinaryWriter bw = new BinaryWriter(fs); GeometryWKBWriter bWriter = new GeometryWKBWriter(fact); bWriter.Write(a, bw, (byte)1); 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); }
public bool Compare(string wkt, string expectedProjectedWkt) { Geometry geometry = (Geometry)_geometryFactory.CreateFromWKT(wkt); Geometry projectedGeometry = (Geometry)geometry.Project(_UKNationalGrid1); string actualProjectedWkt = projectedGeometry.ToText(); return(Geotools.UnitTests.Utilities.Compare.WktStrings(expectedProjectedWkt, actualProjectedWkt)); }
public bool Compare2(string wkt, string expectedProjectedWkt, GeometryFactory geometryFactory, ICoordinateTransformation transformation) { Geometry geometry = (Geometry)geometryFactory.CreateFromWKT(wkt); Geometry projectedGeometry = (Geometry)geometry.Project(transformation); string actualProjectedWkt = projectedGeometry.ToText(); return(Geotools.UnitTests.Utilities.Compare.WktStrings(expectedProjectedWkt, actualProjectedWkt)); }
public void TestPolygon1() { string wkt = "POLYGON( ( 50 31, 54 31, 54 29, 50 29, 50 31) )"; GeometryFactory factory = new GeometryFactory(); IGeometry geometry = factory.CreateFromWKT(wkt); IPolygon polygon = (IPolygon)geometry; string wkt2 = ((Polygon)polygon).ToText(); Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2)); }
public void TestPolygon2() { string wkt = "POLYGON( ( 1 1, 10 1, 10 10, 1 10, 1 1),(4 4, 5 4, 5 5, 4 5, 4 4 ))"; GeometryFactory factory = new GeometryFactory(); IGeometry geometry = factory.CreateFromWKT(wkt); IPolygon polygon = (IPolygon)geometry; string wkt2 = ((Polygon)polygon).ToText(); Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2)); }
public void TestWktReadMultiPoint2() { string wkt = "MULTIPOINT EMPTY"; GeometryFactory factory = new GeometryFactory(); IGeometry geometry = factory.CreateFromWKT(wkt); IGeometryCollection multipoint = (IGeometryCollection)geometry; Assertion.AssertEquals("empty", true, multipoint.IsEmpty()); string wkt2 = ((MultiPoint)geometry).ToText(); Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2)); }
public void TestWktReadPoint3() { string wkt = "POINT EMPTY"; GeometryFactory factory = new GeometryFactory(); IGeometry geometry = factory.CreateFromWKT(wkt); IPoint point = (IPoint)geometry; Assertion.AssertEquals("empty", true, point.IsEmpty()); string wkt2 = ((Point)point).ToText(); Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2)); }
public void Test3() { string wkt = "MULTIPOINT EMPTY2 "; GeometryFactory factory = new GeometryFactory(); try { IGeometry geometry = factory.CreateFromWKT(wkt); Assertion.Fail("EMPTY2 is not valid."); } catch (ParseException) { } }
public void Test2() { string wkt = " "; GeometryFactory factory = new GeometryFactory(); try { IGeometry geometry = factory.CreateFromWKT(wkt); Assertion.Fail("ArgumentException should have been thrown."); } catch (ArgumentException) { } }
public void Test1() { string wkt = null; GeometryFactory factory = new GeometryFactory(); try { IGeometry geometry = factory.CreateFromWKT(wkt); Assertion.Fail("parse exception"); } catch (ArgumentNullException) { } }
public void TestGetNextWord() { string wkt = "POINT *( 3 4 )"; GeometryFactory factory = new GeometryFactory(); try { IGeometry geometry = factory.CreateFromWKT(wkt); Assertion.Fail("parse exception"); } catch (ParseException) { } }
public void TestWktReadPoint2() { string wkt = "POINT ( 3 , 4 )"; GeometryFactory factory = new GeometryFactory(); try { IGeometry geometry = factory.CreateFromWKT(wkt); Assertion.Fail("Should fail because of the comma."); } catch (ParseException) { } }
public void TestGeomtryCollection() { string wkt = "GEOMETRYCOLLECTION(POINT ( 3 4 ),LINESTRING(50 31, 54 31, 54 29, 50 29, 50 31 ))"; GeometryFactory factory = new GeometryFactory(); IGeometry geometry = factory.CreateFromWKT(wkt); GeometryCollection geometryCollection = (GeometryCollection)geometry; Point point = (Point)geometryCollection[0]; LineString linestring = (LineString)geometryCollection[1]; Assertion.AssertEquals("GeometryCollection 1", 3.0, point.X); Assertion.AssertEquals("GeometryCollection 2", 4.0, point.Y); Assertion.AssertEquals("GeometryCollection 3", 5, linestring.GetNumPoints()); string wkt2 = geometryCollection.ToText(); Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2)); }
/// <summary> /// Private method that checks whether a test passes or fails by comparing the WKT that was returned /// and the expected WKT in the object. Also sets the PassFail member of the TestResult object. /// </summary> private void TestForPassFail() { Geometry result = this._testResult.ResultGeometry; // use the PrecisionModel of the returned geometry when creating the expected geometry... Geotools.Geometries.PrecisionModel pm = result.GetPrecisionModel(); // Create a geometry from the expectedWKT... GeometryFactory gf = new GeometryFactory(pm, 0); // create the expected geometry, normalize it, and grab the wkt for it... Geometry expected = (Geometry)gf.CreateFromWKT(this._testResult.ExpectedWKT); expected.Normalize(); string expectedNormalized = expected.ToText(); string actualNormalized = ""; if (this._testResult.ResultGeometry.IsEmpty()) { string type = this._testResult.ResultGeometry.GetGeometryType(); type = type.ToUpper(); actualNormalized = type + " EMPTY"; } else { // normalize the returned geometry and grab the wkt from it... this._testResult.ResultGeometry.Normalize(); actualNormalized = this._testResult.ResultGeometry.ToText(); } // format the two wkt's... expectedNormalized = Test.FormatWKTString(expectedNormalized); actualNormalized = Test.FormatWKTString(actualNormalized); // make the comparison... if (expectedNormalized == actualNormalized) { this._testResult.PassFailWKT = true; } }
public void TestMultiPolygon1() { string wkt = "MULTIPOLYGON (((10 10, 10 20, 20 20, 20 15 , 10 10), (50 40, 50 50, 60 50, 60 40, 50 40)))"; GeometryFactory factory = new GeometryFactory(); IGeometry geometry = factory.CreateFromWKT(wkt); MultiPolygon multiPolygon = (MultiPolygon)geometry; //Assertion.AssertEquals("Multilinestring 1",2,multiPolygon.NumGeometries); IGeometry g = multiPolygon.GetGeometryN(0); Polygon poly1 = (Polygon)multiPolygon.GetGeometryN(0); LinearRing shell = poly1.Shell; LinearRing hole = poly1.Holes[0]; Assertion.AssertEquals("MPS 1", 10.0, shell.GetCoordinates()[0].X); Assertion.AssertEquals("MPS 2", 10.0, shell.GetCoordinates()[0].Y); Assertion.AssertEquals("MPS 3", 10.0, shell.GetCoordinates()[1].X); Assertion.AssertEquals("MPS 4", 20.0, shell.GetCoordinates()[1].Y); Assertion.AssertEquals("MPS 5", 20.0, shell.GetCoordinates()[2].Y); Assertion.AssertEquals("MPS 6", 20.0, shell.GetCoordinates()[2].Y); Assertion.AssertEquals("MPS 7", 20.0, shell.GetCoordinates()[3].X); Assertion.AssertEquals("MPS 8", 15.0, shell.GetCoordinates()[3].Y); Assertion.AssertEquals("MPS 9", 10.0, shell.GetCoordinates()[4].X); Assertion.AssertEquals("MPS 10", 10.0, shell.GetCoordinates()[4].Y); Assertion.AssertEquals("MPS 11", 50.0, hole.GetCoordinates()[0].X); Assertion.AssertEquals("MPS 12", 40.0, hole.GetCoordinates()[0].Y); Assertion.AssertEquals("MPS 13", 50.0, hole.GetCoordinates()[1].X); Assertion.AssertEquals("MPS 14", 50.0, hole.GetCoordinates()[1].Y); Assertion.AssertEquals("MPS 15", 60.0, hole.GetCoordinates()[2].X); Assertion.AssertEquals("MPS 16", 50.0, hole.GetCoordinates()[2].Y); Assertion.AssertEquals("MPS 17", 60.0, hole.GetCoordinates()[3].X); Assertion.AssertEquals("MPS 18", 40.0, hole.GetCoordinates()[3].Y); Assertion.AssertEquals("MPS 19", 50.0, hole.GetCoordinates()[4].X); Assertion.AssertEquals("MPS 20", 40.0, hole.GetCoordinates()[4].Y); string wkt2 = multiPolygon.ToText(); Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2)); }
public void TestMultiLineString1() { string wkt = "MULTILINESTRING (( 10.05 10.28 , 20.95 20.89 ),( 20.95 20.89, 31.92 21.45)) "; GeometryFactory factory = new GeometryFactory(); IGeometry geometry = factory.CreateFromWKT(wkt); MultiLineString multilineString = (MultiLineString)geometry; Assertion.AssertEquals("Multilinestring 1", 2, multilineString.GetNumGeometries()); LineString linestring1 = (LineString)multilineString.GetGeometryN(0); LineString linestring2 = (LineString)multilineString.GetGeometryN(1); Assertion.AssertEquals("MLS 1", 10.05, linestring1.GetCoordinates()[0].X); Assertion.AssertEquals("MLS 2", 10.28, linestring1.GetCoordinates()[0].Y); Assertion.AssertEquals("MLS 3", 20.95, linestring1.GetCoordinates()[1].X); Assertion.AssertEquals("MLS 4", 20.89, linestring1.GetCoordinates()[1].Y); Assertion.AssertEquals("MLS 1", 20.95, linestring2.GetCoordinates()[0].X); Assertion.AssertEquals("MLS 2", 20.89, linestring2.GetCoordinates()[0].Y); Assertion.AssertEquals("MLS 3", 31.92, linestring2.GetCoordinates()[1].X); Assertion.AssertEquals("MLS 4", 21.45, linestring2.GetCoordinates()[1].Y); string wkt2 = ((MultiLineString)multilineString).ToText(); Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2)); }
public void TestLineString() { // 1 2 3 4 5 string wkt = "LINESTRING(50 31, 54 31, 54 29, 50 29, 50 31 )"; GeometryFactory factory = new GeometryFactory(); IGeometry geometry = factory.CreateFromWKT(wkt); ILineString linestring = (ILineString)geometry; Assertion.AssertEquals("numpoints", 5, linestring.GetNumPoints()); Assertion.AssertEquals("x1", 50.0, linestring.GetPointN(0).X); Assertion.AssertEquals("y1", 31.0, linestring.GetPointN(0).Y); Assertion.AssertEquals("x2", 54.0, linestring.GetPointN(1).X); Assertion.AssertEquals("y2", 31.0, linestring.GetPointN(1).Y); Assertion.AssertEquals("x3", 54.0, linestring.GetPointN(2).X); Assertion.AssertEquals("y3", 29.0, linestring.GetPointN(2).Y); Assertion.AssertEquals("x4", 50.0, linestring.GetPointN(3).X); Assertion.AssertEquals("y4", 29.0, linestring.GetPointN(3).Y); Assertion.AssertEquals("x5", 50.0, linestring.GetPointN(4).X); Assertion.AssertEquals("y5", 31.0, linestring.GetPointN(4).Y); string wkt2 = ((LineString)linestring).ToText(); Assertion.AssertEquals("wkt", true, Compare.WktStrings(wkt, wkt2)); }