Exemplo n.º 1
0
 public NpgsqlCircle(NpgsqlPoint center, double radius)
     : this()
 {
     X      = center.X;
     Y      = center.Y;
     Radius = radius;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Point.
 /// </summary>
 internal static byte[] ToPoint(NpgsqlNativeTypeInfo TypeInfo, Object NativeData, Boolean forExtendedQuery, NativeToBackendTypeConverterOptions options, bool arrayElement)
 {
     if (NativeData is NpgsqlPoint)
     {
         NpgsqlPoint P = (NpgsqlPoint)NativeData;
         return(BackendEncoding.UTF8Encoding.GetBytes(String.Format(CultureInfo.InvariantCulture, "({0},{1})", P.X, P.Y)));
     }
     else
     {
         throw new InvalidCastException("Unable to cast data to NpgsqlPoint type");
     }
 }
        /// <summary>
        /// Point.
        /// </summary>

        internal static String ToPoint(NpgsqlNativeTypeInfo TypeInfo, Object NativeData, Boolean ForExtendedQuery)
        {
            if (NativeData is NpgsqlPoint)
            {
                NpgsqlPoint P = (NpgsqlPoint)NativeData;
                return(String.Format(CultureInfo.InvariantCulture, "({0},{1})", P.X, P.Y));
            }
            else
            {
                throw new InvalidCastException("Unable to cast data to NpgsqlPoint type");
            }
        }
Exemplo n.º 4
0
        public void Point()
        {
            var expected = new NpgsqlPoint(1.2, 3.4);
            var cmd = new NpgsqlCommand("SELECT @p1, @p2", Conn);
            var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Point) { Value = expected };
            var p2 = new NpgsqlParameter { ParameterName = "p2", Value = expected };
            Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Point));
            cmd.Parameters.Add(p1);
            cmd.Parameters.Add(p2);
            var reader = cmd.ExecuteReader();
            reader.Read();

            for (var i = 0; i < cmd.Parameters.Count; i++)
            {
                Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof(NpgsqlPoint)));
                Assert.That(reader[i], Is.EqualTo(expected));
            }
        }
Exemplo n.º 5
0
        public void Point()
        {
            using (var conn = OpenConnection())
            {
                var expected = new NpgsqlPoint(1.2, 3.4);
                var cmd = new NpgsqlCommand("SELECT @p1, @p2", conn);
                var p1 = new NpgsqlParameter("p1", NpgsqlDbType.Point) {Value = expected};
                var p2 = new NpgsqlParameter {ParameterName = "p2", Value = expected};
                Assert.That(p2.NpgsqlDbType, Is.EqualTo(NpgsqlDbType.Point));
                cmd.Parameters.Add(p1);
                cmd.Parameters.Add(p2);
                using (var reader = cmd.ExecuteReader()) {
                    reader.Read();

                    for (var i = 0; i < cmd.Parameters.Count; i++)
                    {
                        Assert.That(reader.GetFieldType(i), Is.EqualTo(typeof(NpgsqlPoint)));
                        var actual = reader.GetFieldValue<NpgsqlPoint>(i);
                        AssertPointsEqual(actual, expected);
                    }
                }
            }
        }
Exemplo n.º 6
0
 public NpgsqlLSeg(double startx, double starty, double endx, double endy) : this()
 {
     Start = new NpgsqlPoint(startx, starty);
     End   = new NpgsqlPoint(endx, endy);
 }
Exemplo n.º 7
0
 public NpgsqlLSeg(NpgsqlPoint start, NpgsqlPoint end)
     : this()
 {
     Start = start;
     End   = end;
 }
Exemplo n.º 8
0
 public NpgsqlBox(NpgsqlPoint UpperRight, NpgsqlPoint LowerLeft)
 {
     _UpperRight = UpperRight;
     _LowerLeft  = LowerLeft;
 }
Exemplo n.º 9
0
 public NpgsqlCircle(NpgsqlPoint Center, Double Radius)
 {
     this.Center = Center;
     this.Radius = Radius;
 }
Exemplo n.º 10
0
 public NpgsqlLSeg(NpgsqlPoint Start, NpgsqlPoint End)
 {
     this.Start = Start;
     this.End   = End;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Método para montar o sql para incluir um novo registro
        /// </summary>
        /// <param name="pDrw"></param>
        /// <returns></returns>
        private string MontarComandosInclusao(DataRow pDrw, NpgsqlCommand pCmd)
        {
            StringBuilder strbCampos = new StringBuilder();
            StringBuilder strbParametros = new StringBuilder();
            StringBuilder sbInsertGeo = new StringBuilder();
            string sCampos = "";
            string sParametros;
            string sRetorno = "";
            string sCoordenadas = "";
            bool bDadosGeo = false;

            foreach (DataColumn col in pDrw.Table.Columns)
            {
                Propriedades.ContadorBarraProgresso++;
                if (!col.ColumnName.Equals("id"))
                {
                    if (col.ColumnName.Equals("id_usuario"))
                        pDrw[col] = Propriedades.CodigoUsuario;

                    sCampos = col.ColumnName;
                    strbCampos.Append(sCampos);
                    strbCampos.Append(",");

                    if (col.ColumnName.Contains("pl_") || col.ColumnName.Contains("pt_"))
                    {
                        bDadosGeo = true;

                        if (col.ColumnName.Contains("pl_"))
                        {
                            string[] asCoordenadas = pDrw[col].ToString().Trim().Split(';');
                            NpgsqlPoint[] pontos = new NpgsqlPoint[asCoordenadas.Length];
                            int iContador = 0;
                            foreach (string sCo in asCoordenadas)
                            {
                                pontos[iContador] = new NpgsqlPoint(Convert.ToSingle(sCo.Substring(0, (Convert.ToInt32(sCo.Length) / 2))), Convert.ToSingle(sCo.Substring(Convert.ToInt32(sCo.Length) / 2)));
                                iContador++;
                            }

                            StringBuilder sbCoord = new StringBuilder();
                            //sCoordenadas = string.Join(",", pontos.AsEnumerable().Select(item => item.X + " " + item.Y).ToArray<string>());
                            pontos.AsEnumerable().ToList().ForEach(item =>
                            {
                                sbCoord.Append(item.X).Replace(',','.');
                                sbCoord.Append(" ");
                                sbCoord.Append(item.Y).Replace(',', '.');
                                sbCoord.Append(";");
                                sbCoord.Append(" ");
                            });

                            sCoordenadas = sbCoord.ToString().Replace(';',',');
                            sCoordenadas = Funcoes.RetirarVirgulasDoFimDaString(sCoordenadas);
                        }
                        else
                        {
                            NpgsqlPoint pontos = new NpgsqlPoint(Convert.ToSingle(pDrw[col].ToString().Substring(0, (Convert.ToInt32(pDrw[col].ToString().Length) / 2))), Convert.ToSingle(pDrw[col].ToString().Substring(Convert.ToInt32(pDrw[col].ToString().Length) / 2)));
                            sCoordenadas = pontos.X + " " + pontos.Y;
                            sCoordenadas = sCoordenadas.Replace(',', '.');
                        }
                    }
                    else
                    {

                        sParametros = "@" + col.ColumnName;
                        strbParametros.Append(sParametros);
                        strbParametros.Append(",");
                        pCmd.Parameters.Add(new NpgsqlParameter(sParametros, pDrw[col]));
                    }
                }
            }

            sCampos = Funcoes.RetirarVirgulasDoFimDaString(strbCampos.ToString());
            sParametros = Funcoes.RetirarVirgulasDoFimDaString(strbParametros.ToString());

            if (!bDadosGeo)
                sRetorno = "INSERT INTO " + pDrw.Table.TableName + " ( " + sCampos + ")" + " VALUES ( " + sParametros + ")";
            else
            {
                string sPolygon = "POLYGON";
                string sPoint = "POINT";

                sbInsertGeo.AppendLine("INSERT INTO");
                sbInsertGeo.AppendLine(pDrw.Table.TableName);
                sbInsertGeo.AppendLine("( " + sCampos + ")");
                sbInsertGeo.AppendLine("VALUES (" + sParametros);
                sbInsertGeo.AppendLine(", st_geomfromtext('" + (Propriedades.TipoDadoGeo == eTipoDadoGeografico.polygon ? sPolygon + "((" + sCoordenadas + "))', 4326))" : sPoint + "(" + sCoordenadas + ")', 4326 ))"));
                //inserir o tipo da coluna de acordo com o definido nas propriedades

                sRetorno = sbInsertGeo.ToString();
            }

                return sRetorno;
        }
Exemplo n.º 12
0
 public NpgsqlCircle(NpgsqlPoint center, Double radius)
 {
     Center = center;
     Radius = radius;
 }
Exemplo n.º 13
0
 public NpgsqlBox(NpgsqlPoint upperRight, NpgsqlPoint lowerLeft) : this()
 {
     UpperRight = upperRight;
     LowerLeft  = lowerLeft;
 }
Exemplo n.º 14
0
 public NpgsqlBox(NpgsqlPoint UpperRight, NpgsqlPoint LowerLeft)
 {
     _UpperRight = UpperRight;
     _LowerLeft = LowerLeft;
 }
Exemplo n.º 15
0
 public NpgsqlCircle(NpgsqlPoint Center, Double Radius)
 {
     this.Center = Center;
     this.Radius = Radius;
 }
Exemplo n.º 16
0
 public NpgsqlPolygon(NpgsqlPoint[] Points)
 {
     this.Points = Points;
 }
Exemplo n.º 17
0
 public NpgsqlPath(NpgsqlPoint[] Points)
 {
     this.Points = Points;
     IsOpen = false;
 }
Exemplo n.º 18
0
 public NpgsqlLSeg(NpgsqlPoint Start, NpgsqlPoint End)
 {
     this.Start = Start;
     this.End = End;
 }
Exemplo n.º 19
0
 public NpgsqlBox(NpgsqlPoint upperRight, NpgsqlPoint lowerLeft)
 {
     _upperRight = upperRight;
     _lowerLeft  = lowerLeft;
 }
Exemplo n.º 20
0
 void AssertPointsEqual(NpgsqlPoint actual, NpgsqlPoint expected)
 {
     Assert.That(actual.X, Is.EqualTo(expected.X).Within(1).Ulps);
     Assert.That(actual.Y, Is.EqualTo(expected.Y).Within(1).Ulps);
 }