本文整理汇总了C#中Geotools.Geometries.GeometryFactory.CreateFromWKT方法的典型用法代码示例。如果您正苦于以下问题:C# GeometryFactory.CreateFromWKT方法的具体用法?C# GeometryFactory.CreateFromWKT怎么用?C# GeometryFactory.CreateFromWKT使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Geotools.Geometries.GeometryFactory
的用法示例。
在下文中一共展示了GeometryFactory.CreateFromWKT方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestHelper
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;
}
示例2: Test1
public void Test1()
{
string wkt = null;
GeometryFactory factory = new GeometryFactory();
try
{
IGeometry geometry = factory.CreateFromWKT(wkt);
Assertion.Fail("parse exception");
}
catch(ArgumentNullException)
{
}
}
示例3: TestGetNextWord
public void TestGetNextWord()
{
string wkt = "POINT *( 3 4 )";
GeometryFactory factory = new GeometryFactory();
try
{
IGeometry geometry = factory.CreateFromWKT(wkt);
Assertion.Fail("parse exception");
}
catch(ParseException)
{
}
}
示例4: TestForPassFail
/// <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;
}
}
示例5: CreateBGeometry
/// <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);
}
示例6: Test2
public void Test2()
{
string wkt = " ";
GeometryFactory factory = new GeometryFactory();
try
{
IGeometry geometry = factory.CreateFromWKT(wkt);
Assertion.Fail("ArgumentException should have been thrown.");
}
catch(ArgumentException)
{
}
}
示例7: TestWktReadPoint2
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)
{
}
}
示例8: TestMultiLineString1
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));
}
示例9: TestMultiPolygon1
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));
}
示例10: TestPolygon1
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));
}
示例11: TestPolygon2
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));
}
示例12: TestLineString
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));
}
示例13: TestWktReadMultiPoint2
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));
}
示例14: TestWktReadPoint3
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));
}
示例15: TestTopologyEquals
/// <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);
}