本文整理汇总了C#中NetTopologySuite.Geometries.GeometryFactory类的典型用法代码示例。如果您正苦于以下问题:C# GeometryFactory类的具体用法?C# GeometryFactory怎么用?C# GeometryFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeometryFactory类属于NetTopologySuite.Geometries命名空间,在下文中一共展示了GeometryFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Test
public void Test()
{
var features = new List<Features.IFeature>();
var seq = DotSpatialAffineCoordinateSequenceFactory.Instance.Create(1, Ordinates.XY);
seq.SetOrdinate(0, Ordinate.X, -91.0454);
seq.SetOrdinate(0, Ordinate.Y, 32.5907);
var pt = new GeometryFactory(DotSpatialAffineCoordinateSequenceFactory.Instance).CreatePoint(seq);
var attr = new Features.AttributesTable();
attr.AddAttribute("FirstName", "John");
attr.AddAttribute("LastName", "Doe");
features.Add(new Features.Feature(pt, attr));
var fileName = Path.GetTempFileName();
fileName = fileName.Substring(0, fileName.Length - 4);
var shpWriter = new IO.ShapefileDataWriter(fileName, features[0].Geometry.Factory)
{
Header = IO.ShapefileDataWriter.GetHeader(features[0], features.Count)
};
shpWriter.Write(features);
bool isTrue;
using (var reader = new IO.ShapefileDataReader(fileName, pt.Factory))
@isTrue = reader.ShapeHeader.ShapeType.ToString() == "Point";
foreach (var file in Directory.GetFiles(Path.GetTempPath(), Path.GetFileName(fileName) + ".*" ))
{
File.Delete(file);
}
Assert.IsTrue(@isTrue);
}
示例2: TestWriteZMValuesShapeFile
private void TestWriteZMValuesShapeFile(bool testM)
{
var points = new Coordinate[3];
points[0] = new Coordinate(0, 0);
points[1] = new Coordinate(1, 0);
points[2] = new Coordinate(1, 1);
var csFactory = NetTopologySuite.Geometries.Implementation.DotSpatialAffineCoordinateSequenceFactory.Instance;
var sequence = csFactory.Create(3, Ordinates.XYZM);
for (var i = 0; i < 3; i ++)
{
sequence.SetOrdinate(i, Ordinate.X, points[i].X);
sequence.SetOrdinate(i, Ordinate.Y, points[i].Y);
sequence.SetOrdinate(i, Ordinate.Z, 1 + i);
if (testM)
sequence.SetOrdinate(i, Ordinate.M, 11 + i);
}
var lineString = Factory.CreateLineString(sequence);
var attributes = new AttributesTable();
attributes.AddAttribute("FOO", "Trond");
var feature = new Feature(Factory.CreateMultiLineString(new[] { lineString }), attributes);
var features = new Feature[1];
features[0] = feature;
var shpWriter = new ShapefileDataWriter("ZMtest", Factory)
{
Header = ShapefileDataWriter.GetHeader(features[0], features.Length)
};
shpWriter.Write(features);
// Now let's read the file and verify that we got Z and M back
var factory = new GeometryFactory(NetTopologySuite.Geometries.Implementation.DotSpatialAffineCoordinateSequenceFactory.Instance);
using (var reader = new ShapefileDataReader("ZMtest", factory))
{
reader.Read();
var geom = reader.Geometry;
for (var i = 0; i < 3; i++)
{
var c = geom.Coordinates[i];
Assert.AreEqual(i + 1, c.Z);
}
if (testM)
{
sequence = ((ILineString) geom).CoordinateSequence;
for (var i = 0; i < 3; i++)
{
Assert.AreEqual(sequence.GetOrdinate(i, Ordinate.M), 11 + i);
}
}
// Run a simple attribute test too
var v = reader.GetString(0);
Assert.AreEqual(v, "Trond");
}
}
示例3: Form2_Load
private void Form2_Load(object sender, EventArgs e)
{
//TileAsyncLayer osmLayer= new TileAsyncLayer(new OsmTileSource(), "TileLayer - OSM");
TileAsyncLayer bingLayer = new TileAsyncLayer(new BingTileSource(BingRequest.UrlBing, "", BingMapType.Roads), "TileLayer - Bing");
this.mapBox1.Map.BackgroundLayer.Add(bingLayer);
GeometryFactory gf = new GeometryFactory(new PrecisionModel(), 3857);
#if DotSpatialProjections
var mathTransform = LayerTools.Wgs84toGoogleMercator;
var geom = GeometryTransform.TransformBox(
new Envelope(-9.205626, -9.123736, 38.690993, 38.740837),
mathTransform.Source, mathTransform.Target);
#else
IMathTransform mathTransform = LayerTools.Wgs84toGoogleMercator.MathTransform;
Envelope geom = GeometryTransform.TransformBox(
new Envelope(-9.205626, -9.123736, 38.690993, 38.740837),
mathTransform);
#endif
//Adds a pushpin layer
VectorLayer pushPinLayer = new VectorLayer("PushPins");
List<IGeometry> geos = new List<IGeometry>();
geos.Add(gf.CreatePoint(geom.Centre));
var geoProvider = new FeatureProvider(geos);
pushPinLayer.DataSource = geoProvider;
//this.mapBox1.Map.Layers.Add(pushPinLayer);
this.mapBox1.Map.ZoomToBox(geom);
this.mapBox1.Map.Zoom = 8500;
this.mapBox1.Refresh();
}
示例4: TestAreaPrecisionPerformance
public void TestAreaPrecisionPerformance()
{
const double originX = 1000000;
const double originY = 5000000;
var sw = new Stopwatch();
var sw1 = new Stopwatch();
var sw2 = new Stopwatch();
var sw3 = new Stopwatch();
//-2,23057128323489E-11
sw.Start();
for (var nrVertices = 4; nrVertices <= 5000000; nrVertices *= 2)
{
var coordinates = new Coordinate[nrVertices + 1];
for (var i = 0; i <= nrVertices; i++)
{
var vertex = new Coordinate(originX + (1d + Math.Sin( i/(double) nrVertices*2*Math.PI)),
originY + (1d + Math.Cos( i/(double) nrVertices*2*Math.PI)));
coordinates[i] = vertex;
}
// close ring
coordinates[nrVertices] = coordinates[0];
var g1 = new GeometryFactory().CreateLinearRing(coordinates);
var holes = new ILinearRing[] {};
var polygon = (Polygon) new GeometryFactory().CreatePolygon(g1, holes);
//Console.WriteLine(polygon);
sw1.Start();
var area = polygon.Area;
sw1.Stop();
sw2.Start();
var area2 = AccurateSignedArea(coordinates);
sw2.Stop();
sw3.Start();
var areaOld = OriginalSignedArea(coordinates);
sw3.Stop();
var exactArea = 0.5 * nrVertices * Math.Sin(2 * Math.PI / nrVertices);
var eps1 = exactArea - area;
var eps2 = exactArea - area2;
var eps3 = exactArea - areaOld;
//Assert.IsTrue(Math.Abs(eps2) <= Math.Abs(eps3));
Console.WriteLine(string.Format("{0,10},\tnow err: {1,23},\tacc err: {2,23},\told err: {3,23}", nrVertices ,eps1, eps2 ,eps3));
}
sw.Stop();
Console.WriteLine("\n\nTime: " + sw.Elapsed);
Console.WriteLine("Time Now: " + sw1.ElapsedTicks);
Console.WriteLine("Time Acc: " + sw2.ElapsedTicks);
Console.WriteLine("Time Old: " + sw3.ElapsedTicks);
Assert.IsTrue(true);
}
示例5: main
public static void main(string[] args)
{
ExtendedCoordinateSequenceFactory seqFact = ExtendedCoordinateSequenceFactory.Instance();
ExtendedCoordinate[] array1 = new ExtendedCoordinate[] { new ExtendedCoordinate(0, 0, 0, 91),
new ExtendedCoordinate(10, 0, 0, 92), new ExtendedCoordinate(10, 10, 0, 93),
new ExtendedCoordinate(0, 10, 0, 94), new ExtendedCoordinate(0, 0, 0, 91)};
ICoordinateSequence seq1 = seqFact.Create(array1);
ICoordinateSequence seq2 = seqFact.Create(new ExtendedCoordinate[] { new ExtendedCoordinate(5, 5, 0, 91),
new ExtendedCoordinate(15, 5, 0, 92), new ExtendedCoordinate(15, 15, 0, 93),
new ExtendedCoordinate(5, 15, 0, 94), new ExtendedCoordinate(5, 5, 0, 91)});
GeometryFactory fact = new GeometryFactory(ExtendedCoordinateSequenceFactory.Instance());
IGeometry g1 = fact.CreatePolygon(fact.CreateLinearRing(seq1), null);
IGeometry g2 = fact.CreatePolygon(fact.CreateLinearRing(seq2), null);
Console.WriteLine("WKT for g1: " + g1);
Console.WriteLine("Internal rep for g1: " + ((IPolygon) g1).ExteriorRing.CoordinateSequence);
Console.WriteLine("WKT for g2: " + g2);
Console.WriteLine("Internal rep for g2: " + ((IPolygon)g2).ExteriorRing.CoordinateSequence);
IGeometry gInt = g1.Intersection(g2);
Console.WriteLine("WKT for gInt: " + gInt);
Console.WriteLine("Internal rep for gInt: " + ((IPolygon)gInt).ExteriorRing.CoordinateSequence);
}
示例6: XmlTestFactory
public XmlTestFactory(PrecisionModel pm, IGeometryOperation geometryOperation, IResultMatcher resultMatcher)
{
ObjGeometryFactory = new GeometryFactory(pm);
_geometryOperation = geometryOperation;
_resultMatcher = resultMatcher;
_objReader = new WKTOrWKBReader(ObjGeometryFactory);
}
示例7: GetASecondLine
public static ILineString GetASecondLine()
{
var q1 = new Coordinate(0, 10);
var q2 = new Coordinate(10, 0);
var coordinatesq = new[] { q1, q2 };
var line2 = new GeometryFactory().CreateLineString(coordinatesq);
return line2;
}
示例8: GetALine
public static ILineString GetALine()
{
var p1 = new Coordinate(0, 0);
var p2 = new Coordinate(10, 10);
var coordinatesp = new[] { p1, p2 };
var line1 = new GeometryFactory().CreateLineString(coordinatesp);
return line1;
}
示例9: TestPackedCoordinateSequence
public void TestPackedCoordinateSequence() {
var pcsFactory = new GeometryFactory(PackedCoordinateSequenceFactory.DoubleFactory);
var geom0 = Read(pcsFactory, "POLYGON ((210 210, 210 220, 220 220, 220 210, 210 210))");
var geom1 = Read("POLYGON ((225 225, 225 215, 215 215, 215 225, 225 225))");
var cbo = new CommonBitsOp(true);
var result = cbo.Intersection(geom0, geom1);
var expected = geom0.Intersection(geom1);
//Geometry expected = read("POLYGON ((220 215, 215 215, 215 220, 220 220, 220 215))");
CheckEqual(expected, result);
}
示例10: 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);
}
示例11: GeometryPrecisionReducerTest
public GeometryPrecisionReducerTest()
{
pmFloat = new PrecisionModel();
pmFixed1 = new PrecisionModel(1);
reducer = new GeometryPrecisionReducer(pmFixed1);
reducerKeepCollapse = new GeometryPrecisionReducer(pmFixed1);
gfFloat = new GeometryFactory(pmFloat, 0);
reader = new WKTReader(gfFloat);
reducerKeepCollapse.RemoveCollapsedComponents = false;
}
示例12: CoordinateTransformationTransformsQueryHavingDifferentSpatialReferenceAsTransformationTarget
public void CoordinateTransformationTransformsQueryHavingDifferentSpatialReferenceAsTransformationTarget()
{
MockRepository repository = new MockRepository();
FeatureProviderBase provider = repository.CreateMock<FeatureProviderBase>();
BufferedCoordinateFactory coordFactory = new BufferedCoordinateFactory();
BufferedCoordinateSequenceFactory coordSeqFactory = new BufferedCoordinateSequenceFactory(coordFactory);
IGeometryFactory<BufferedCoordinate> geoFactory = new GeometryFactory<BufferedCoordinate>(coordSeqFactory);
IMatrixFactory<DoubleComponent> matrixFactory = new LinearFactory<DoubleComponent>();
ICoordinateTransformationFactory transformFactory =
new CoordinateTransformationFactory<BufferedCoordinate>(coordFactory, geoFactory, matrixFactory);
SetupResult.For(provider.CoordinateTransformation).Return(transformFactory);
}
示例13: 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));
}
示例14: main
public static void main(string[] args)
{
// create a factory using default values (e.g. floating precision)
GeometryFactory fact = new GeometryFactory();
IPoint p1 = fact.CreatePoint(new Coordinate(0, 0));
Console.WriteLine(p1);
IPoint p2 = fact.CreatePoint(new Coordinate(1, 1));
Console.WriteLine(p1);
IMultiPoint mpt = fact.CreateMultiPoint(new Coordinate[]{ new Coordinate(0, 0), new Coordinate(1, 1), });
Console.WriteLine(mpt);
}
示例15: 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));
}