13 namespace Deveel.Data.Spatial {
18 private static readonly IGeometryServices DefaultGeometryServices =
new NtsGeometryServices();
19 private static readonly IGeometryFactory DefaultGeometryFactory =
new GeometryFactory();
28 : this(geometry, false) {
30 throw new ArgumentNullException(
"geometry");
33 private IGeometry Geometry {
get; set; }
35 int IComparable.CompareTo(
object obj) {
37 throw new ArgumentException();
39 return CompareTo((SqlGeometry) obj);
42 int IComparable<ISqlObject>.CompareTo(
ISqlObject other) {
44 throw new ArgumentException();
46 return CompareTo((SqlGeometry)other);
50 return Geometry.CompareTo(other.
Geometry);
53 public bool IsNull {
get;
private set; }
60 return new SqlString(Geometry.GeometryType);
104 return IsComparableTo((SqlGeometry)other);
108 if (IsNull && (other == null || other.
IsNull))
110 if (!IsNull && (other != null && !other.
IsNull))
124 var result = Geometry.
Buffer(distance);
129 if (IsNull || (geometry == null || geometry.
IsNull))
132 var result = Geometry.Distance(geometry.
Geometry);
137 if (IsNull || (other == null || other.
IsNull))
140 return Geometry.Contains(other.
Geometry);;
147 var bytes = Geometry.AsBinary();
155 return ToWellKnownText().ToString();
162 var text = Geometry.AsText();
167 if (String.IsNullOrEmpty(text)) {
169 error =
new ArgumentNullException(
"text");
174 var reader =
new WKTReader(DefaultGeometryFactory);
177 using (var textReader =
new StringReader(text)) {
178 g = reader.Read(textReader);
184 }
catch (Exception ex) {
193 return TryParse(text, out geometry, out error);
199 if (!TryParse(text, out geometry, out error))
200 throw new FormatException(String.Format(
"Could not parse the input string '{0}' to a valid GEOMETRY.", text), error);
207 return TryParse(bytes, out geometry, out error);
213 error =
new ArgumentNullException(
"bytes");
220 var reader =
new WKBReader(DefaultGeometryServices);
221 using (var stream =
new MemoryStream(bytes)) {
222 g = reader.Read(stream);
228 }
catch (Exception ex) {
238 if (!TryParse(bytes, out geometry, out error))
239 throw new FormatException(
"Could not parse the input bytes to a valid GEOMETRY.", error);
bool IsComparableTo(SqlGeometry other)
static bool TryParse(string text, out SqlGeometry geometry)
static bool TryParse(string text, out SqlGeometry geometry, out Exception error)
Implements a BINARY object that handles a limited number of bytes, not exceding MaxLength.
SqlBoolean Contains(SqlGeometry other)
SqlGeometry Buffer(double distance)
SqlNumber Distance(SqlGeometry geometry)
static bool TryParse(byte[] bytes, out SqlGeometry geometry, out Exception error)
SqlBinary ToWellKnownBytes()
Defines the contract for a valid SQL Object
static SqlGeometry Parse(string text)
double IConvertible. ToDouble(IFormatProvider provider)
SqlGeometry(IGeometry geometry)
static readonly SqlNumber Null
static SqlGeometry Parse(byte[] bytes)
bool IsComparableTo(ISqlObject other)
Checks if the current object is comparable with the given one.
static bool TryParse(byte[] bytes, out SqlGeometry geometry)
SqlGeometry Buffer(SqlNumber distance)
SqlString ToWellKnownText()
override string ToString()
SqlGeometry(IGeometry geometry, bool isNull)
int CompareTo(SqlGeometry other)
Deveel.Data.Sql.Objects.SqlString SqlString
static readonly SqlBinary Null