private void ParsePolygon(string parens, string mods, Color lineColor, Color polyColor, double alt, Dates date) { if (!parens.StartsWith("(") && parens.EndsWith(")")) { return; } // string the top level of parens parens = parens.Substring(1, parens.Length - 2); List <string> shapes = UiTools.SplitString(parens, ","); foreach (string shape in shapes) { KmlLineList lineList = new KmlLineList(); lineList.Astronomical = astronomical; lineList.MeanRadius = meanRadius; lineList.ParseWkt(shape, mods, alt, date); if (alt == 0) { AddPolygonFlat(false, lineList, 1, polyColor, lineColor, true, true, date); } else { AddPolygon(false, lineList, 1, polyColor, lineColor, true, true, date); } } }
public void ParseWkt(string geoText, string option, double alt, Dates date) { //todo fix the WKT parser List <string> parts = UiTools.Split(geoText, "(,)"); foreach (string part in parts) { string[] coordinates = part.Trim().Split(" "); if (coordinates.Length > 1) { KmlCoordinate pnt = new KmlCoordinate(); pnt.Lng = double.Parse(coordinates[0]); if (Astronomical) { pnt.Lng -= 180; } pnt.Lat = double.Parse(coordinates[1]); if (coordinates.Length > 2 && alt == 0) { pnt.Alt = double.Parse(coordinates[2]); } else { pnt.Alt = alt; } pnt.Date = date; PointList.Add(pnt); } } }
//public void Save(string path) //{ // using (Stream s = new FileStream(path, FileMode.Create)) // { // Save(s); // } //} //public void Save(Stream stream) //{ // stream = new GZipStream(stream, CompressionMode.Compress); // StreamWriter sw = new StreamWriter(stream, Encoding.UTF8); // bool first = true; // foreach (string col in Header) // { // if (!first) // { // sw.Write("\t"); // } // else // { // first = false; // } // sw.Write(col); // } // sw.Write("\r\n"); // foreach (string[] row in Rows) // { // first = true; // foreach (string col in row) // { // if (!first) // { // sw.Write("\t"); // } // else // { // first = false; // } // sw.Write(col); // } // sw.Write("\r\n"); // } // sw.Close(); //} //public override string ToString() //{ // StringBuilder sb = new StringBuilder(); // StringWriter sw = new StringWriter(sb); // bool first = true; // foreach (string col in Header) // { // if (!first) // { // sw.Write("\t"); // } // else // { // first = false; // } // sw.Write(col); // } // sw.Write("\r\n"); // foreach (string[] row in Rows) // { // first = true; // foreach (string col in row) // { // if (!first) // { // sw.Write("\t"); // } // else // { // first = false; // } // sw.Write(col); // } // sw.Write("\r\n"); // } // return sb.ToString(); //} //public static bool IsGzip(Stream stream) //{ // BinaryReader br = new BinaryReader(stream); // byte[] line = br.ReadBytes(2); // if (line[0] == 31 && line[1] == 139) // { // return true; // } // else // { // return false; // } //} //public static Table Load(string path, char delimiter) //{ // if (path.ToLower().EndsWith("csv")) // { // delimiter = ','; // } // using (Stream s = new FileStream(path, FileMode.Open)) // { // return Load(s, delimiter); // } //} //public static Table Load(Stream stream, char delimiter) //{ // bool gZip = IsGzip(stream); // stream.Seek(0, SeekOrigin.Begin); // if (gZip) // { // stream = new GZipStream(stream, CompressionMode.Decompress); // } // Table table = new Table(); // table.Delimiter = delimiter; // StreamReader sr = new StreamReader(stream); // if (sr.Peek() >= 0) // { // string headerLine = sr.ReadLine(); // table.Rows.Clear(); // table.Header = UiTools.SplitString(headerLine, delimiter); // } // else // { // table.Header = new string[0]; // } // int count = 0; // while (sr.Peek() >= 0) // { // string line = sr.ReadLine(); // string[] rowData = UiTools.SplitString(line, delimiter); // if (rowData.Length < 2) // { // break; // } // table.Rows.Add(rowData); // count++; // } // return table; //} public void LoadFromString(string data, bool isUpdate, bool purge, bool hasHeader) { int count = 0; string[] lines = data.Split("\r\n"); if (!isUpdate || hasHeader) { if (lines.Length > 0) { string headerLine = lines[0]; count++; if (headerLine.IndexOf("\t") == -1 && headerLine.IndexOf(",") > -1) { Delimiter = ","; } if (!isUpdate) { Rows.Clear(); } Header = UiTools.SplitString(headerLine, Delimiter); } else { Header = new List <string>(); } } List <List <string> > temp = new List <List <string> >(); if (!purge) { temp = Rows; } while (count < lines.Length) { string line = lines[count]; List <string> rowData = UiTools.SplitString(line, Delimiter); if (rowData.Count < 1) { break; } temp.Add(rowData); count++; } if (purge) { Rows = temp; } }
private void ExtractCatalogTileRows() { bool headerRemoved = false; foreach (string line in catalogData.GetText().Split("\n")) { if (!line.StartsWith("#") && !headerRemoved) { headerRemoved = true; continue; } if (!line.StartsWith("#")) { List <string> rowData = UiTools.SplitString(line, dataset.HipsProperties.CatalogSpreadSheetLayer.Table.Delimiter); catalogRows.Add(rowData); } } }
private void ParseLineString(string parens, string mods, Color lineColor, double alt, bool single, Dates date) { if (!parens.StartsWith("(") && parens.EndsWith(")")) { return; } if (!single) { // string the top level of parens parens = parens.Substring(1, parens.Length - 2); } List <string> shapes = UiTools.SplitString(parens, ","); foreach (string shape in shapes) { KmlLineList lineList = new KmlLineList(); lineList.Astronomical = astronomical; lineList.MeanRadius = meanRadius; lineList.ParseWkt(shape, mods, alt, date); AddPolygon(false, lineList, 1, Colors.White, lineColor, false, false, date); } }
private void ParseGeometry(string gs, Color lineColor, Color polyColor, double alt, Dates date) { gs = gs.Trim().ToLowerCase(); int index = gs.IndexOf('('); if (index < 0) { return; } if (!gs.EndsWith(")")) { return; } string commandPart = gs.Substring(0, index).Trim(); string parens = gs.Substr(index); string[] parts = commandPart.Split(" "); string command = null; string mods = null; if (parts.Length > 0) { foreach (string item in parts) { if (string.IsNullOrEmpty(command)) { command = item; } else if (string.IsNullOrEmpty(mods)) { mods = item; } } } switch (command) { case "multipolygon": case "polygon": { ParsePolygon(parens, mods, lineColor, polyColor, alt, date); } break; case "multilinestring": { ParseLineString(parens, mods, lineColor, alt, false, date); } break; case "linestring": { ParseLineString(parens, mods, lineColor, alt, true, date); } break; case "geometrycollection": { parens = parens.Substring(1, parens.Length - 2); List <string> shapes = UiTools.SplitString(parens, ","); foreach (string shape in shapes) { ParseGeometry(shape, lineColor, polyColor, alt, date); } } break; default: break; } }