本文整理汇总了C#中IGeometryFactory.CreatePolygon方法的典型用法代码示例。如果您正苦于以下问题:C# IGeometryFactory.CreatePolygon方法的具体用法?C# IGeometryFactory.CreatePolygon怎么用?C# IGeometryFactory.CreatePolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGeometryFactory
的用法示例。
在下文中一共展示了IGeometryFactory.CreatePolygon方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCircle
public static IPolygon CreateCircle(
IGeometryFactory fact,
double basex,
double basey,
double size,
int nPts)
{
Coordinate[] pts = CreateCircle(basex, basey, size, nPts);
var ring = fact.CreateLinearRing(pts);
var poly = fact.CreatePolygon(ring, null);
return poly;
}
示例2: ReadPolygon
private static GeoAPI.Geometries.IPolygon ReadPolygon(byte[] geom, ref int idx, bool isLittleEndian, IGeometryFactory factory)
{
double[] adfTuple = new double[2];
int nRings;
nRings = ReadUInt32(geom,ref idx, isLittleEndian);
if (nRings < 1 || nRings > Int32.MaxValue / (2 * 8))
throw new ApplicationException("Currupt SpatialLite geom");
List<GeoAPI.Geometries.ILineString> lineStrings = new List<GeoAPI.Geometries.ILineString>();
for (int i = 0; i < nRings; i++)
lineStrings.Add(ReadLineString(geom,ref idx, isLittleEndian, factory));
List<GeoAPI.Geometries.ILinearRing> holes = null;
var shell = factory.CreateLinearRing(lineStrings[0].Coordinates);
if (lineStrings.Count > 1)
{
holes = new List<GeoAPI.Geometries.ILinearRing>();
for (int i = 1; i < lineStrings.Count; i++)
{
holes.Add(new NetTopologySuite.Geometries.LinearRing(lineStrings[i].Coordinates));
}
}
return factory.CreatePolygon(shell, holes == null ? null : holes.ToArray());
}
示例3: GetTriangles
/// <summary>
/// Gets the geometry for the triangles in a triangulated subdivision as a <see cref="IGeometryCollection"/>
/// of triangular <see cref="IPolygon"/>s.
/// </summary>
/// <param name="geomFact">the GeometryFactory to use</param>
/// <returns>a GeometryCollection of triangular Polygons</returns>
public IGeometryCollection GetTriangles(IGeometryFactory geomFact)
{
var triPtsList = GetTriangleCoordinates(false);
IPolygon[] tris = new Polygon[triPtsList.Count];
int i = 0;
foreach (var triPt in triPtsList)
{
tris[i++] = geomFact
.CreatePolygon(geomFact.CreateLinearRing(triPt), null);
}
return geomFact.CreateGeometryCollection(tris);
}
示例4: ToPolygon
/// <summary>
///
/// </summary>
/// <param name="geometryFactory"></param>
/// <returns></returns>
public IPolygon ToPolygon(IGeometryFactory geometryFactory)
{
ILinearRing[] holeLR = new ILinearRing[_holes.Count];
for (int i = 0; i < _holes.Count; i++)
holeLR[i] = _holes[i].LinearRing;
IPolygon poly = geometryFactory.CreatePolygon(LinearRing, holeLR);
return poly;
}
示例5: GeneratePolygons
private static void GeneratePolygons(IGeometryFactory factory, ICollection<IGeometry> geometry, Random rndGen)
{
int numPolygons = rndGen.Next(10, 100);
for (var polyIndex = 0; polyIndex < numPolygons; polyIndex++)
{
var vertices = new GeoPoint[5];
var upperLeft = new GeoPoint(rndGen.NextDouble()*1000, rndGen.NextDouble()*1000);
var sideLength = rndGen.NextDouble()*50;
// Make a square
vertices[0] = new GeoPoint(upperLeft.X, upperLeft.Y);
vertices[1] = new GeoPoint(upperLeft.X + sideLength, upperLeft.Y);
vertices[2] = new GeoPoint(upperLeft.X + sideLength, upperLeft.Y - sideLength);
vertices[3] = new GeoPoint(upperLeft.X, upperLeft.Y - sideLength);
vertices[4] = upperLeft;
geometry.Add(factory.CreatePolygon(factory.CreateLinearRing(vertices), null));
}
}
示例6: TransformPolygon
/// <summary>
/// Transforms a <see cref="GeoAPI.Geometries.IPolygon"/>.
/// </summary>
/// <param name="p">Polygon to transform</param>
/// <param name="from">Source Projection</param>
/// <param name="to">Target Projection</param>
/// <param name="toFactory">The factory to create geometries for <paramref name="to"/></param>
/// <returns>Transformed Polygon</returns>
public static IPolygon TransformPolygon(IPolygon p, ProjectionInfo from, ProjectionInfo to, IGeometryFactory toFactory)
{
var shell = toFactory.CreateLinearRing(TransformSequence(p.Shell.CoordinateSequence, from, to, toFactory.CoordinateSequenceFactory));
var holes = new ILinearRing[p.NumInteriorRings];
for (var i = 0; i < p.NumInteriorRings; i++)
holes[i] = toFactory.CreateLinearRing(TransformSequence(p.GetInteriorRingN(i).CoordinateSequence, from, to, toFactory.CoordinateSequenceFactory));
return toFactory.CreatePolygon(shell, holes);
}
示例7: TransformPolygon
/// <summary>
/// Transforms a <see cref="Polygon" /> object.
/// </summary>
/// <param name="factory"></param>
/// <param name="p"></param>
/// <param name="transform"></param>
/// <returns></returns>
public static IPolygon TransformPolygon(IGeometryFactory factory,
IPolygon p, IMathTransform transform)
{
List<ILinearRing> holes = new List<ILinearRing>(p.InteriorRings.Length);
for (int i = 0; i < p.InteriorRings.Length; i++)
{
ILinearRing hole = TransformLinearRing(factory,
(ILinearRing) p.InteriorRings[i], transform);
holes.Add(hole);
}
ILinearRing shell = TransformLinearRing(factory,
(ILinearRing) p.ExteriorRing, transform);
return factory.CreatePolygon(shell, holes.ToArray());
}
示例8: ReadPolygonText
/// <summary>
/// Creates a Polygon using the next token in the stream.
/// </summary>
/// <param name="tokenizer">Tokenizer over a stream of text in Well-known Text
/// format. The next tokens must form a <Polygon Text>.</param>
/// <param name="factory">The factory to create the result geometry</param>
/// <returns>Returns a Polygon specified by the next token
/// in the stream</returns>
/// <remarks>
/// ParseException is thrown if the coordinates used to create the Polygon
/// shell and holes do not form closed linestrings, or if an unexpected
/// token is encountered.
/// </remarks>
private static IPolygon ReadPolygonText(WktStreamTokenizer tokenizer, IGeometryFactory factory)
{
string nextToken = GetNextEmptyOrOpener(tokenizer);
if (nextToken == "EMPTY")
return factory.CreatePolygon(null, null);
var exteriorRing = factory.CreateLinearRing(GetCoordinates(tokenizer));
nextToken = GetNextCloserOrComma(tokenizer);
var interiorRings = new List<ILinearRing>();
while (nextToken == ",")
{
//Add holes
interiorRings.Add(factory.CreateLinearRing(GetCoordinates(tokenizer)));
nextToken = GetNextCloserOrComma(tokenizer);
}
return factory.CreatePolygon(exteriorRing, interiorRings.ToArray());
}
示例9: ToNTSPolygon
internal static NTSPolygon ToNTSPolygon(Geometries.Polygon geom,
IGeometryFactory factory)
{
NTSLinearRing shell = ToNTSLinearRing(geom.ExteriorRing, factory);
NTSLinearRing[] holes = new NTSLinearRing[geom.InteriorRings.Count];
int index = 0;
foreach (Geometries.LinearRing hole in geom.InteriorRings)
holes[index++] = ToNTSLinearRing(hole, factory);
return factory.CreatePolygon(shell, holes) as NTSPolygon;
}
示例10: CreateWKBPolygon
private static IPolygon CreateWKBPolygon(BinaryReader reader, WkbByteOrder byteOrder, IGeometryFactory factory)
{
// Get the Number of rings in this Polygon.
var numRings = (int) ReadUInt32(reader, byteOrder);
Debug.Assert(numRings >= 1, "Number of rings in polygon must be 1 or more.");
var shell = CreateWKBLinearRing(reader, byteOrder, factory);
var holes = new ILinearRing[--numRings];
for (var i = 0; i < numRings; i++)
holes[i] = CreateWKBLinearRing(reader, byteOrder, factory);
return factory.CreatePolygon(shell, holes);
}
示例11: generatePolygons
private static void generatePolygons(IGeometryFactory geometryFactory,
ICollection<IGeometry> geometry,
Random rndGen)
{
ICoordinateSequenceFactory coordinateSequenceFactory =
geometryFactory.CoordinateSequenceFactory;
ICoordinateFactory coordinateFactory = geometryFactory.CoordinateFactory;
ICoordinateSequence coords = coordinateSequenceFactory.Create(CoordinateDimensions.Two);
Int32 polyCount = rndGen.Next(10, 100);
for (Int32 polyIndex = 0; polyIndex < polyCount; polyIndex++)
{
ICoordinate upperLeft = coordinateFactory.Create(rndGen.NextDouble() * 1000,
rndGen.NextDouble() * 1000);
Double sideLength = rndGen.NextDouble() * 50;
// Make a square
coords.Add(upperLeft);
coords.Add(coordinateFactory.Create(upperLeft[Ordinates.X] + sideLength,
upperLeft[Ordinates.Y]));
coords.Add(coordinateFactory.Create(upperLeft[Ordinates.X] + sideLength,
upperLeft[Ordinates.Y] - sideLength));
coords.Add(coordinateFactory.Create(upperLeft[Ordinates.X],
upperLeft[Ordinates.Y] - sideLength));
IPolygon polygon = geometryFactory.CreatePolygon(coords);
geometry.Add(polygon);
}
}
示例12: Read
//.........这里部分代码省略.........
if ( ! ( shapeType == ShapeGeometryTypes.Polygon || shapeType == ShapeGeometryTypes.PolygonM ||
shapeType == ShapeGeometryTypes.PolygonZ || shapeType == ShapeGeometryTypes.PolygonZM))
throw new ShapefileException("Attempting to load a non-polygon as polygon.");
// Read and for now ignore bounds.
double[] box = new double[4];
for (int i = 0; i < 4; i++)
box[i] = file.ReadDouble();
int numParts = file.ReadInt32();
int numPoints = file.ReadInt32();
int[] partOffsets = new int[numParts];
for (int i = 0; i < numParts; i++)
partOffsets[i] = file.ReadInt32();
ArrayList shells = new ArrayList();
ArrayList holes = new ArrayList();
for (int part = 0; part < numParts; part++)
{
int start = partOffsets[part];
int finish;
if (part == numParts - 1)
finish = numPoints;
else finish = partOffsets[part + 1];
int length = finish - start;
CoordinateList points = new CoordinateList();
for (int i = 0; i < length; i++)
{
Coordinate external = new Coordinate(file.ReadDouble(), file.ReadDouble() );
new PrecisionModel(geometryFactory.PrecisionModel).MakePrecise(external);
Coordinate internalCoord = external;
points.Add(internalCoord);
}
ILinearRing ring = geometryFactory.CreateLinearRing(points.ToArray());
// If shape have only a part, jump orientation check and add to shells
if (numParts == 1)
shells.Add(ring);
else
{
// Orientation check
if (CGAlgorithms.IsCounterClockwise(points.ToArray()))
holes.Add(ring);
else shells.Add(ring);
}
}
// Now we have a list of all shells and all holes
ArrayList holesForShells = new ArrayList(shells.Count);
for (int i = 0; i < shells.Count; i++)
holesForShells.Add(new ArrayList());
// Find holes
for (int i = 0; i < holes.Count; i++)
{
LinearRing testRing = (LinearRing) holes[i];
LinearRing minShell = null;
IEnvelope minEnv = null;
IEnvelope testEnv = testRing.EnvelopeInternal;
Coordinate testPt = testRing.GetCoordinateN(0);
LinearRing tryRing;
for (int j = 0; j < shells.Count; j++)
{
tryRing = (LinearRing) shells[j];
IEnvelope tryEnv = tryRing.EnvelopeInternal;
if (minShell != null)
minEnv = minShell.EnvelopeInternal;
bool isContained = false;
CoordinateList coordList = new CoordinateList(tryRing.Coordinates);
if (tryEnv.Contains(testEnv)
&& (CGAlgorithms.IsPointInRing(testPt, coordList.ToArray())
|| (PointInList(testPt, coordList))))
isContained = true;
// Check if this new containing ring is smaller than the current minimum ring
if (isContained)
{
if (minShell == null || minEnv.Contains(tryEnv))
minShell = tryRing;
// Suggested by Brian Macomber and added 3/28/2006:
// holes were being found but never added to the holesForShells array
// so when converted to geometry by the factory, the inner rings were never created.
ArrayList holesForThisShell = (ArrayList)holesForShells[j];
holesForThisShell.Add(holes[i]);
}
}
}
IPolygon[] polygons = new Polygon[shells.Count];
for (int i = 0; i < shells.Count; i++)
polygons[i] = geometryFactory.CreatePolygon((LinearRing) shells[i],
(LinearRing[])((ArrayList) holesForShells[i]).ToArray(typeof(LinearRing)));
if (polygons.Length == 1)
return polygons[0];
// It's a multi part
return geometryFactory.CreateMultiPolygon(polygons);
}
示例13: GetVoronoiCellPolygon
/// <summary>
/// Gets the Voronoi cell around a site specified
/// by the origin of a QuadEdge.
/// </summary>
/// <remarks>
/// The userData of the polygon is set to be the <see cref="Coordinate" />
/// of the site. This allows attaching external
/// data associated with the site to this cell polygon.
/// </remarks>
/// <param name="qe">a quadedge originating at the cell site</param>
/// <param name="geomFact">a factory for building the polygon</param>
/// <returns>a polygon indicating the cell extent</returns>
public IPolygon GetVoronoiCellPolygon(QuadEdge qe, IGeometryFactory geomFact)
{
var cellPts = new List<Coordinate>();
QuadEdge startQE = qe;
do
{
// Coordinate cc = circumcentre(qe);
// use previously computed circumcentre
Coordinate cc = qe.Rot.Orig.Coordinate;
cellPts.Add(cc);
// move to next triangle CW around vertex
qe = qe.OPrev;
} while (qe != startQE);
var coordList = new CoordinateList();
coordList.AddAll(cellPts, false);
coordList.CloseRing();
if (coordList.Count < 4)
{
#if !PCL
Debug.WriteLine(coordList);
#endif
coordList.Add(coordList[coordList.Count - 1], true);
}
Coordinate[] pts = coordList.ToCoordinateArray();
IPolygon cellPoly = geomFact.CreatePolygon(geomFact.CreateLinearRing(pts), null);
Vertex v = startQE.Orig;
cellPoly.UserData = v.Coordinate;
return cellPoly;
}
示例14: FromPolygon
/// <summary>
/// Creates a Polygon or MultiPolygon from this Polygon shape.
/// </summary>
/// <param name="factory">The IGeometryFactory to use to create the new IGeometry.</param>
/// <returns>The IPolygon or IMultiPolygon created from this shape.</returns>
protected IGeometry FromPolygon(IGeometryFactory factory)
{
if (factory == null) factory = Geometry.DefaultFactory;
List<ILinearRing> shells = new List<ILinearRing>();
List<ILinearRing> holes = new List<ILinearRing>();
foreach (PartRange part in _shapeRange.Parts)
{
List<Coordinate> coords = new List<Coordinate>();
int i = part.StartIndex;
foreach (Vertex d in part)
{
Coordinate c = new Coordinate(d.X, d.Y);
if (M != null && M.Length > 0) c.M = M[i];
if (Z != null && Z.Length > 0) c.Z = Z[i];
i++;
coords.Add(c);
}
ILinearRing ring = factory.CreateLinearRing(coords);
if (_shapeRange.Parts.Count == 1)
{
shells.Add(ring);
}
else
{
if (CgAlgorithms.IsCounterClockwise(ring.Coordinates))
{
holes.Add(ring);
}
else
{
shells.Add(ring);
}
}
}
//// Now we have a list of all shells and all holes
List<ILinearRing>[] holesForShells = new List<ILinearRing>[shells.Count];
for (int i = 0; i < shells.Count; i++)
{
holesForShells[i] = new List<ILinearRing>();
}
// Find holes
foreach (ILinearRing t in holes)
{
ILinearRing testRing = t;
ILinearRing minShell = null;
IEnvelope minEnv = null;
IEnvelope testEnv = testRing.EnvelopeInternal;
Coordinate testPt = testRing.Coordinates[0];
ILinearRing tryRing;
for (int j = 0; j < shells.Count; j++)
{
tryRing = shells[j];
IEnvelope tryEnv = tryRing.EnvelopeInternal;
if (minShell != null)
minEnv = minShell.EnvelopeInternal;
bool isContained = false;
if (tryEnv.Contains(testEnv)
&& (CgAlgorithms.IsPointInRing(testPt, tryRing.Coordinates)
|| (PointInList(testPt, tryRing.Coordinates))))
{
isContained = true;
}
// Check if this new containing ring is smaller than the current minimum ring
if (isContained)
{
if (minShell == null || minEnv.Contains(tryEnv))
{
minShell = tryRing;
}
holesForShells[j].Add(t);
}
}
}
IPolygon[] polygons = new Polygon[shells.Count];
for (int i = 0; i < shells.Count; i++)
{
polygons[i] = factory.CreatePolygon(shells[i], holesForShells[i].ToArray());
}
if (polygons.Length == 1)
{
return polygons[0];
}
// It's a multi part
return factory.CreateMultiPolygon(polygons);
}
示例15: ToGeometry
public IGeometry ToGeometry(IGeometryFactory geomFactory)
{
if (IsNull)
{
return geomFactory.CreatePoint((ICoordinateSequence)null);
}
Coordinate px00 = new Coordinate(_minX, _minA - _minX);
Coordinate px01 = new Coordinate(_minX, _minX - _minB);
Coordinate px10 = new Coordinate(_maxX, _maxX - _maxB);
Coordinate px11 = new Coordinate(_maxX, _maxA - _maxX);
Coordinate py00 = new Coordinate(_minA - _minY, _minY);
Coordinate py01 = new Coordinate(_minY + _maxB, _minY);
Coordinate py10 = new Coordinate(_maxY + _minB, _maxY);
Coordinate py11 = new Coordinate(_maxA - _maxY, _maxY);
IPrecisionModel pm = geomFactory.PrecisionModel;
pm.MakePrecise(px00);
pm.MakePrecise(px01);
pm.MakePrecise(px10);
pm.MakePrecise(px11);
pm.MakePrecise(py00);
pm.MakePrecise(py01);
pm.MakePrecise(py10);
pm.MakePrecise(py11);
CoordinateList coordList = new CoordinateList();
coordList.Add(px00, false);
coordList.Add(px01, false);
coordList.Add(py10, false);
coordList.Add(py11, false);
coordList.Add(px11, false);
coordList.Add(px10, false);
coordList.Add(py01, false);
coordList.Add(py00, false);
if (coordList.Count == 1)
{
return geomFactory.CreatePoint(px00);
}
Coordinate[] pts;
if (coordList.Count == 2)
{
pts = coordList.ToCoordinateArray();
return geomFactory.CreateLineString(pts);
}
// must be a polygon, so add closing point
coordList.Add(px00, false);
pts = coordList.ToCoordinateArray();
return geomFactory.CreatePolygon(geomFactory.CreateLinearRing(pts), null);
}