本文整理汇总了C#中IGeometryFactory.CreateMultiLineString方法的典型用法代码示例。如果您正苦于以下问题:C# IGeometryFactory.CreateMultiLineString方法的具体用法?C# IGeometryFactory.CreateMultiLineString怎么用?C# IGeometryFactory.CreateMultiLineString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGeometryFactory
的用法示例。
在下文中一共展示了IGeometryFactory.CreateMultiLineString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Read
/// <summary>
/// Reads a stream and converts the shapefile record to an equilivent geometry object.
/// </summary>
/// <param name="file">The stream to read.</param>
/// <param name="geometryFactory">The geometry factory to use when making the object.</param>
/// <returns>The Geometry object that represents the shape file record.</returns>
public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory)
{
int shapeTypeNum = file.ReadInt32();
type = (ShapeGeometryType) Enum.Parse(typeof(ShapeGeometryType), shapeTypeNum.ToString());
if (type == ShapeGeometryType.NullShape)
return geometryFactory.CreateMultiLineString(null);
if (!(type == ShapeGeometryType.LineString || type == ShapeGeometryType.LineStringM ||
type == ShapeGeometryType.LineStringZ || type == ShapeGeometryType.LineStringZM))
throw new ShapefileException("Attempting to load a non-arc as arc.");
// Read and for now ignore bounds.
int bblength = GetBoundingBoxLength();
bbox = new double[bblength];
for (; bbindex < 4; bbindex++)
{
double d = file.ReadDouble();
bbox[bbindex] = d;
}
int numParts = file.ReadInt32();
int numPoints = file.ReadInt32();
int[] partOffsets = new int[numParts];
for (int i = 0; i < numParts; i++)
partOffsets[i] = file.ReadInt32();
ILineString[] lines = new ILineString[numParts];
for (int part = 0; part < numParts; part++)
{
int start, finish, length;
start = partOffsets[part];
if (part == numParts - 1)
finish = numPoints;
else finish = partOffsets[part + 1];
length = finish - start;
CoordinateList points = new CoordinateList();
points.Capacity = length;
for (int i = 0; i < length; i++)
{
double x = file.ReadDouble();
double y = file.ReadDouble();
ICoordinate external = new Coordinate(x, y);
geometryFactory.PrecisionModel.MakePrecise(external);
points.Add(external);
}
ILineString line = geometryFactory.CreateLineString(points.ToArray());
lines[part] = line;
}
geom = geometryFactory.CreateMultiLineString(lines);
GrabZMValues(file);
return geom;
}
示例2: ToGeometry
/// <summary>
/// Converts a collection of <see cref="ISegmentString"/>s into a <see cref="IGeometry"/>.
/// The geometry will be either a <see cref="ILineString"/>
/// or a <see cref="IMultiLineString"/> (possibly empty).
/// </summary>
/// <param name="segStrings">A collection of <see cref="ISegmentString"/>.</param>
/// <param name="geomFact">A geometry factory</param>
/// <returns>A <see cref="ILineString"/> or a <see cref="IMultiLineString"/>.</returns>
public static IGeometry ToGeometry(IList<ISegmentString> segStrings, IGeometryFactory geomFact)
{
ILineString[] lines = new ILineString[segStrings.Count];
int index = 0;
foreach (ISegmentString ss in segStrings)
{
ILineString line = geomFact.CreateLineString(ss.Coordinates);
lines[index++] = line;
}
if (lines.Length == 1)
return lines[0];
return geomFact.CreateMultiLineString(lines);
}
示例3: Read
/// <summary>
/// Reads a stream and converts the shapefile record to an equilivent geometry object.
/// </summary>
/// <param name="file">The stream to read.</param>
/// <param name="geometryFactory">The geometry factory to use when making the object.</param>
/// <returns>The Geometry object that represents the shape file record.</returns>
public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory)
{
int shapeTypeNum = file.ReadInt32();
ShapeGeometryTypes shapeType = (ShapeGeometryTypes)Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString());
if( ! ( shapeType == ShapeGeometryTypes.LineString || shapeType == ShapeGeometryTypes.LineStringM ||
shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM ))
throw new ShapefileException("Attempting to load a non-arc as arc.");
//read and for now ignore bounds.
double[] box = new double[4];
for (int i = 0; i < 4; i++)
{
double d= file.ReadDouble();
box[i] =d;
}
int numParts = file.ReadInt32();
int numPoints = file.ReadInt32();
int[] partOffsets = new int[numParts];
for (int i = 0; i < numParts; i++)
partOffsets[i] = file.ReadInt32();
ILineString[] lines = new ILineString[numParts];
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;
CoordinateList points = new CoordinateList();
points.Capacity=length;
ICoordinate external;
for (int i = 0; i < length; i++)
{
external = new Coordinate(file.ReadDouble(),file.ReadDouble());
geometryFactory.PrecisionModel.MakePrecise( external);
points.Add(external);
}
lines[part] = geometryFactory.CreateLineString(points.ToArray());
}
return geometryFactory.CreateMultiLineString(lines);
}
示例4: FromLine
/// <summary>
/// Gets the line for the specified index
/// </summary>
/// <returns>A LineString or MultiLineString geometry created from this shape.</returns>
protected IGeometry FromLine(IGeometryFactory factory)
{
if (factory == null) factory = Geometry.DefaultFactory;
List<IBasicLineString> lines = new List<IBasicLineString>();
foreach (PartRange part in _shapeRange.Parts)
{
int i = part.StartIndex;
List<Coordinate> coords = new List<Coordinate>();
foreach (Vertex d in part)
{
Coordinate c = new Coordinate(d.X, d.Y);
coords.Add(c);
if (M != null && M.Length > 0) c.M = M[i];
if (Z != null && Z.Length > 0) c.Z = Z[i];
i++;
}
lines.Add(factory.CreateLineString(coords));
}
if (lines.Count == 1) return (IGeometry)lines[0];
return factory.CreateMultiLineString(lines.ToArray());
}
示例5: Parse
/// <summary>
/// See http://www.gaia-gis.it/gaia-sins/BLOB-Geometry.html
/// for the specification of the spatialite BLOB geometry format
/// Derived from WKB, but unfortunately it is not practical to reuse existing
/// WKB encoding/decoding code
/// </summary>
/// <param name="spatialliteGeom">The geometry blob</param>
/// <param name="factory">The factory to create the result geometry</param>
/// <returns>A geometry</returns>
public static IGeometry Parse(byte[] spatialliteGeom, IGeometryFactory factory)
{
var nBytes = spatialliteGeom.Length;
if (spatialliteGeom.Length < 44
|| spatialliteGeom[0] != 0
|| spatialliteGeom[38] != 0x7C
|| spatialliteGeom[nBytes - 1] != 0xFE)
throw new ApplicationException("Corrupt SpatialLite geom");
bool isLittleEndian = spatialliteGeom[1] == 0x01;
if (spatialliteGeom[1] != 0x00 && spatialliteGeom[1] != 0x01)
throw new ApplicationException("Corrupt SpatialLite geom");
int idx = 39;
int nGType = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
if (nGType < 1 || nGType > 7)
throw new ApplicationException("Unsupported geom type!");
/* -------------------------------------------------------------------- */
/* Point */
/* -------------------------------------------------------------------- */
if (nGType == 1)
{
return factory.CreatePoint(ReadPoint(spatialliteGeom, ref idx, isLittleEndian));
}
/* -------------------------------------------------------------------- */
/* LineString */
/* -------------------------------------------------------------------- */
else if (nGType == 2)
{
return ReadLineString(spatialliteGeom, ref idx, isLittleEndian, factory);
}
/* -------------------------------------------------------------------- */
/* Polygon */
/* -------------------------------------------------------------------- */
else if (nGType == 3)
{
return ReadPolygon(spatialliteGeom, ref idx, isLittleEndian, factory);
}
/* -------------------------------------------------------------------- */
/* MultiPoint */
/* -------------------------------------------------------------------- */
else if (nGType == 4)
{
List<GeoAPI.Geometries.IPoint> pts = new List<GeoAPI.Geometries.IPoint>();
int numGeoms = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
for (int i = 0; i < numGeoms; i++)
{
if (spatialliteGeom[idx] != 0x69)
throw new ApplicationException("FormatError in SpatiaLIteGeom");
idx++;
int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
if (gt != 1)
throw new ApplicationException("MultiPoint must Contain Point entities");
pts.Add(factory.CreatePoint(ReadPoint(spatialliteGeom, ref idx, isLittleEndian)));
}
return factory.CreateMultiPoint(pts.ToArray());
}
/* -------------------------------------------------------------------- */
/* MultiLineString */
/* -------------------------------------------------------------------- */
else if (nGType == 5)
{
List<GeoAPI.Geometries.ILineString> lss = new List<GeoAPI.Geometries.ILineString>();
int numGeoms = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
for (int i = 0; i < numGeoms; i++)
{
if (spatialliteGeom[idx] != 0x69)
throw new ApplicationException("FormatError in SpatiaLIteGeom");
idx++;
int gt = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
if (gt != 2)
throw new ApplicationException("MultiLineString must contain LineString Entities");
lss.Add(ReadLineString(spatialliteGeom, ref idx, isLittleEndian, factory));
}
return factory.CreateMultiLineString(lss.ToArray());
}
/* -------------------------------------------------------------------- */
/* MultiPolygon */
/* -------------------------------------------------------------------- */
else if (nGType == 6)
{
List<GeoAPI.Geometries.IPolygon> polys = new List<GeoAPI.Geometries.IPolygon>();
int numPolys = ReadUInt32(spatialliteGeom, ref idx, isLittleEndian);
for (int i = 0; i < numPolys; i++)
{
if (spatialliteGeom[idx] != 0x69)
throw new ApplicationException("FormatError in SpatiaLIteGeom");
idx++;
//.........这里部分代码省略.........
示例6: Read
//.........这里部分代码省略.........
public override IGeometry Read(BigEndianBinaryReader file, IGeometryFactory geometryFactory)
{
int shapeTypeNum = file.ReadInt32();
ShapeGeometryTypes shapeType = (ShapeGeometryTypes)Enum.Parse(typeof(ShapeGeometryTypes), shapeTypeNum.ToString());
if (shapeType == ShapeGeometryTypes.NullShape)
return null;
if( ! ( shapeType == ShapeGeometryTypes.LineString || shapeType == ShapeGeometryTypes.LineStringM ||
shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM ))
throw new ShapefileException("Attempting to load a non-arc as arc.");
//read and for now ignore bounds.
double[] box = new double[4];
for (int i = 0; i < 4; i++)
{
double d= file.ReadDouble();
box[i] =d;
}
int numParts = file.ReadInt32();
int numPoints = file.ReadInt32();
int[] partOffsets = new int[numParts];
for (int i = 0; i < numParts; i++)
partOffsets[i] = file.ReadInt32();
ILineString[] lines = new ILineString[numParts];
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;
CoordinateList points = new CoordinateList();
points.Capacity=length;
ICoordinate external;
for (int i = 0; i < length; i++)
{
external = new Coordinate(file.ReadDouble(),file.ReadDouble());
geometryFactory.PrecisionModel.MakePrecise( external);
points.Add(external);
}
if (numPoints < 2)
lines[part] = geometryFactory.CreateLineString(null as Topology.Geometries.ICoordinate[]);
else
lines[part] = geometryFactory.CreateLineString(points.ToArray());
}
//If we have Z-coordinates, read them..
if (shapeType == ShapeGeometryTypes.LineStringZ || shapeType == ShapeGeometryTypes.LineStringZM)
{
//z-Bounds
double zMin = file.ReadDouble();
double zMax = file.ReadDouble();
for (int part = 0; part < numParts; part++)
{
start = partOffsets[part];
if (part == numParts - 1)
finish = numPoints;
else finish = partOffsets[part + 1];
length = finish - start;
for (int i = 0; i < length; i++)
{
double val = file.ReadDouble();
if (numPoints > 1)
{
lines[part].Coordinates[i].Z = val;
}
}
}
}
//If we have M-coordinates, read them..
if (shapeType == ShapeGeometryTypes.LineStringM || shapeType == ShapeGeometryTypes.LineStringZM)
{
//m-Bounds
double mMin = file.ReadDouble();
double mMax = file.ReadDouble();
for (int part = 0; part < numParts; part++)
{
start = partOffsets[part];
if (part == numParts - 1)
finish = numPoints;
else finish = partOffsets[part + 1];
length = finish - start;
for (int i = 0; i < length; i++)
{
double val = file.ReadDouble();
//dont store..
}
}
}
return geometryFactory.CreateMultiLineString(lines);
}
示例7: FromLine
/// <summary>
/// Gets the line for the specified index
/// </summary>
/// <returns>A LineString or MultiLineString geometry created from this shape.</returns>
protected IGeometry FromLine(IGeometryFactory factory)
{
if (factory == null) factory = Geometry.DefaultFactory;
var lines = new List<IBasicLineString>();
foreach (var part in _shapeRange.Parts)
{
var coords = GetCoordinates(part);
lines.Add(factory.CreateLineString(coords));
}
if (lines.Count == 1) return (IGeometry)lines[0];
return factory.CreateMultiLineString(lines.ToArray());
}
示例8: GetEdges
/// <summary>
/// Gets the geometry for the edges in the subdivision as a <see cref="IMultiLineString"/>
/// containing 2-point lines.
/// </summary>
/// <param name="geomFact">the GeometryFactory to use</param>
/// <returns>a IMultiLineString</returns>
public IMultiLineString GetEdges(IGeometryFactory geomFact)
{
var quadEdges = GetPrimaryEdges(false);
ILineString[] edges = new LineString[quadEdges.Count];
int i = 0;
foreach (var qe in quadEdges)
{
edges[i++] = geomFact.CreateLineString(new[] {
qe.Orig.Coordinate, qe.Dest.Coordinate });
}
return geomFact.CreateMultiLineString(edges);
}
示例9: RandomLinealZ
private static ILineal RandomLinealZ(IGeometryFactory geometryFactory)
{
switch (Random.Next(0, 2))
{
case 0:
return geometryFactory.CreateLineString(RandomCoordinatesZ(geometryFactory, 2, 10));
case 1:
var ls = new ILineString[Random.Next(2, 5)];
for (int i = 0; i < ls.Length; i++)
ls[i] = geometryFactory.CreateLineString(RandomCoordinatesZ(geometryFactory, 2, 15));
return geometryFactory.CreateMultiLineString(ls);
}
return geometryFactory.CreateLineString(RandomCoordinatesZ(geometryFactory, 2, 10));
}
示例10: ReadMultiLineStringText
/// <summary>
/// Creates a <c>MultiLineString</c> using the next token in the stream.
/// </summary>
/// <param name="tokens">
/// Tokenizer over a stream of text in Well-known Text
/// format. The next tokens must form a MultiLineString Text.
/// </param>
/// <param name="factory"> </param>
/// <returns>
/// A <c>MultiLineString</c> specified by the
/// next token in the stream.</returns>
private IMultiLineString ReadMultiLineStringText(IEnumerator<Token> tokens, IGeometryFactory factory)
{
string nextToken = GetNextEmptyOrOpener(tokens);
if (nextToken.Equals("EMPTY"))
return factory.CreateMultiLineString( new ILineString[] { } );
var lineStrings = new List<ILineString>();
var lineString = ReadLineStringText(tokens, factory);
lineStrings.Add(lineString);
nextToken = GetNextCloserOrComma(tokens);
while (nextToken.Equals(",")) {
lineString = ReadLineStringText(tokens, factory);
lineStrings.Add(lineString);
nextToken = GetNextCloserOrComma(tokens);
}
return factory.CreateMultiLineString(lineStrings.ToArray());
}
示例11: TransformMultiLineString
/// <summary>
/// Transforms a <see cref="GeoAPI.Geometries.IMultiLineString"/>.
/// </summary>
/// <param name="lines">MultiLineString to transform</param>
/// <param name="transform">MathTransform</param>
/// <param name="targetFactory">The factory to create the target geometry</param>
/// <returns>Transformed MultiLineString</returns>
public static IMultiLineString TransformMultiLineString(IMultiLineString lines, IMathTransform transform, IGeometryFactory targetFactory)
{
var lineList = new ILineString[lines.NumGeometries];
for (var i = 0; i < lines.NumGeometries; i++)
{
var line = (ILineString)lines[i];
lineList[i] = TransformLineString(line, transform, targetFactory);
}
return targetFactory.CreateMultiLineString(lineList);
}
示例12: TransformMultiLineString
/// <summary>
/// Transforms a <see cref="MultiLineString" /> object.
/// </summary>
/// <param name="factory"></param>
/// <param name="lines"></param>
/// <param name="transform"></param>
/// <returns></returns>
public static IMultiLineString TransformMultiLineString(IGeometryFactory factory,
IMultiLineString lines, IMathTransform transform)
{
List<ILineString> strings = new List<ILineString>(lines.Geometries.Length);
foreach (ILineString ls in lines.Geometries)
{
ILineString item = TransformLineString(factory, ls, transform);
strings.Add(item);
}
return factory.CreateMultiLineString(strings.ToArray());
}
示例13: CreateWKBMultiLineString
private static IMultiLineString CreateWKBMultiLineString(BinaryReader reader, WkbByteOrder byteOrder, IGeometryFactory factory)
{
// Get the number of linestrings in this multilinestring.
var numLineStrings = (int) ReadUInt32(reader, byteOrder);
// Create a new array for the linestrings .
var lines = new ILineString[numLineStrings];
// Loop on the number of linestrings.
for (var i = 0; i < numLineStrings; i++)
{
// Read linestring header
reader.ReadByte();
ReadUInt32(reader, byteOrder);
// Create the next linestring and add it to the array.
lines[i] = CreateWKBLineString(reader, byteOrder, factory);
}
// Create and return the MultiLineString.
return factory.CreateMultiLineString(lines);
}
示例14: ToNTSMultiLineString
internal static NTSMultiLineString ToNTSMultiLineString(Geometries.MultiLineString geom,
IGeometryFactory factory)
{
NTSLineString[] lstrings = new NTSLineString[geom.LineStrings.Count];
int index = 0;
foreach (Geometries.LineString lstring in geom.LineStrings)
lstrings[index++] = ToNTSLineString(lstring, factory);
return factory.CreateMultiLineString(lstrings) as NTSMultiLineString;
}
示例15: Write
/// <summary>
/// Writes to the given stream the equilivent shape file record given a Geometry object.
/// </summary>
/// <param name="geometry">The geometry object to write.</param>
/// <param name="file">The stream to write to.</param>
/// <param name="geometryFactory">The geometry factory to use.</param>
public override void Write(IGeometry geometry, BinaryWriter file, IGeometryFactory geometryFactory)
{
// Force to use a MultiGeometry
IMultiLineString multi;
if (geometry is IGeometryCollection)
multi = (IMultiLineString) geometry;
else multi = geometryFactory.CreateMultiLineString(new ILineString[] { (ILineString) geometry });
file.Write(int.Parse(Enum.Format(typeof(ShapeGeometryType), ShapeType, "d")));
IEnvelope box = multi.EnvelopeInternal;
file.Write(box.MinX);
file.Write(box.MinY);
file.Write(box.MaxX);
file.Write(box.MaxY);
int numParts = multi.NumGeometries;
int numPoints = multi.NumPoints;
file.Write(numParts);
file.Write(numPoints);
// Write the offsets
int offset=0;
for (int i = 0; i < numParts; i++)
{
IGeometry g = multi.GetGeometryN(i);
file.Write( offset );
offset = offset + g.NumPoints;
}
for (int part = 0; part < numParts; part++)
{
CoordinateList points = new CoordinateList(multi.GetGeometryN(part).Coordinates);
for (int i = 0; i < points.Count; i++)
{
ICoordinate external = points[i];
file.Write(external.X);
file.Write(external.Y);
}
}
}