Exemplo n.º 1
0
        public override string GetValue(IDocContext ctxt, params string[] values)
        {
            double value = 0;

            string pattern = @"^\s*(\d+)\s*°\s*(\d+)?\s*['′]?\s*([\d.]+)?\s*[″""]?\s*([NSEOW])\s*$";

            Match match = Regex.Match(values[0], pattern);

            if (match.Success)
            {
                double deg       = double.Parse(match.Groups[1].Value, CultureInfo.InvariantCulture);
                double min       = match.Groups[2].Value == ""? 0 : double.Parse(match.Groups[2].Value, CultureInfo.InvariantCulture);
                double sec       = match.Groups[3].Value == ""? 0 : double.Parse(match.Groups[3].Value, CultureInfo.InvariantCulture);
                string direction = match.Groups[4].Value;
                double sign      = direction == "N" || direction == "E" ? +1 : -1;

                value = sign * (deg + min / 60.0 + sec / 3600);
            }
            else
            {
                throw new Exception("Incorrect format: " + values[0]);
            }

            return(value.ToString(CultureInfo.InvariantCulture));
        }
Exemplo n.º 2
0
        public override string GetValue(IDocContext ctxt, params string[] values)
        {
            if (Str.IsEmpty(values[0]) || Str.IsEmpty(values[1]))
            {
                return("");
            }

            string[] lats = values[0].Split(';');
            string[] lngs = values[1].Split(';');

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < lats.Length; i++)
            {
                if (sb.Length > 0)
                {
                    sb.Append(",");
                }
                sb.Append("(");
                sb.Append(lngs[i]);
                sb.Append(" ");
                sb.Append(lats[i]);
                sb.Append(")");
            }

            return("MULTIPOINT(" + sb.ToString() + ")");
        }
Exemplo n.º 3
0
        public override string GetValue(IDocContext ctxt, params string[] values)
        {
            string latitude  = values[0];
            string longitude = values[1];

            return("POINT(" + longitude + " " + latitude + ")");
        }
Exemplo n.º 4
0
        public override string GetValue(IDocContext ctxt, params string[] values)
        {
            double x    = double.Parse(values[0].Trim(), CultureInfo.InvariantCulture);
            double y    = double.Parse(values[1].Trim(), CultureInfo.InvariantCulture);
            bool   is_x = Str.EQNC(values[2].Trim(), "x");

            double n   = 0.7289686274;
            double c   = 11745793.39;   // En mètres
            double Xs  = 600000.0;      // En mètres
            double Ys  = 8199695.768;   // En mètres
            double l0  = 0.0;           //correspond à la longitude en radian de Paris (2°20'14.025" E) par rapport à Greenwich
            double e   = 0.08248325676; //e du NTF (on le change après pour passer en WGS)
            double eps = 0.00001;       // précision


            /*
             * Conversion Lambert 2 -> NTF géographique : ALG0004
             */
            double R       = Math.Sqrt(((x - Xs) * (x - Xs)) + ((y - Ys) * (y - Ys)));
            double g       = Math.Atan((x - Xs) / (Ys - y));
            double l       = l0 + (g / n);
            double L       = -(1 / n) * Math.Log(Math.Abs(R / c));
            double phi0    = 2 * Math.Atan(Math.Exp(L)) - (Math.PI / 2.0);
            double phiprec = phi0;
            double phii    = 2 * Math.Atan((Math.Pow(((1 + e * Math.Sin(phiprec)) / (1 - e * Math.Sin(phiprec))), e / 2.0) * Math.Exp(L))) - (Math.PI / 2.0);

            while (!(Math.Abs(phii - phiprec) < eps))
            {
                phiprec = phii;
                phii    = 2 * Math.Atan((Math.Pow(((1 + e * Math.Sin(phiprec)) / (1 - e * Math.Sin(phiprec))), e / 2.0) * Math.Exp(L))) - (Math.PI / 2.0);
            }
            double phi = phii;

            /*
             * Conversion NTF géogra$phique -> NTF cartésien : ALG0009
             */
            double a      = 6378249.2;
            double h      = 100;    // En mètres
            double N      = a / (Math.Pow((1 - (e * e) * (Math.Sin(phi) * Math.Sin(phi))), 0.5));
            double X_cart = (N + h) * Math.Cos(phi) * Math.Cos(l);
            double Y_cart = (N + h) * Math.Cos(phi) * Math.Sin(l);
            double Z_cart = ((N * (1 - (e * e))) + h) * Math.Sin(phi);

            /*
             * Conversion NTF cartésien -> WGS84 cartésien : ALG0013
             */
            // Il s'agit d'une simple translation
            double XWGS84 = X_cart - 168;
            double YWGS84 = Y_cart - 60;
            double ZWGS84 = Z_cart + 320;

            /*
             * Conversion WGS84 cartésien -> WGS84 géogra$phique : ALG0012
             */

            double l840 = 0.04079234433;    // 0.04079234433 pour passer dans un référentiel par rapport au méridien

            // de Greenwich, sinon mettre 0

            e = 0.08181919106;              // On change $e pour le mettre dans le système WGS84 au lieu de NTF
            a = 6378137.0;
            double P      = Math.Sqrt((XWGS84 * XWGS84) + (YWGS84 * YWGS84));
            double l84    = l840 + Math.Atan(YWGS84 / XWGS84);
            double phi840 = Math.Atan(ZWGS84 / (P * (1 - ((a * e * e))
                                                     / Math.Sqrt((XWGS84 * XWGS84) + (YWGS84 * YWGS84) + (ZWGS84 * ZWGS84)))));
            double phi84prec = phi840;
            double phi84i    = Math.Atan((ZWGS84 / P) / (1 - ((a * e * e * Math.Cos(phi84prec))
                                                              / (P * Math.Sqrt(1 - e * e * (Math.Sin(phi84prec) * Math.Sin(phi84prec)))))));

            while (!(Math.Abs(phi84i - phi84prec) < eps))
            {
                phi84prec = phi84i;
                phi84i    = Math.Atan((ZWGS84 / P) / (1 - ((a * e * e * Math.Cos(phi84prec))
                                                           / (P * Math.Sqrt(1 - ((e * e) * (Math.Sin(phi84prec) * Math.Sin(phi84prec))))))));
            }
            double phi84 = phi84i;


            return(is_x ? (phi84 * 180.0 / Math.PI).ToString(CultureInfo.InvariantCulture) : (l84 * 180.0 / Math.PI).ToString(CultureInfo.InvariantCulture));
        }
Exemplo n.º 5
0
        public override Return OnExecute()
        {
            string           indexes;
            HashSet <string> hsMD5       = new HashSet <string>();
            int     emptyLinesCount      = 0;
            int     duplicatesLinesCount = 0;
            int     writtenLinesCount    = 0;
            int     rowProcessed         = 0;
            ListStr lHeaders             = new ListStr();

            EngineClient _client = null;

            Sinequa.Engine.Client.Cursor _cursor = null;

            //do not use StreamWriter in a using statement. In simulate mode the file is not created so this will trigger an exception.
            StreamWriter sw = null;

            try
            {
                _client = EngineClientsPool.FromPoolByIndexList(conf.listIndexes, out indexes, conf.engine, false);
            }
            catch (Exception ex)
            {
                Sys.LogError("Cannot get Engine Client from pool for indexes [" + conf.listIndexes + "]");
                Sys.LogError(ex);
                return(Return.Error);
            }
            Sys.Log("Using Engine client  [" + _client.Name + "]");

            try
            {
                Sys.Log("Execute query [" + conf.GetSQL() + "]");

                _cursor = _client.ExecCursor(conf.GetSQL());

                if (_cursor == null)
                {
                    Sys.LogError("Cannot get cursor for query [" + conf.GetSQL() + "]");
                    return(Return.Error);
                }

                DocExportIndexToCsv doc = new DocExportIndexToCsv(this, _cursor, conf.dColumnColumnAlias);
                var context             = new IDocContext {
                    Doc = doc
                };

                Sys.Log("Query processingtime [" + _cursor.GetAttribute("processingtime") + "]");
                Sys.Log("Query row count [" + _cursor.TotalRowCount + "]");
                int globalTimer = Sys.TimerStart();

                if (!conf.simulate)
                {
                    sw = new StreamWriter(conf.destinationFilePath, false, Encoding.UTF8);
                }

                int localTimer = Sys.TimerStart();
                while (!_cursor.End())
                {
                    rowProcessed++;
                    if (rowProcessed % logStatsEveryNRows == 0)
                    {
                        Sys.Log("----------------------------------------------------");
                        Sys.Log("Number of rows processed [" + rowProcessed + "] ");
                        Sys.Log("Number of lines exported [" + writtenLinesCount + "] ");
                        Sys.Log("Number of empty lines removed [" + emptyLinesCount + "] ");
                        Sys.Log("Number of duplicated lines removed [" + duplicatesLinesCount + "] ");
                        Sys.Log("Processing [" + logStatsEveryNRows + "] rows in [", Sys.TimerGetText(Sys.TickDuration(localTimer)), "]");
                        localTimer = Sys.TimerStart();
                    }

                    ListStr l       = new ListStr();
                    bool    isEmpty = true;

                    for (int i = 0; i < _cursor.ColumnCount; i++)
                    {
                        if (conf.addHeaders && rowProcessed == 1)   //headers
                        {
                            string header = _cursor.GetColumnName(i);
                            if (conf.useDblQuote)
                            {
                                header = "\"" + header + "\"";
                            }
                            lHeaders.Add(header);
                        }

                        string colValue = Str.Empty;
                        //cursor column match column mapping column name ?
                        if (conf.lColumnMapping.Exists(x => Str.EQNC(x.columnName, _cursor.GetColumnName(i))))
                        {
                            //get all matching column mapping for current column
                            List <ColumnMapping> lColumnMapping = conf.lColumnMapping.FindAll(x => Str.EQNC(x.columnName, _cursor.GetColumnName(i)));
                            foreach (ColumnMapping columnMapping in lColumnMapping)
                            {
                                if (columnMapping.slectionQuery.IsSelected(context, doc))  //match selection query ? if so, apply value pattern
                                {
                                    Sys.Log2(40, "Column [" + columnMapping.columnName + "] match selection query [" + columnMapping.slectionQuery.Sql + "]");

                                    colValue = IDocHelper.GetValue(context, doc, columnMapping.valueExpression);
                                    Sys.Log2(40, "Column [" + columnMapping.columnName + "] use value pattern [" + columnMapping.valueExpression + "] = [" + colValue + "]");
                                    break;  //stop mapping when selection query match
                                }
                                else
                                {
                                    Sys.Log2(40, "Column [" + columnMapping.columnName + "] don't match selection query [" + columnMapping.slectionQuery.Sql + "]");
                                    continue;   //go to next expression
                                }
                            }
                        }
                        //no column mapping, get value from cursor
                        else
                        {
                            colValue = _cursor.GetColumn(i);
                        }
                        if (!Str.IsEmpty(colValue))
                        {
                            isEmpty = false;
                        }
                        if (conf.useReplaceSeparator)
                        {
                            colValue = colValue.Replace(conf.separator, conf.replaceSeparator);                            //replace separator in values
                        }
                        if (conf.useDblQuote)
                        {
                            colValue = "\"" + colValue + "\"";                      //use double quote
                        }
                        l.Add(colValue);
                    }

                    string line = l.ToStr(conf.separator);

                    if (conf.removeDuplicates)  //remove duplicates
                    {
                        string MD5 = Str.Md5(line);
                        if (!hsMD5.Add(MD5))
                        {
                            duplicatesLinesCount++;
                            _cursor.MoveNext();
                            continue;
                        }
                    }

                    if (conf.removeEmptyLines && isEmpty)   //remove empty lines
                    {
                        emptyLinesCount++;
                        _cursor.MoveNext();
                        continue;
                    }

                    writtenLinesCount++;
                    if (conf.simulate)  //simulate, add headers and line into logs
                    {
                        if (conf.addHeaders && rowProcessed == 1)
                        {
                            Sys.Log(GetHeaders(lHeaders)); // write headers
                        }
                        Sys.Log(line);                     //write line
                        if (writtenLinesCount >= conf.simulateCount)
                        {
                            break;
                        }
                    }
                    else
                    {
                        if (conf.addHeaders && rowProcessed == 1)
                        {
                            sw.WriteLine(GetHeaders(lHeaders)); // write headers
                        }
                        sw.WriteLine(line);                     //write line
                    }

                    _cursor.MoveNext();
                }

                if (sw != null)
                {
                    sw.Close();             //dispose stream writer
                }
                Sys.Log("----------------------------------------------------");
                if (conf.removeEmptyLines)
                {
                    Sys.Log("Number of empty lines removed [" + emptyLinesCount + "]");
                }
                if (conf.removeDuplicates)
                {
                    Sys.Log("Number of duplicated lines removed [" + duplicatesLinesCount + "]");
                }
                Sys.Log("[" + writtenLinesCount + "] lines exported into file [" + conf.destinationFilePath + "]");
                Sys.Log("Processing [" + rowProcessed + "] rows in [", Sys.TimerGetText(Sys.TickDuration(globalTimer)), "]");
            }
            catch (Exception ex)
            {
                Sys.LogError("Select index Cursor error : ", ex);
                try
                {
                    if (_client != null)
                    {
                        EngineClientsPool.ToPool(_client);
                    }
                }
                catch (Exception exe)
                {
                    Sys.LogError("EngineClientsPool ToPool : ", exe);
                    Sys.Log(exe.StackTrace);
                }
            }
            finally
            {
                try
                {
                    if (_cursor != null)
                    {
                        _cursor.Close();
                    }
                }
                catch (Exception ex)
                {
                    Sys.LogError("Close cursor error : ", ex);
                    Sys.Log(ex.StackTrace);
                }
                EngineClientsPool.ToPool(_client);
            }

            return(base.OnExecute());
        }