本文整理汇总了C#中Geotools.Geometries.GeometryFactory.CreateMultiPolygon方法的典型用法代码示例。如果您正苦于以下问题:C# GeometryFactory.CreateMultiPolygon方法的具体用法?C# GeometryFactory.CreateMultiPolygon怎么用?C# GeometryFactory.CreateMultiPolygon使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Geotools.Geometries.GeometryFactory
的用法示例。
在下文中一共展示了GeometryFactory.CreateMultiPolygon方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
//.........这里部分代码省略.........
partOffsets[i] = file.ReadInt32();
}
ArrayList shells = new ArrayList();
ArrayList holes = new ArrayList();
int start, finish, length;
for (int part = 0; part < numParts; part++)
{
start = partOffsets[part];
if (part == numParts - 1)
{
finish = numPoints;
}
else
{
finish = partOffsets[part + 1];
}
length = finish - start;
Coordinates points = new Coordinates();
points.Capacity=length;
for (int i = 0; i < length; i++)
{
Coordinate external = new Coordinate(file.ReadDouble(), file.ReadDouble() );
Coordinate internalCoord = geometryFactory.PrecisionModel.ToInternal(external);
points.Add(internalCoord);
}
LinearRing ring = geometryFactory.CreateLinearRing(points);
//Debug.Assert(ring.IsValid()==false,"Ring is not valid.");
if (_cga.IsCCW(points))
{
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 homes
for (int i = 0; i < holes.Count; i++)
{
LinearRing testRing = (LinearRing) holes[i];
LinearRing minShell = null;
Envelope minEnv = null;
Envelope testEnv = testRing.GetEnvelopeInternal();
Coordinate testPt = testRing.GetCoordinateN(0);
LinearRing tryRing;
for (int j = 0; j < shells.Count; j++)
{
tryRing = (LinearRing) shells[j];
Envelope tryEnv = tryRing.GetEnvelopeInternal();
if (minShell != null)
{
minEnv = minShell.GetEnvelopeInternal();
}
bool isContained = false;
Coordinates coordList = tryRing.GetCoordinates() ;
if (tryEnv.Contains(testEnv)
&& (_cga.IsPointInRing(testPt,coordList ) ||
(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;
}
}
}
//if (minShell==null)
//{
// throw new InvalidOperationException("Could not find shell for a hole. Try a different precision model.");
//}
}
Polygon[] 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);
}
示例2: CreateMP1
private MultiPolygon CreateMP1()
{
Polygon[] polygons = new Polygon[2];
LineString[] rings = new LineString[2];
Coordinates coords = new Coordinates();
Coordinate coord = new Coordinate(5, 1);
coords.Add(coord);
coord = new Coordinate(6, 2);
coords.Add(coord);
coord = new Coordinate(7, 3);
coords.Add(coord);
coord = new Coordinate(6, 4);
coords.Add(coord);
coord = new Coordinate(5, 5);
coords.Add(coord);
coord = new Coordinate(4, 4);
coords.Add(coord);
coord = new Coordinate(3, 3);
coords.Add(coord);
coord = new Coordinate(4, 2);
coords.Add(coord);
coord = new Coordinate(5, 1);
coords.Add(coord);
GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
LinearRing exterior1 = gf.CreateLinearRing(coords);
polygons[0] = gf.CreatePolygon(exterior1);
rings[0] = exterior1 as LineString;
coords = new Coordinates();
coord = new Coordinate(5, 1);
coords.Add(coord);
coord = new Coordinate(6, 2);
coords.Add(coord);
coord = new Coordinate(7, 3);
coords.Add(coord);
coord = new Coordinate(6, 4);
coords.Add(coord);
coord = new Coordinate(5, 5);
coords.Add(coord);
coord = new Coordinate(4, 4);
coords.Add(coord);
coord = new Coordinate(3, 3);
coords.Add(coord);
coord = new Coordinate(4, 2);
coords.Add(coord);
coord = new Coordinate(5, 1);
coords.Add(coord);
LinearRing exterior2 = gf.CreateLinearRing(coords);
polygons[1] = gf.CreatePolygon(exterior2);
rings[1] = exterior2;
_mls1 = gf.CreateMultiLineString(rings);
return gf.CreateMultiPolygon(polygons);
}
示例3: Write
/// <summary>
/// Writes a Geometry to the given binary wirter.
/// </summary>
/// <param name="geometry">The geometry to write.</param>
/// <param name="file">The file stream to write to.</param>
/// <param name="geometryFactory">The geometry factory to use.</param>
public override void Write(Geometry geometry, System.IO.BinaryWriter file, GeometryFactory geometryFactory)
{
if (geometry.IsValid()==false)
{
Trace.WriteLine("Invalid polygon being written.");
}
GeometryCollection multi;
if(geometry is GeometryCollection)
{
multi = (GeometryCollection) geometry;
}
else
{
GeometryFactory gf = new GeometryFactory(geometry.PrecisionModel, geometry.GetSRID());
//multi = new MultiPolygon(new Polygon[]{(Polygon) geometry}, geometry.PrecisionModel, geometry.GetSRID());
multi = gf.CreateMultiPolygon( new Polygon[]{(Polygon) geometry} );
}
//file.setLittleEndianMode(true);
file.Write(int.Parse(Enum.Format(typeof(ShapeType),this.ShapeType,"d")));
Envelope box = multi.GetEnvelopeInternal();
Envelope bounds = ShapeHandler.GetEnvelopeExternal(geometryFactory.PrecisionModel, box);
file.Write(bounds.MinX);
file.Write(bounds.MinY);
file.Write(bounds.MaxX);
file.Write(bounds.MaxY);
int numParts = GetNumParts(multi);
int numPoints = multi.GetNumPoints();
file.Write(numParts);
file.Write(numPoints);
// write the offsets to the points
int offset=0;
for (int part = 0; part < multi.Count; part++)
{
// offset to the shell points
Polygon polygon = (Polygon)multi[part];
file.Write(offset);
offset = offset + polygon.Shell.GetNumPoints();
// offstes to the holes
foreach (LinearRing ring in polygon.Holes)
{
file.Write(offset);
offset = offset + ring.GetNumPoints();
}
}
// write the points
for (int part = 0; part < multi.Count; part++)
{
Polygon poly = (Polygon)multi[part];
Coordinates points = poly.Shell.GetCoordinates();
if (_cga.IsCCW(points)==true)
{
//points = points.ReverseCoordinateOrder();
}
WriteCoords(points, file, geometryFactory);
foreach(LinearRing ring in poly.Holes)
{
Coordinates points2 = ring.GetCoordinates();
if (_cga.IsCCW(points2)==false)
{
//points2 = points2.ReverseCoordinateOrder();
}
WriteCoords(points2, file, geometryFactory);
}
}
}
示例4: CreateMP2
private MultiPolygon CreateMP2()
{
Polygon[] polygons = new Polygon[2];
GeometryFactory gf = new GeometryFactory(_precMod, _sRID);
Coordinates coords = new Coordinates();
Coordinate coord = new Coordinate(10, 13);
coords.Add(coord);
coord = new Coordinate(11, 13);
coords.Add(coord);
coord = new Coordinate(12, 13);
coords.Add(coord);
coord = new Coordinate(13, 14);
coords.Add(coord);
coord = new Coordinate(14, 15);
coords.Add(coord);
coord = new Coordinate(15, 16);
coords.Add(coord);
coord = new Coordinate(15, 17);
coords.Add(coord);
coord = new Coordinate(15, 18);
coords.Add(coord);
coord = new Coordinate(14, 19);
coords.Add(coord);
coord = new Coordinate(13, 20);
coords.Add(coord);
coord = new Coordinate(12, 21);
coords.Add(coord);
coord = new Coordinate(11, 21);
coords.Add(coord);
coord = new Coordinate(10, 21);
coords.Add(coord);
coord = new Coordinate(9, 20);
coords.Add(coord);
coord = new Coordinate(8, 19);
coords.Add(coord);
coord = new Coordinate(7, 18);
coords.Add(coord);
coord = new Coordinate(7, 17);
coords.Add(coord);
coord = new Coordinate(7, 16);
coords.Add(coord);
coord = new Coordinate(8, 15);
coords.Add(coord);
coord = new Coordinate(9, 14);
coords.Add(coord);
coord = new Coordinate(10, 13);
coords.Add(coord);
LinearRing exterior = gf.CreateLinearRing(coords);
coords = new Coordinates();
coord = new Coordinate(10, 16);
coords.Add(coord);
coord = new Coordinate(11, 17);
coords.Add(coord);
coord = new Coordinate(10, 18);
coords.Add(coord);
coord = new Coordinate(9, 17);
coords.Add(coord);
coord = new Coordinate(10, 16);
coords.Add(coord);
LinearRing interior = gf.CreateLinearRing(coords);
LinearRing[] linearRings = new LinearRing[1];
linearRings[0] = interior;
polygons[0] = gf.CreatePolygon(exterior, linearRings);
coords = new Coordinates();
coord = new Coordinate(5, 1);
coords.Add(coord);
coord = new Coordinate(6, 2);
coords.Add(coord);
coord = new Coordinate(7, 3);
coords.Add(coord);
coord = new Coordinate(6, 4);
coords.Add(coord);
coord = new Coordinate(5, 5);
coords.Add(coord);
coord = new Coordinate(4, 4);
coords.Add(coord);
coord = new Coordinate(3, 3);
coords.Add(coord);
coord = new Coordinate(4, 2);
coords.Add(coord);
coord = new Coordinate(5, 1);
coords.Add(coord);
exterior = gf.CreateLinearRing(coords);
polygons[1] = gf.CreatePolygon(exterior);
return gf.CreateMultiPolygon(polygons);
}