本文整理汇总了C#中IGeometry.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IGeometry.GetType方法的具体用法?C# IGeometry.GetType怎么用?C# IGeometry.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IGeometry
的用法示例。
在下文中一共展示了IGeometry.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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(IGeometry geometry, System.IO.BinaryWriter file, IGeometryFactory geometryFactory)
{
if(!(geometry is IMultiPoint))
throw new ArgumentException("Geometry Type error: MultiPoint expected, but the type retrieved is " + geometry.GetType().Name);
// Slow and maybe not useful...
// if (!geometry.IsValid)
// Trace.WriteLine("Invalid multipoint being written.");
IMultiPoint mpoint = geometry as IMultiPoint;
file.Write(int.Parse(Enum.Format(typeof(ShapeGeometryTypes), this.ShapeType, "d")));
IEnvelope box = geometry.EnvelopeInternal;
IEnvelope bounds = ShapeHandler.GetEnvelopeExternal(geometryFactory.PrecisionModel, box);
file.Write(bounds.MinX);
file.Write(bounds.MinY);
file.Write(bounds.MaxX);
file.Write(bounds.MaxY);
int numPoints = mpoint.NumPoints;
file.Write(numPoints);
// write the points
for (int i = 0; i < numPoints; i++)
{
IPoint point = (IPoint) mpoint.Geometries[i];
file.Write(point.X);
file.Write(point.Y);
}
}
示例2: IsSameStructure
public static bool IsSameStructure(IGeometry g1, IGeometry g2)
{
if (g1.GetType() != g2.GetType())
return false;
if (g1 is GeometryCollection)
return IsSameStructureCollection((GeometryCollection)g1, (GeometryCollection)g2);
if (g1 is Polygon)
return IsSameStructurePolygon((Polygon)g1, (Polygon)g2);
if (g1 is LineString)
return IsSameStructureLineString((LineString)g1, (LineString)g2);
if (g1 is Point)
return IsSameStructurePoint((Point)g1, (Point)g2);
NetTopologySuite.Utilities.Assert.ShouldNeverReachHere("Unsupported Geometry class: " + g1.GetType().FullName);
return false;
}
示例3: NtsGeometry
public NtsGeometry(IGeometry geom, NtsSpatialContext ctx, bool dateline180Check)
{
this.ctx = ctx;
//GeometryCollection isn't supported in relate()
if (geom.GetType() == typeof(GeometryCollection))
throw new ArgumentException("NtsGeometry does not support GeometryCollection but does support its subclasses.");
//NOTE: All this logic is fairly expensive. There are some short-circuit checks though.
if (ctx.IsGeo())
{
//Unwraps the geometry across the dateline so it exceeds the standard geo bounds (-180 to +180).
if (dateline180Check)
UnwrapDateline(geom); //potentially modifies geom
//If given multiple overlapping polygons, fix it by union
geom = UnionGeometryCollection(geom); //returns same or new geom
Envelope unwrappedEnv = geom.EnvelopeInternal;
//Cuts an unwrapped geometry back into overlaid pages in the standard geo bounds.
geom = CutUnwrappedGeomInto360(geom); //returns same or new geom
Debug.Assert(geom.EnvelopeInternal.Width <= 360);
Debug.Assert(geom.GetType() != typeof (GeometryCollection)); //double check
//note: this bbox may be sub-optimal. If geom is a collection of things near the dateline on both sides then
// the bbox will needlessly span most or all of the globe longitudinally.
// TODO so consider using MultiShape's planned minimal geo bounding box algorithm once implemented.
double envWidth = unwrappedEnv.Width;
//adjust minX and maxX considering the dateline and world wrap
double minX, maxX;
if (envWidth >= 360)
{
minX = -180;
maxX = 180;
}
else
{
minX = unwrappedEnv.MinX;
maxX = DistanceUtils.NormLonDEG(unwrappedEnv.MinX + envWidth);
}
bbox = new RectangleImpl(minX, maxX, unwrappedEnv.MinY, unwrappedEnv.MaxY, ctx);
}
else
{//not geo
Envelope env = geom.EnvelopeInternal;
bbox = new RectangleImpl(env.MinX, env.MaxX, env.MinY, env.MaxY, ctx);
}
var _ = geom.EnvelopeInternal;//ensure envelope is cached internally, which is lazy evaluated. Keeps this thread-safe.
//Check geom validity; use helpful error
// TODO add way to conditionally skip at your peril later
var isValidOp = new IsValidOp(geom);
if (!isValidOp.IsValid)
throw new InvalidShapeException(isValidOp.ValidationError.ToString());
this.geom = geom;
this._hasArea = !((geom is ILineal) || (geom is IPuntal));
}
示例4: GetEndVector
public static Vector2 GetEndVector(IGeometry g) {
Vector2 v;
if (g is LineSegment2) {
v = (g as LineSegment2).ToVector();
} else if (g is Arc) {
v = (g as Arc).EndVector;
} else
throw new NotSupportedException("Can't get End-Vector from IGeometryBase: " + g.GetType().ToString());
return v;
}
示例5: HasRepeatedPoint
/// <summary>
///
/// </summary>
/// <param name="g"></param>
/// <returns></returns>
protected virtual bool HasRepeatedPoint(IGeometry g)
{
if (g.IsEmpty) return false;
if (g is Point) return false;
if (g is MultiPoint) return false;
// LineString also handles LinearRings
if (g is LineString)
return HasRepeatedPoint(g.Coordinates);
if (g is Polygon)
return HasRepeatedPoint((IPolygon) g);
if (g is GeometryCollection)
return HasRepeatedPoint((IGeometryCollection) g);
throw new NotSupportedException(g.GetType().FullName);
}
示例6: HasRepeatedPoint
/// <summary>
///
/// </summary>
/// <param name="g"></param>
/// <returns></returns>
public bool HasRepeatedPoint(IGeometry g)
{
if (g.IsEmpty) return false;
if (g is IPoint) return false;
else if (g is IMultiPoint) return false;
// LineString also handles LinearRings
else if (g is ILineString)
return HasRepeatedPoint(((ILineString) g).Coordinates);
else if (g is IPolygon)
return HasRepeatedPoint((IPolygon) g);
else if (g is IGeometryCollection)
return HasRepeatedPoint((IGeometryCollection) g);
else throw new NotSupportedException(g.GetType().FullName);
}
示例7: TransformGeometry
/// <summary>
/// Transforms a <see cref="Geometry" /> object.
/// </summary>
/// <param name="g"></param>
/// <param name="transform"></param>
/// <returns></returns>
public static IGeometry TransformGeometry(IGeometry g, IMathTransform transform)
{
if (g == null) return null;
else if (g is IPoint)
return TransformPoint(g as IPoint, transform);
else if (g is ILineString)
return TransformLineString(g as ILineString, transform);
else if (g is IPolygon)
return TransformPolygon(g as IPolygon, transform);
else if (g is IMultiPoint)
return TransformMultiPoint(g as IMultiPoint, transform);
else if (g is IMultiLineString)
return TransformMultiLineString(g as IMultiLineString, transform);
else if (g is IMultiPolygon)
return TransformMultiPolygon(g as IMultiPolygon, transform);
else throw new ArgumentException("Could not transform geometry type '" + g.GetType().ToString() +"'");
}
示例8: Project
public IGeometry Project(IGeometry geography)
{
#region Preconditions
if (geography == null) throw new ArgumentNullException("geography");
#endregion
if (geography is Point)
{
return Project((Point)geography);
}
if (geography is GeometryGroup)
{
var group = (GeometryGroup)geography;
var geos = new IGeometry[group.Count];
for (int i = 0; i < group.Count; i++)
{
geos[i] = Project(group[i]);
}
return new GeometryGroup(geos);
}
else if (geography is Polygon)
{
var polygon = (Polygon)geography;
var points = new Point[polygon.Points.Length];
for (int i = 0; i < polygon.Points.Length; i++)
{
points[i] = Project(polygon.Points[i]);
}
return new Polygon(points);
}
else
{
throw new Exception("Unexpected geography type: " + geography.GetType().Name);
}
}
示例9: Apply
public IGeometry Apply(IGeometry geom)
{
if (geom == null)
return null;
if (geom is IPoint)
return Apply(geom as IPoint);
if (geom is ILineString)
return Apply(geom as ILineString);
if (geom is IPolygon)
return Apply(geom as IPolygon);
if (geom is IMultiPoint)
return Apply(geom as IMultiPoint);
if (geom is IMultiLineString)
return Apply(geom as IMultiLineString);
if (geom is IMultiPolygon)
return Apply(geom as IMultiPolygon);
throw new ArgumentException(string.Format("Could not transform geometry type '{0}'", geom.GetType()));
}
示例10: GeometryToSqlGeometry
private static void GeometryToSqlGeometry(IGeometry geom, SqlGeometryBuilder bldr)
{
if (geom is IPoint)
GeometryToSqlGeometry(geom as IPoint, bldr);
else if (geom is IMultiPoint)
GeometryToSqlGeometry(geom as IMultiPoint, bldr);
else if (geom is ILineString)
GeometryToSqlGeometry(geom as ILineString, bldr);
else if (geom is IMultiLineString)
GeometryToSqlGeometry(geom as IMultiLineString, bldr);
else if (geom is IPolygon)
GeometryToSqlGeometry(geom as IPolygon, bldr);
else if (geom is IMultiPolygon)
GeometryToSqlGeometry(geom as IMultiPolygon, bldr);
else if (geom is IGeometryCollection)
GeometryToSqlGeometry(geom as IGeometryCollection, bldr);
else
throw new Exception(String.Format("Unable to convert geometry of type '{0}'", geom.GetType().Name));
}
示例11: TransformGeometry
/// <summary>
/// Transforms a <see cref="GeoAPI.Geometries.IGeometry"/>.
/// </summary>
/// <param name="g">Geometry to transform</param>
/// <param name="transform">MathTransform</param>
/// <param name="targetFactory">The factory to create the target geometry</param>
/// <returns>Transformed Geometry</returns>
public static IGeometry TransformGeometry(IGeometry g, IMathTransform transform, IGeometryFactory targetFactory)
{
if (g == null)
return null;
if (g is IPoint)
return TransformPoint(g as IPoint, transform, targetFactory);
if (g is ILineString)
return TransformLineString(g as ILineString, transform, targetFactory);
if (g is IPolygon)
return TransformPolygon(g as IPolygon, transform, targetFactory);
if (g is IMultiPoint)
return TransformMultiPoint(g as IMultiPoint, transform, targetFactory);
if (g is IMultiLineString)
return TransformMultiLineString(g as IMultiLineString, transform, targetFactory);
if (g is IMultiPolygon)
return TransformMultiPolygon(g as IMultiPolygon, transform, targetFactory);
if (g is IGeometryCollection)
return TransformGeometryCollection(g as IGeometryCollection, transform, targetFactory);
throw new ArgumentException("Could not transform geometry type '" + g.GetType() + "'");
}
示例12: Add
/// <summary>
///
/// </summary>
/// <param name="g"></param>
private void Add(IGeometry g)
{
if (g.IsEmpty) return;
if (g is IPolygon)
AddPolygon((IPolygon) g);
// LineString also handles LinearRings
else if (g is ILineString)
AddLineString(g);
else if (g is IPoint)
AddPoint(g);
else if (g is IMultiPoint)
AddCollection(g);
else if (g is IMultiLineString)
AddCollection(g);
else if (g is IMultiPolygon)
AddCollection(g);
else if (g is IGeometryCollection)
AddCollection(g);
else throw new NotSupportedException(g.GetType().FullName);
}
示例13: TransformGeometry
/// <summary>
/// Transforms a <see cref="GeoAPI.Geometries.IGeometry"/>.
/// </summary>
/// <param name="g">Geometry to transform</param>
/// <param name="from">Source Projection</param>
/// <param name="to">Target Projection</param>
/// <param name="toFactory">The factory to create the transformed geometry</param>
/// <returns>Transformed Geometry</returns>
public static IGeometry TransformGeometry(IGeometry g, ProjectionInfo from, ProjectionInfo to, IGeometryFactory toFactory)
{
if (g == null)
return null;
if (g is IPoint)
return TransformPoint(g as IPoint, from, to, toFactory);
if (g is ILineString)
return TransformLineString(g as ILineString, from, to, toFactory);
if (g is IPolygon)
return TransformPolygon(g as IPolygon, from, to, toFactory);
if (g is IMultiPoint)
return TransformMultiPoint(g as IMultiPoint, from, to, toFactory);
if (g is IMultiLineString)
return TransformMultiLineString(g as IMultiLineString, from, to, toFactory);
if (g is IMultiPolygon)
return TransformMultiPolygon(g as IMultiPolygon, from, to, toFactory);
if (g is IGeometryCollection)
return TransformGeometryCollection(g as IGeometryCollection, from, to, toFactory);
throw new ArgumentException("Could not transform geometry type '" + g.GetType() + "'");
}
示例14: TransformGeometry
/// <summary>
/// Transforms a <see cref="Geometry" /> object.
/// </summary>
/// <param name="factory"></param>
/// <param name="g"></param>
/// <param name="transform"></param>
/// <returns></returns>
public static IGeometry TransformGeometry(IGeometryFactory factory,
IGeometry g, IMathTransform transform)
{
if (g == null)
return null;
if (g is IPoint)
return TransformPoint(factory, g as IPoint, transform);
if (g is ILineString)
return TransformLineString(factory, g as ILineString, transform);
if (g is IPolygon)
return TransformPolygon(factory, g as IPolygon, transform);
if (g is IMultiPoint)
return TransformMultiPoint(factory, g as IMultiPoint, transform);
if (g is IMultiLineString)
return TransformMultiLineString(factory, g as IMultiLineString, transform);
if (g is IMultiPolygon)
return TransformMultiPolygon(factory, g as IMultiPolygon, transform);
if (g is IGeometryCollection)
return TransformGeometryCollection(factory, g as IGeometryCollection, transform);
throw new ArgumentException(String.Format(
"Could not transform geometry type '{0}'", g.GetType()));
}
示例15: Write
/// <summary>
/// Writes a Geometry to the given binary wirter.
/// </summary>
/// <param name="geometry">The geometry to write.</param>
/// <param name="writer">The writer to use.</param>
/// <param name="geometryFactory">The geometry factory to use.</param>
public override void Write(IGeometry geometry, BinaryWriter writer, IGeometryFactory geometryFactory)
{
var mpoint = geometry as IMultiPoint;
if (mpoint == null)
throw new ArgumentException("Geometry Type error: MultiPoint expected, but the type retrieved is " + geometry.GetType().Name);
// Slow and maybe not useful...
// if (!geometry.IsValid)
// Trace.WriteLine("Invalid multipoint being written.");
writer.Write((int)ShapeType);
WriteEnvelope(writer, geometryFactory.PrecisionModel, geometry.EnvelopeInternal);
var numPoints = mpoint.NumPoints;
writer.Write(numPoints);
var hasZ = HasZValue();
var zList = hasZ ? new List<double>() : null;
var hasM = HasMValue();
var mList = hasM ? new List<double>() : null;
// write the points
for (var i = 0; i < numPoints; i++)
{
var point = (IPoint) mpoint.Geometries[i];
writer.Write(point.X);
writer.Write(point.Y);
if (hasZ) zList.Add(point.Z);
if (hasM) mList.Add(point.M);
}
WriteZM(writer, numPoints, zList, mList);
}