本文整理汇总了C#中NetTopologySuite.IO.WKTReader.Read方法的典型用法代码示例。如果您正苦于以下问题:C# WKTReader.Read方法的具体用法?C# WKTReader.Read怎么用?C# WKTReader.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetTopologySuite.IO.WKTReader
的用法示例。
在下文中一共展示了WKTReader.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CascadedUnionError
public void CascadedUnionError()
{
String[] wkt =
{
//MULTIPOLYGON (((-2.775 -37.382, -2.7694818956884695 -37.302294048833446, -4.381 -37.19, -4.379 -37.16, -2.7674053419183364 -37.272299383264858, -2.766 -37.252, -2.703 -37.257, -2.712 -37.386, -2.775 -37.382)), ((-0.558 -16.355, -0.556624473051351 -16.33528411373603, -2.168 -16.223, -2.165 -16.193, -0.55452706181921063 -16.305221219408683, -0.549 -16.226, -0.485 -16.23, -0.494 -16.36, -0.558 -16.355)))
"MULTIPOLYGON (((-2.775 -37.382, -2.7694818956884695 -37.302294048833446, -4.381 -37.19, -4.379 -37.16, -2.7674053419183364 -37.272299383264858, -2.766 -37.252, -2.703 -37.257, -2.712 -37.386, -2.775 -37.382)), ((-0.558 -16.355, -0.556624473051351 -16.33528411373603, -2.168 -16.223, -2.165 -16.193, -0.55452706181921063 -16.305221219408683, -0.549 -16.226, -0.485 -16.23, -0.494 -16.36, -0.558 -16.355)))",
//MULTIPOLYGON (((-4.218 -16.08, -4.216 -16.05, -2.924 -16.14, -2.926 -16.17, -4.218 -16.08)), ((-5.291 -18.097, -5.243 -17.415, -5.239 -17.352, -5.15929328747628 -17.357518157020873, -5.071 -16.091, -5.041 -16.093, -5.1292306097055169 -17.359599419328081, -5.109 -17.361, -5.114 -17.424, -5.161 -18.106, -5.291 -18.097)))
"MULTIPOLYGON (((-4.218 -16.08, -4.216 -16.05, -2.924 -16.14, -2.926 -16.17, -4.218 -16.08)), ((-5.291 -18.097, -5.243 -17.415, -5.239 -17.352, -5.15929328747628 -17.357518157020873, -5.071 -16.091, -5.041 -16.093, -5.1292306097055169 -17.359599419328081, -5.109 -17.361, -5.114 -17.424, -5.161 -18.106, -5.291 -18.097)))"
};
IList<IGeometry> items = new List<IGeometry>();
IGeometryFactory factory = GeometryFactory.Default;
WKTReader reader = new WKTReader(factory);
IGeometry geoms = reader.Read(wkt[0]);
for (int i = 0; i < geoms.NumGeometries; i++)
{
IGeometry geom = geoms.GetGeometryN(i);
items.Add(geom);
}
geoms = reader.Read(wkt[1]);
for (int i = 0; i < geoms.NumGeometries; i++)
{
IGeometry geom = geoms.GetGeometryN(i);
items.Add(geom);
}
UnaryUnionOp op = new UnaryUnionOp(items, new GeometryFactory(new PrecisionModel(100)));
IGeometry result = op.Union();
Assert.IsNotNull(result);
}
示例2: Execute
private void Execute(IGeometryFactory factory)
{
const string wkt1 = @"POLYGON ((34.8998882099012 30.3837960942026, 34.9010566737651 30.3644568453302, 34.952062587058 30.3841960548712, 34.9237694926759 30.3379967024143, 34.8688043479468 30.2722872698552, 34.8675239767921 30.2729668362851, 34.8644624659558 30.2746560404891, 34.8614352803289 30.2763912924804, 34.8584433396252 30.2781720660657, 34.8554875530179 30.2799978212197, 34.8525688188649 30.2818680042466, 34.8496880244379 30.2837820479458, 34.8468460456542 30.2857393717817, 34.8440437468117 30.2877393820578, 34.8412819803279 30.2897814720941, 34.8385615864812 30.291865022409, 34.8358833931563 30.2939894009049, 34.8332482155932 30.2961539630577, 34.8306568561393 30.2983580521099, 34.8281101040059 30.3006009992674, 34.8256087350277 30.3028821239005, 34.8231535114263 30.3052007337477, 34.8207451815784 30.3075561251236, 34.8183844797864 30.3099475831299, 34.8160721260548 30.3123743818706, 34.813808825869 30.3148357846692, 34.8115952699799 30.3173310442906, 34.8094321341915 30.3198594031656, 34.8073200791532 30.3224200936183, 34.8052597501567 30.3250123380972, 34.8038593775008 30.3268416420348, 34.8413134524996 30.34133631112, 34.8380456129141 30.3420679436136, 34.8345469119455 30.3429079098264, 34.8310655827664 30.3438006160548, 34.827824169131 30.3446853380141, 34.827602680711 30.3447457917824, 34.8241592556176 30.3457431505854, 34.8207363515157 30.3467923902175, 34.8173350063135 30.3478931927008, 34.8139562514873 30.34904522442, 34.8106011117732 30.3502481362226, 34.80727060486 30.3515015635225, 34.8039657410851 30.3528051264095, 34.8006875231308 30.3541584297621, 34.7974369457248 30.355561063366, 34.8114061852091 30.3793421607384, 34.8098261518056 30.3806388748041, 34.8072325551456 30.3828429255909, 34.8046836035397 30.3850858339783, 34.8021800734927 30.387366919357, 34.7997227278858 30.3896854894863, 34.797312315744 30.3920408407015, 34.7949495720071 30.3944322581256, 34.7926352173053 30.3968590158832, 34.7903699577383 30.3993203773193, 34.7881544846595 30.4018155952199, 34.8175519633847 30.421036532238, 34.8473374156124 30.4405111377535, 34.8473374156124 30.4405111377536, 34.8945946797018 30.4714093282142, 34.89504284421 30.4639917561117, 34.9249010902965 30.4502666241023, 34.9120339400511 30.4239712613602, 34.8990624811609 30.3974627330299, 34.8990624811609 30.3974627330298, 34.8998882099012 30.3837960942026), (34.8998882099012 30.3837960942026, 34.8896581575596 30.3782440174851, 34.8896581575596 30.3782440174851, 34.8998882099012 30.3837960942026))";
const string wkt2 = @"POLYGON ((34.89504284421 30.4639917561117, 34.8974881525283 30.4235194508906, 34.8362388038152 30.4216169690234, 34.8683403196915 30.4762662772922, 34.89504284421 30.4639917561117))";
WKTReader reader = new WKTReader(factory);
IGeometry g1 = reader.Read(wkt1);
Assert.IsFalse(g1.IsValid);
IGeometry v1 = g1.Buffer(0);
Assert.IsTrue(v1.IsValid);
IGeometry g2 = reader.Read(wkt2);
//Assert.IsFalse(g2.IsValid);
IGeometry v2 = g2.Buffer(0);
Assert.IsTrue(v2.IsValid);
IGeometry union1 = g1.Union(g2);
Assert.IsNotNull(union1);
Assert.IsTrue(union1.IsValid);
IGeometry union2 = v1.Union(v2);
Assert.IsNotNull(union2);
Assert.IsTrue(union2.IsValid);
}
示例3: Test1
public void Test1()
{
WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(1), 0));
LineString lineString = (LineString)reader.Read("LINESTRING (30 220, 240 220, 240 220)");
LineString convexHull = (LineString)reader.Read("LINESTRING (30 220, 240 220)");
Assert.IsTrue(convexHull.EqualsExact(lineString.ConvexHull()));
}
示例4: Test4
public void Test4()
{
WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(1), 0));
IGeometry geometry = reader.Read("MULTIPOINT (0 0, 10 0, 10 0)");
LineString convexHull = (LineString)reader.Read("LINESTRING (0 0, 10 0)");
Assert.IsTrue(convexHull.EqualsExact(geometry.ConvexHull()));
}
示例5: MultiPoint_WKT_reader_should_skip_extra_parenthesis_around_coordinates
public void MultiPoint_WKT_reader_should_skip_extra_parenthesis_around_coordinates()
{
WKTReader reader = new WKTReader();
IGeometry mp1 = reader.Read("MULTIPOINT (10 10, 20 20)");
IGeometry mp2 = reader.Read("MULTIPOINT ((10 10), (20 20))");
Assert.IsTrue(mp1.EqualsExact(mp2));
}
示例6: PerformTest
private static void PerformTest(IGeometryFactory factory)
{
if (factory == null)
throw new ArgumentNullException("factory");
WKTReader reader = new WKTReader(factory);
IGeometry g1 = reader.Read(t1);
Assert.IsNotNull(g1);
Assert.IsTrue(g1.IsValid);
Assert.IsInstanceOf(typeof(IPolygon), g1);
Assert.IsInstanceOf(typeof(Polygon), g1);
IGeometry g2 = reader.Read(t2);
Assert.IsNotNull(g2);
Assert.IsTrue(g2.IsValid);
Assert.IsInstanceOf(typeof(IMultiPolygon), g2);
Assert.IsInstanceOf(typeof(MultiPolygon), g2);
Stopwatch watch = new Stopwatch();
watch.Start();
IGeometry r = g1.Intersection(g2);
watch.Stop();
Assert.IsNotNull(r);
Assert.IsInstanceOf(typeof(IMultiPolygon), r);
Assert.IsInstanceOf(typeof(MultiPolygon), r);
Assert.IsTrue(r.IsValid);
Console.WriteLine("GeometryFactory.Default => Elapsed: {0}", watch.Elapsed);
}
示例7: main
public static void main(string[] args)
{
WKTReader rdr = new WKTReader();
IGeometry[] geom = new IGeometry[3];
geom[0] = rdr.Read("POLYGON (( 100 180, 100 260, 180 260, 180 180, 100 180 ))");
geom[1] = rdr.Read("POLYGON (( 80 140, 80 200, 200 200, 200 140, 80 140 ))");
geom[2] = rdr.Read("POLYGON (( 160 160, 160 240, 240 240, 240 160, 160 160 ))");
UnionUsingBufferOp(geom);
}
示例8: main
public static void main(string[] args)
{
WKTReader rdr = new WKTReader();
ILineString line1 = (ILineString) rdr.Read("LINESTRING (0 0, 10 10, 20 20)");
ShowSelfIntersections(line1);
ILineString line2 = (ILineString) rdr.Read("LINESTRING (0 40, 60 40, 60 0, 20 0, 20 60)");
ShowSelfIntersections(line2);
}
示例9: Intersection
public virtual void Intersection(string wktA, string wktB, PrecisionModel pm)
{
Console.WriteLine("Running example using Precision Model = " + pm);
GeometryFactory fact = new GeometryFactory(pm);
WKTReader wktRdr = new WKTReader(fact);
IGeometry A = wktRdr.Read(wktA);
IGeometry B = wktRdr.Read(wktB);
IGeometry C = A.Intersection(B);
Console.WriteLine("A intersection B = " + C);
}
示例10: check_difference_results_with_fixed_precision
public void check_difference_results_with_fixed_precision()
{
GeometryFactory precisionModel = new GeometryFactory(new PrecisionModel(100));
WKTReader reader = new WKTReader(precisionModel);
IGeometry p1 = reader.Read(@"POLYGON ((504927.9 6228865.64, 504969.88 6228833.89, 504980.82 6228861.76, 504927.9 6228865.64))");
IGeometry p2 = reader.Read(@"POLYGON ((504927.9 6228865.64, 504951.14 6228848.06, 504957.42 6228863.47, 504927.9 6228865.64))");
IGeometry test = p1.Difference(p2);
Assert.That(test, Is.Not.Null);
Assert.That(test.IsEmpty, Is.False);
const string expected = @"POLYGON ((504927.9 6228865.64, 504980.82 6228861.76, 504969.88 6228833.89, 504951.14 6228848.06, 504957.42 6228863.47, 504927.9 6228865.64))";
string actual = test.AsText();
Assert.That(actual, Is.EqualTo(expected));
}
示例11: Run
/// <summary>
///
/// </summary>
public virtual void Run()
{
GeometryFactory fact = new GeometryFactory();
WKTReader wktRdr = new WKTReader(fact);
string wktA = "POLYGON((40 100, 40 20, 120 20, 120 100, 40 100))";
string wktB = "LINESTRING(20 80, 80 60, 100 140)";
IGeometry A = wktRdr.Read(wktA);
IGeometry B = wktRdr.Read(wktB);
IGeometry C = A.Intersection(B);
Console.WriteLine("A = " + A);
Console.WriteLine("B = " + B);
Console.WriteLine("A intersection B = " + C);
Console.WriteLine("A relate C = " + A.Relate(B));
}
示例12: TestTransform
public void TestTransform()
{
CoordinateSystemFactory csFactory = new CoordinateSystemFactory();
const string sourceCsWkt = "GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]]";
ICoordinateSystem sourceCs = csFactory.CreateFromWkt(sourceCsWkt);
Assert.That(sourceCs, Is.Not.Null);
const string targetCsWkt = "PROJCS[\"WGS 84 / Australian Antarctic Lambert\",GEOGCS[\"WGS 84\",DATUM[\"WGS_1984\",SPHEROID[\"WGS 84\",6378137,298.257223563,AUTHORITY[\"EPSG\",\"7030\"]],AUTHORITY[\"EPSG\",\"6326\"]],PRIMEM[\"Greenwich\",0,AUTHORITY[\"EPSG\",\"8901\"]],UNIT[\"degree\",0.01745329251994328,AUTHORITY[\"EPSG\",\"9122\"]],AUTHORITY[\"EPSG\",\"4326\"]],PROJECTION[\"Lambert_Conformal_Conic_2SP\"],PARAMETER[\"standard_parallel_1\",-68.5],PARAMETER[\"standard_parallel_2\",-74.5],PARAMETER[\"latitude_of_origin\",-50],PARAMETER[\"central_meridian\",70],PARAMETER[\"false_easting\",6000000],PARAMETER[\"false_northing\",6000000],UNIT[\"metre\",1,AUTHORITY[\"EPSG\",\"9001\"]],AUTHORITY[\"EPSG\",\"3033\"]]";
ICoordinateSystem targetCs = csFactory.CreateFromWkt(targetCsWkt);
Assert.That(targetCs, Is.Not.Null);
CoordinateTransformationFactory ctFactory = new CoordinateTransformationFactory();
ICoordinateTransformation coordTransformation = ctFactory.CreateFromCoordinateSystems(sourceCs, targetCs);
IGeometryFactory gf = GeometryFactory.Default;
const string geomWkt = "MULTIPOINT (152.83949210500001 -42.14413555,152.83910355899999 -42.129844618)";
WKTReader reader = new WKTReader(gf);
IGeometry geom = reader.Read(geomWkt);
Assert.That(geom, Is.Not.Null);
Assert.That(geom.IsValid, Is.True);
Assert.That(geom, Is.InstanceOf<IMultiPoint>());
IMultiPoint mp = (IMultiPoint)geom;
foreach (IPoint pt in mp.Geometries)
{
IGeometry tp = GeometryTransform.TransformGeometry(gf, pt, coordTransformation.MathTransform);
Assert.That(tp, Is.Not.Null);
Assert.That(tp.IsValid, Is.True);
}
IGeometry transformed = GeometryTransform.TransformGeometry(gf, mp, coordTransformation.MathTransform);
Assert.That(transformed, Is.Not.Null);
Assert.That(transformed.IsValid, Is.True);
}
示例13: TestWktWkb
private static bool TestWktWkb(int number, IGeometryFactory factory, string wkt, string wkb)
{
WKTReader r = new WKTReader(factory);
IGeometry wktGeom = r.Read(wkt);
WKBReader s = new WKBReader(factory);
IGeometry wkbGeom = s.Read(WKBReader.HexToBytes(wkb));
try
{
Assert.AreEqual(wkb, WKBWriter.ToHex(wktGeom.AsBinary()), "wkb's don't match");
Assert.IsTrue(DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9, number + ": DiscreteHausdorffDistance.Distance(wktGeom, wkbGeom) < 1e-9");
if (!wktGeom.EqualsExact(wkbGeom))
{
Assert.AreEqual(wkt, wktGeom.AsText(), number + ": wkt.Equals(wktGeom.AsText())");
var wktGeom2 = s.Read(wktGeom.AsBinary());
Assert.AreEqual(wkt, wktGeom2.AsText(), number + ": wkt.Equals(wktGeom2.AsText())");
var diff = wkbGeom.Difference(wktGeom);
Assert.IsTrue(false, number + ": wktGeom.EqualsExact(wkbGeom)\n" + diff.AsText());
}
return false;
}
catch (AssertionException ex)
{
Console.WriteLine(ex.Message);
return true;
}
}
示例14: ToGeoJson
public static string ToGeoJson(System.Data.Entity.Spatial.DbGeometry location)
{
var wktReader = new WKTReader();
var geometry = wktReader.Read(location.WellKnownValue.WellKnownText);
var geoJsonWriter = new GeoJsonWriter();
return geoJsonWriter.Write(geometry);
}
示例15: OverlayUsingFixedPrecision
public void OverlayUsingFixedPrecision()
{
IGeometryFactory factory = GeometryFactory.Fixed;
WKTReader reader = new WKTReader(factory);
IGeometry pol = reader.Read(wktpol);
Assert.IsNotNull(pol);
Assert.IsTrue(pol.IsValid);
Assert.IsTrue(pol.Factory.PrecisionModel == factory.PrecisionModel);
IGeometry line = reader.Read(wktline);
Assert.IsNotNull(line);
Assert.IsTrue(line.IsValid);
Assert.IsTrue(line.Factory.PrecisionModel == factory.PrecisionModel);
Assert.IsTrue(pol.Intersects(line));
}