geometry.cs
来自「Sharp Map 用于制作GIS系统S harp Map 用于制作GIS系统S」· CS 代码 · 共 135 行
CS
135 行
// Copyright 2005, 2006 - Morten Nielsen (www.iter.dk)
//
// This file is part of SharpMap.
// SharpMap is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// SharpMap is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
// You should have received a copy of the GNU Lesser General Public License
// along with SharpMap; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
namespace SharpMap.Geometries
{
/// <summary>
/// <see cref="Geometry"/> is the root class of the Geometry Object Model hierarchy.
/// <see cref="Geometry"/> is an abstract (non-instantiable) class.
/// </summary>
/// <remarks>
/// <para>The instantiable subclasses of <see cref="Geometry"/> defined in the specification are restricted to 0, 1 and twodimensional
/// geometric objects that exist in two-dimensional coordinate space (R^2).</para>
/// <para>All instantiable geometry classes described in this specification are defined so that valid instances of a
/// geometry class are topologically closed (i.e. all defined geometries include their boundary).</para>
/// </remarks>
[Serializable]
public abstract class Geometry : IGeometry, IEquatable<Geometry>
{
private SharpMap.CoordinateSystems.ICoordinateSystem _SpatialReference;
/// <summary>
/// Gets or sets the spatial reference system associated with the <see cref="Geometry"/>.
/// A <see cref="Geometry"/> may not have had a spatial reference system defined for
/// it, in which case *spatialRef will be NULL.
/// </summary>
public SharpMap.CoordinateSystems.ICoordinateSystem SpatialReference
{
get { return _SpatialReference; }
set { _SpatialReference = value; }
}
// The following are methods that should be implemented on a geometry object according to
// the OpenGIS Simple Features Specification
#region "Basic Methods on Geometry"
/// <summary>
/// The inherent dimension of this <see cref="Geometry"/> object, which must be less than or equal
/// to the coordinate dimension.
/// </summary>
/// <remarks>This specification is restricted to geometries in two-dimensional coordinate space.</remarks>
public abstract int Dimension { get; }
/// <summary>
/// The minimum bounding box for this <see cref="Geometry"/>, returned as a <see cref="Geometry"/>. The
/// polygon is defined by the corner points of the bounding box ((MINX, MINY), (MAXX, MINY), (MAXX,
/// MAXY), (MINX, MAXY), (MINX, MINY)).
/// </summary>
/// <remarks>The envelope is actually the <see cref="BoundingBox"/> converted into a polygon.</remarks>
/// <seealso cref="GetBoundingBox"/>
public Geometry Envelope()
{
BoundingBox box = this.GetBoundingBox();
Polygon envelope = new Polygon();
envelope.ExteriorRing.Vertices.Add(box.Min); //minx miny
envelope.ExteriorRing.Vertices.Add(new Point(box.Max.X, box.Min.Y)); //maxx minu
envelope.ExteriorRing.Vertices.Add(box.Max); //maxx maxy
envelope.ExteriorRing.Vertices.Add(new Point(box.Min.X, box.Max.Y)); //minx maxy
envelope.ExteriorRing.Vertices.Add(envelope.ExteriorRing.StartPoint); //close ring
return envelope;
}
/// <summary>
/// The minimum bounding box for this <see cref="Geometry"/>, returned as a <see cref="BoundingBox"/>.
/// </summary>
/// <returns></returns>
public abstract BoundingBox GetBoundingBox();
/// <summary>
/// Exports this <see cref="Geometry"/> to a specific well-known text representation of <see cref="Geometry"/>.
/// </summary>
public string AsText()
{
return SharpMap.Converters.WellKnownText.GeometryToWKT.Write(this);
}
/// <summary>
/// Exports this <see cref="Geometry"/> to a specific well-known binary representation of <see cref="Geometry"/>.
/// </summary>
public byte[] AsBinary()
{
return SharpMap.Converters.WellKnownBinary.GeometryToWKB.Write(this);
}
/// <summary>
/// Returns a WellKnownText representation of the <see cref="Geometry"/>
/// </summary>
/// <returns>Well-known text</returns>
public override string ToString()
{
return this.AsText();
}
/// <summary>
/// Creates a <see cref="Geometry"/> based on a WellKnownText string
/// </summary>
/// <param name="WKT">Well-known Text</param>
/// <returns></returns>
public static Geometry GeomFromText(string WKT)
{
return SharpMap.Converters.WellKnownText.GeometryFromWKT.Parse(WKT);
}
/// <summary>
/// Creates a <see cref="Geometry"/> based on a WellKnownBinary byte array
/// </summary>
/// <param name="WKB">Well-known Binary</param>
/// <returns></returns>
public static Geometry GeomFromWKB(byte[] WKB)
{
return SharpMap.Converters.WellKnownBinary.GeometryFromWKB.Parse(WKB);
}
/// <summary>
/// Returns 'true' if this <see cref="Geometry"/> is the empty geometry . If true, then this
/// <see cref="Geometry"/> represents the empty point set,
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?