Esempio n. 1
0
        /// <summary>
        /// This is a temporary method that is being used to test if two geometries are equal.
        /// This is being used because the normalize methods on the geometries has not been implemented
        /// and we are getting false failures due to the WKT strings being different.
        /// This method creates two geometry objects from well-known text strings and then calls
        /// the EqualsTopology method on one of them to see if they are equal.
        /// </summary>
        /// <param name="wkt1">The well-known text string for the first geometry.</param>
        /// <param name="wkt2">The well-known text string for the second geometry.</param>
        /// <returns>
        /// True if the geometries are equal otherwise returns false.</returns>
        private bool TestTopologyEquals(string wkt1, string wkt2)
        {
            // create the GeometryFactory object...
            Geotools.Geometries.GeometryFactory geometryFactory = new Geotools.Geometries.GeometryFactory();
            // create the two geometries from the well-known text strings...
            Geometry a = (Geometry)geometryFactory.CreateFromWKT(wkt1);
            Geometry b = (Geometry)geometryFactory.CreateFromWKT(wkt2);

            // Call the EqualsTopology method and return...
            return(a.EqualsTopology(b));
        }
		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;
		}
Esempio n. 3
0
        /// <summary>
        /// Creates the "B" geometry for this TestCase by instantiating a GeometryFactory object and
        /// calling its CreateFromWKT method. The geometry object is created from its Well-known text.
        /// </summary>
        /// <param name="precisionModel">The precision model for this run.</param>
        /// <returns>OGC.SimpleFeatures.IGeometry object.</returns>

        public IGeometry CreateBGeometry(Geotools.Geometries.PrecisionModel precisionModel)
        {
            // create the GeometryFactory object...
            Geotools.Geometries.GeometryFactory geometryFactory = new Geotools.Geometries.GeometryFactory(precisionModel, -1);
            // create the geometry and return it...
            return(geometryFactory.CreateFromWKT(this._bGeometry));
        }
		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 Test1()
		{
			string wkt = null;

			GeometryFactory factory = new GeometryFactory();
			try
			{
				IGeometry geometry = factory.CreateFromWKT(wkt);
				Assertion.Fail("parse exception");
			}
			catch(ArgumentNullException)
			{
			}
		}
		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)
			{
			}
		}
Esempio n. 7
0
		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 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));
		}
Esempio n. 9
0
		/// <summary>
		/// This is a temporary method that is being used to test if two geometries are equal.
		/// This is being used because the normalize methods on the geometries has not been implemented
		/// and we are getting false failures due to the WKT strings being different.
		/// This method creates two geometry objects from well-known text strings and then calls
		/// the EqualsTopology method on one of them to see if they are equal.
		/// </summary>
		/// <param name="wkt1">The well-known text string for the first geometry.</param>
		/// <param name="wkt2">The well-known text string for the second geometry.</param>
		/// <returns>
		/// True if the geometries are equal otherwise returns false.</returns>
		private bool TestTopologyEquals(string wkt1, string wkt2)
		{
			// create the GeometryFactory object...
			Geotools.Geometries.GeometryFactory geometryFactory = new Geotools.Geometries.GeometryFactory();
			// create the two geometries from the well-known text strings...
			Geometry a = (Geometry)geometryFactory.CreateFromWKT(wkt1);
			Geometry b = (Geometry)geometryFactory.CreateFromWKT(wkt2);

			// Call the EqualsTopology method and return...
			return a.EqualsTopology(b);
		}
Esempio n. 10
0
		/// <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;
			}
		}
Esempio n. 11
0
		/// <summary>
		/// Creates the "B" geometry for this TestCase by instantiating a GeometryFactory object and 
		/// calling its CreateFromWKT method. The geometry object is created from its Well-known text.
		/// </summary>
		/// <param name="precisionModel">The precision model for this run.</param>
		/// <returns>OGC.SimpleFeatures.IGeometry object.</returns>
		
		public IGeometry CreateBGeometry(Geotools.Geometries.PrecisionModel precisionModel)
		{
			// create the GeometryFactory object...
			Geotools.Geometries.GeometryFactory geometryFactory = new Geotools.Geometries.GeometryFactory(precisionModel, -1);
			// create the geometry and return it...
			return geometryFactory.CreateFromWKT(this._bGeometry);
		}
		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 Test2()
		{
			string wkt = "  ";

			GeometryFactory factory = new GeometryFactory();
			try
			{
				IGeometry geometry = factory.CreateFromWKT(wkt);
				Assertion.Fail("ArgumentException should have been thrown.");
			}
			catch(ArgumentException)
			{
			}
		}
		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));
		}
		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 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 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 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 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));
		}