本文整理汇总了C#中NetTopologySuite.IO.WKTReader类的典型用法代码示例。如果您正苦于以下问题:C# WKTReader类的具体用法?C# WKTReader怎么用?C# WKTReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WKTReader类属于NetTopologySuite.IO命名空间,在下文中一共展示了WKTReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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);
}
示例3: Test5
public void Test5()
{
WKTReader reader = new WKTReader(new GeometryFactory(new PrecisionModel(1), 0));
IGeometry geometry = reader.Read("MULTIPOINT (0 0, 5 0, 10 0)");
LineString convexHull = (LineString)reader.Read("LINESTRING (0 0, 10 0)");
Assert.IsTrue(convexHull.EqualsExact(geometry.ConvexHull()));
}
示例4: 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);
}
示例5: 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);
}
示例6: 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()));
}
示例7: 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;
}
}
示例8: 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));
}
示例9: 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);
}
示例10: TestIssue147
public void TestIssue147()
{
var wkt = "POLYGON ((-94.16 42.25, -94.15 42.26, -94.14 42.25, -94.16 42.25))";
var geom = new WKTReader().Read(wkt);
Assert.AreEqual(
"0x010300000001000000040000000AD7A3703D8A57C000000000002045409A999999998957C0E17A14AE47214540295C8FC2F58857C000000000002045400AD7A3703D8A57C00000000000204540",
"0x"+ WKBWriter.ToHex(geom.AsBinary()));
}
示例11: UnionAggregate
public static System.Data.Entity.Spatial.DbGeometry UnionAggregate(
IEnumerable<System.Data.Entity.Spatial.DbGeometry> dbGeometrys)
{
var wktReader = new WKTReader();
var geometries = dbGeometrys.Select(x => wktReader.Read(x.WellKnownValue.WellKnownText)).ToArray();
var collection = new GeometryCollection(geometries);
var wktWriter = new WKTWriter();
return System.Data.Entity.Spatial.DbGeometry.FromText(wktWriter.Write(collection));
}
示例12: 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);
}
示例13: TestSerializeable
public void TestSerializeable(string wkt)
{
var reader = new WKTReader(new GeometryFactory());
var gS = (Geometry)reader.Read(wkt);
var buffer = SerializationUtility.Serialize(gS);
var gD = SerializationUtility.Deserialize<Geometry>(buffer);
Assert.IsTrue(gD.EqualsExact(gS));
}
示例14: 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);
}
示例15: test_intersection_bug_clipped
public void test_intersection_bug_clipped()
{
IGeometryFactory factory = GeometryFactory.Default;
WKTReader reader = new WKTReader(factory);
IGeometry geom = reader.Read(NonNodedIntersection);
Envelope clipEnv = geom.EnvelopeInternal;
clipEnv.ExpandBy(BufferValue);
IGeometry clip = factory.ToGeometry(clipEnv);
Assert.DoesNotThrow(() => DoIntersection(FromWkb(Poly1Wkb, clip), FromWkb(Poly2Wkb, clip), clip));
}