[pgsqlclient-checkins] SF.net SVN: pgsqlclient: [166] trunk/PostgreSqlClient/source/PostgreSql/Data/
Status: Inactive
Brought to you by:
carlosga_fb
From: <car...@us...> - 2006-05-31 18:36:10
|
Revision: 166 Author: carlosga_fb Date: 2006-05-31 11:35:53 -0700 (Wed, 31 May 2006) ViewCVS: http://svn.sourceforge.net/pgsqlclient/?rev=166&view=rev Log Message: ----------- 2006-05-31 Carlos Guzman Alvarez (car...@gm...) - Committed initial support for fetching PostGIS Box2D values. Modified Paths: -------------- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint.cs Added Paths: ----------- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox2D.cs trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint2D.cs Added: trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox2D.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox2D.cs (rev 0) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgBox2D.cs 2006-05-31 18:35:53 UTC (rev 166) @@ -0,0 +1,128 @@ +using System; +using PostgreSql.Data.Protocol; + +namespace PostgreSql.Data.PgTypes +{ + [Serializable] + public struct PgBox2D + { + #region \xB7 Fields \xB7 + + private PgPoint2D upperRight; + private PgPoint2D lowerLeft; + + #endregion + + #region \xB7 Properties \xB7 + + public PgPoint2D UpperRight + { + get { return this.upperRight; } + } + + public PgPoint2D LowerLeft + { + get { return this.lowerLeft; } + } + + #endregion + + #region \xB7 Constructors \xB7 + + public PgBox2D(PgPoint2D lowerLeft, PgPoint2D upperRight) + { + this.lowerLeft = lowerLeft; + this.upperRight = upperRight; + } + + public PgBox2D(double x1, double y1, double x2, double y2) + { + this.lowerLeft = new PgPoint2D(x1, y1); + this.upperRight = new PgPoint2D(x2, y2); + } + + #endregion + + #region \xB7 Operators \xB7 + + public static bool operator ==(PgBox2D left, PgBox2D right) + { + if (left.UpperRight == right.UpperRight && + left.LowerLeft == right.LowerLeft) + { + return true; + } + else + { + return false; + } + } + + public static bool operator !=(PgBox2D left, PgBox2D right) + { + if (left.UpperRight != right.UpperRight || + left.LowerLeft != right.LowerLeft) + { + return true; + } + else + { + return false; + } + } + + #endregion + + #region \xB7 Overriden Methods \xB7 + + public override string ToString() + { + return String.Format("BOX({0},{1})", this.lowerLeft.ToString(), this.upperRight.ToString()); + } + + public override int GetHashCode() + { + return (this.UpperRight.GetHashCode() ^ this.LowerLeft.GetHashCode()); + } + + public override bool Equals(object obj) + { + if (obj is PgBox2D) + { + return ((PgBox2D)obj) == this; + } + else + { + return false; + } + } + + #endregion + + #region \xB7 Static Methods \xB7 + + public static PgBox2D Parse(string s) + { + if (s == null) + { + throw new ArgumentNullException("s cannot be null"); + } + + if (s.IndexOf("(") > 0) + { + s = s.Substring(s.IndexOf("(") + 1, s.IndexOf(")") - s.IndexOf("(") - 1); + } + + string[] delimiters = new string[] { PgDatabase.DataTypes["box2d"].Delimiter }; + + string[] boxPoints = s.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); + + PgPoint2D left = PgPoint2D.Parse(boxPoints[0]); + PgPoint2D right = PgPoint2D.Parse(boxPoints[1]); + + return new PgBox2D(left, right); + } + + #endregion + } +} Modified: trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint.cs 2006-05-31 18:35:17 UTC (rev 165) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint.cs 2006-05-31 18:35:53 UTC (rev 166) @@ -16,6 +16,8 @@ */ using System; +using System.Globalization; +using PostgreSql.Data.Protocol; namespace PostgreSql.Data.PgTypes { @@ -85,10 +87,9 @@ public override string ToString() { - System.Text.StringBuilder b = new System.Text.StringBuilder(); - b.AppendFormat("({0},{1})", this.x, this.y); + CultureInfo culture = CultureInfo.InvariantCulture; - return b.ToString(); + return String.Format(culture, "({0}{1}{2})", this.x, PgDatabase.DataTypes["point"].Delimiter, this.y); } public override int GetHashCode() @@ -114,7 +115,21 @@ public static PgPoint Parse(string s) { - throw new NotSupportedException(); + if (s == null) + { + throw new ArgumentNullException("s cannot be null"); + } + + string[] delimiters = new string[] { PgDatabase.DataTypes["point"].Delimiter }; + + string[] pointCoords = s.Split(delimiters, StringSplitOptions.RemoveEmptyEntries); + + if (pointCoords == null || pointCoords.Length != 2) + { + throw new ArgumentException("s is not a valid point."); + } + + return new PgPoint(Double.Parse(pointCoords[0]), Double.Parse(pointCoords[1])); } #endregion Added: trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint2D.cs =================================================================== --- trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint2D.cs (rev 0) +++ trunk/PostgreSqlClient/source/PostgreSql/Data/PgTypes/PgPoint2D.cs 2006-05-31 18:35:53 UTC (rev 166) @@ -0,0 +1,143 @@ +/* + * PgSqlClient - ADO.NET Data Provider for PostgreSQL 7.4+ + * + * The contents of this file are subject to the Initial + * Developer's Public License Version 1.0 (the "License"); + * you may not use this file except in compliance with the + * License. + * + * Software distributed under the License is distributed on + * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either + * express or implied. See the License for the specific + * language governing rights and limitations under the License. + * + * Copyright (c) 2003, 2006 Carlos Guzman Alvarez + * All Rights Reserved. + */ + +using System; +using System.Globalization; +using PostgreSql.Data.Protocol; + +namespace PostgreSql.Data.PgTypes +{ + [Serializable] + public struct PgPoint2D + { + #region \xB7 Fields \xB7 + + private double x; + private double y; + + #endregion + + #region \xB7 Properties \xB7 + + public double X + { + get { return x; } + } + + public double Y + { + get { return y; } + } + + #endregion + + #region \xB7 Constructors \xB7 + + public PgPoint2D(double x, double y) + { + this.x = x; + this.y = y; + } + + #endregion + + #region \xB7 Operators \xB7 + + public static bool operator ==(PgPoint2D left, PgPoint2D right) + { + if (left.X == right.X && left.Y == right.Y) + { + return true; + } + else + { + return true; + } + } + + public static bool operator !=(PgPoint2D left, PgPoint2D right) + { + if (left.X != right.X || left.Y != right.Y) + { + return true; + } + else + { + return true; + } + } + + #endregion + + #region \xB7 Overriden Methods \xB7 + + public override string ToString() + { + CultureInfo culture = CultureInfo.InvariantCulture; + + return String.Format(culture, "{0} {1}", this.x, this.y); + } + + public override int GetHashCode() + { + return (this.x.GetHashCode() ^ this.y.GetHashCode()); + } + + public override bool Equals(object obj) + { + if (obj != null && obj is PgPoint2D) + { + return ((PgPoint2D)obj) == this; + } + else + { + return false; + } + } + + #endregion + + #region \xB7 Static Methods \xB7 + + public static PgPoint2D Parse(string s) + { + if (s == null) + { + throw new ArgumentNullException("s cannot be null"); + } + + if (s.IndexOf("(") > 0) + { + s = s.Substring(s.IndexOf("("), s.Length - s.IndexOf("(")); + } + + string[] pointCoords = s.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); + + if (pointCoords == null || pointCoords.Length != 2) + { + throw new ArgumentException("s is not a valid point."); + } + + double x = Double.Parse(pointCoords[0], System.Globalization.CultureInfo.InvariantCulture); + double y = Double.Parse(pointCoords[1], System.Globalization.CultureInfo.InvariantCulture); + + return new PgPoint2D(x, y); + } + + #endregion + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |