public static object ReadDataFromCSV(string filePath, int titleRows = 0, string valuesSeparator = ";", string linesSeparator = "\n")
        {
            string        dataString     = ServiceTools.ReadTextFromFile(filePath);
            List <string> dataSubstrings = new List <string>(dataString.Split(linesSeparator.ToCharArray()));

            if (titleRows > 0)
            {
                dataSubstrings = dataSubstrings.Skip(titleRows).ToList();
            }

            dataSubstrings.RemoveAll(str => str == "");
            string[] values0 = dataSubstrings[0].Split(valuesSeparator.ToCharArray());
            if (values0.Count() == 1)
            {
                DenseVector retVec = DenseVector.Create(dataSubstrings.Count(),
                                                        idx => Convert.ToDouble(dataSubstrings[idx].Replace(".", ",")));
                return(retVec);
            }
            else
            {
                DenseMatrix retMatrix = DenseMatrix.Create(dataSubstrings.Count(), values0.Count(),
                                                           (r, c) =>
                                                           Convert.ToDouble(dataSubstrings[r].Split(valuesSeparator.ToCharArray())[c].Replace(".", ",")));
                //foreach (string substring in dataSubstrings)
                //{
                //    List<string> currRowStrings = new List<string>(substring.Split(valuesSeparator.ToCharArray()));
                //    retMatrix.InsertRow(retMatrix.RowCount,
                //        DenseVector.OfEnumerable(
                //            currRowStrings.ConvertAll<double>(str => Convert.ToDouble(str.Replace(".", ",")))));
                //}
                return(retMatrix);
            }
        }
        public static List <List <string> > ReadDataFromCSV(string filePath, int titleRows = 0, bool nonNumberData = true, string valuesSeparator = ";", string linesSeparator = "\n")
        {
            string        dataString     = ServiceTools.ReadTextFromFile(filePath);
            List <string> dataSubstrings = new List <string>(dataString.Split(linesSeparator.ToCharArray()));

            if (titleRows > 0)
            {
                dataSubstrings = dataSubstrings.Skip(titleRows).ToList();
            }

            dataSubstrings.RemoveAll(str => str == "");

            List <List <string> > output =
                dataSubstrings.ConvertAll <List <string> >(
                    str => new List <string>(str.Split(valuesSeparator.ToCharArray())));

            return(output);
        }
示例#3
0
        private void ReadShorelineData(int level = 0)
        {
            string currLevelShorelineFilename = shorelineFileNames.Find(tpl => tpl.Item1 == level).Item2;

            //lShorelines = new List<Contour<Point>>();

            string strFileContents = ServiceTools.ReadTextFromFile(currLevelShorelineFilename);

            List <string> lContoursSubstrings =
                new List <string>(strFileContents.Split(new string[] { "END" }, StringSplitOptions.RemoveEmptyEntries));
            List <List <string> > lContoursStringContents = lContoursSubstrings.ConvertAll(str =>
            {
                List <string> lStrContents =
                    new List <string>(str.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries));
                if (lStrContents.Count == 0)
                {
                    return(lStrContents);
                }
                //удалим номер контура
                lStrContents.RemoveAt(0);
                return(lStrContents);
            });

            lContoursStringContents.RemoveAll(l => l.Count == 0);



            //RectangleF imageLimits = new RectangleF(ptdLeftTopGPS.PointF(),
            //    new SizeF((ptdRightBottomGPS - ptdLeftTopGPS).PointF()));
            //imageLimits.Height = -imageLimits.Height;
            ////сместить на 180 по долготе, на 90 по широте, отразить сверху вниз.
            //// отмасштабировать все линейные размеры в scaleFactor * 2.0d раз
            //imageLimits.Location = imageLimits.Location + new SizeF(180.0f, 0.0f);
            //imageLimits.Location = new PointF(imageLimits.Location.X, 90.0f - imageLimits.Location.Y);
            //imageLimits.Location = ((new PointD(imageLimits.Location)) * scaleFactor * 2.0d).PointF();
            //imageLimits.Width *= (float)(scaleFactor * additionalScale * 2.0d);
            //imageLimits.Height *= (float)(scaleFactor * additionalScale * 2.0d);
            //Rectangle imageLimitsInt = new Rectangle((new PointD(imageLimits.Location)).Point(),
            //    new Size(Convert.ToInt32(imageLimits.Width), Convert.ToInt32(imageLimits.Height)));

            Rectangle imageLimitsInt = new Rectangle(new Point(0, 0), imgSize);
            double    currScaleLat   = imgSize.Height / 180.0d;
            double    currScaleLon   = imgSize.Width / 360.0d;
            double    currScale      = Math.Min(currScaleLat, currScaleLon);


            #region // obsolete

            //Contour<Point> cImageMarginsContour = new Contour<Point>(new MemStorage());

            //List<Point> ptBoundingRectVertices = new List<Point>()
            //{
            //    imageLimitsInt.Location,
            //    imageLimitsInt.Location + new Size(imageLimitsInt.Width, 0),
            //    imageLimitsInt.Location + imageLimitsInt.Size,
            //    imageLimitsInt.Location + new Size(0, imageLimitsInt.Height)
            //};

            //cImageMarginsContour.PushMulti(ptBoundingRectVertices.ToArray(), Emgu.CV.CvEnum.BACK_OR_FRONT.BACK);

            //lShorelinesAtImage = lContoursStringContents.ConvertAll(lContourDataStr =>
            //{
            //    Contour<PointF> currContour = new Contour<PointF>(new MemStorage());
            //    List<PointF> pointsToPush = lContourDataStr.ConvertAll<PointF>(strPointCoords =>
            //    {
            //        List<string> lStrCoordsValues =
            //            new List<string>(strPointCoords.Split(',')).ConvertAll<string>(
            //                str => str.Trim().Replace(".", ","));

            //        List<double> lDoubCoordsValues = lStrCoordsValues.ConvertAll(Convert.ToDouble);
            //        PointD ptdCoordinatesLonLat = new PointD(lDoubCoordsValues[0], lDoubCoordsValues[1]);
            //        PointD ptdCoordinatesAtImage = ptdCoordinatesLonLat + new SizeD(180.0d, 0.0d);
            //        ptdCoordinatesAtImage.Y = 90.0d - ptdCoordinatesAtImage.Y;
            //        ptdCoordinatesAtImage *= scaleFactor * 2.0d;
            //        return ptdCoordinatesAtImage.PointF();
            //    });

            //    pointsToPush = pointsToPush.ConvertAll(ptd =>
            //    {
            //        if (ptd.X < imageLimitsInt.Left) ptd.X = imageLimitsInt.Left - 4;
            //        if (ptd.X > imageLimitsInt.Right) ptd.X = imageLimitsInt.Right + 4;
            //        if (ptd.Y < imageLimitsInt.Top) ptd.Y = imageLimitsInt.Top - 4;
            //        if (ptd.Y > imageLimitsInt.Bottom) ptd.Y = imageLimitsInt.Bottom + 4;
            //        return ptd;
            //    });

            //    List<PointF> pointsToPushShifted = pointsToPush.ConvertAll(pt => new PointF(pt.X - imageLimitsInt.Left, pt.Y - imageLimitsInt.Top));

            //    currContour.PushMulti(pointsToPushShifted.ToArray(), Emgu.CV.CvEnum.BACK_OR_FRONT.BACK);
            //    return currContour;
            //});

            #endregion // obsolete


            lShorelinesAtImage = lContoursStringContents.ConvertAll(lContourDataStr =>
            {
                //VectorOfPoint currContour = new VectorOfPoint();

                Contour <Point> currContour = new Contour <Point>(new MemStorage());

                List <Point> pointsToPush = lContourDataStr.ConvertAll <Point>(strPointCoords =>
                {
                    List <string> lStrCoordsValues =
                        new List <string>(strPointCoords.Split(',')).ConvertAll <string>(
                            str => str.Trim().Replace(".", ","));

                    List <double> lDoubCoordsValues = lStrCoordsValues.ConvertAll(Convert.ToDouble);
                    PointD ptdCoordinatesLonLat     = new PointD(lDoubCoordsValues[0], lDoubCoordsValues[1]);
                    // PointD ptdCoordinatesAtImage = ptdCoordinatesLonLat + new SizeD(180.0d, 0.0d);
                    PointD ptdCoordinatesAtImage = ptdCoordinatesLonLat * currScale + new SizeD(imgSize.Width / 2.0d, 0.0d);
                    ptdCoordinatesAtImage.Y      = imgSize.Height / 2.0d - ptdCoordinatesAtImage.Y;
                    // ptdCoordinatesAtImage *= scaleFactor * additionalScale * 2.0d;
                    return(ptdCoordinatesAtImage.Point());
                });

                pointsToPush = pointsToPush.ConvertAll(pt =>
                {
                    if (pt.X < imageLimitsInt.Left)
                    {
                        pt.X = imageLimitsInt.Left - 4;
                    }
                    if (pt.X > imageLimitsInt.Right)
                    {
                        pt.X = imageLimitsInt.Right + 4;
                    }
                    if (pt.Y < imageLimitsInt.Top)
                    {
                        pt.Y = imageLimitsInt.Top - 4;
                    }
                    if (pt.Y > imageLimitsInt.Bottom)
                    {
                        pt.Y = imageLimitsInt.Bottom + 4;
                    }
                    return(pt);
                });

                List <Point> pointsToPushShifted = pointsToPush.ConvertAll(pt => new Point(pt.X - imageLimitsInt.Left, pt.Y - imageLimitsInt.Top));

                //currContour.Push(pointsToPushShifted.ToArray());
                currContour.PushMulti(pointsToPushShifted.ToArray(), Emgu.CV.CvEnum.BACK_OR_FRONT.BACK);

                return(currContour);
            });

            // lShorelinesAtImage.RemoveAll(cont => CvInvoke.ContourArea(cont, false) < 1.0d);
            lShorelinesAtImage.RemoveAll(cont => cont.Area < 1.0d);


            Size imgToPlotSize = imageLimitsInt.Size; //new Size(Convert.ToInt32(360*scaleFactor * 2), Convert.ToInt32(180*scaleFactor*2));

            imgShorelinesBackground = new Image <Bgr, byte>(imgToPlotSize.Width, imgToPlotSize.Height, colorOcean);

            foreach (Contour <Point> contour in lShorelinesAtImage)
            {
                if (!contour.Any())
                {
                    continue;
                }
                //imgShorelinesBackground.Draw(contour, colorBlack, (currentShorelineDetailsLevel + 1) * 2);
                imgShorelinesBackground.Draw(contour, colorBlack, 2);
                imgShorelinesBackground.Draw(contour, new Bgr(200, 200, 200), -1);
            }


            //imgShorelinesBackground.Draw(imageLimitsInt, new Bgr(Color.Red), (currentShorelineDetailsLevel + 1) * 4);

            //imgShorelinesBackground.ROI = imageLimitsInt;
            //imgShorelinesBackground = imgShorelinesBackground.Copy();
            //imgShorelinesBackground.ROI = Rectangle.Empty;
        }