public static void Run() { FileInfo fi = new FileInfo(pathXlsx); using var exp = new ExcelPackage(fi); var dataSheet = exp.Workbook.Worksheets["Лист1"]; int lastCells = dataSheet.Cells.Last().End.Row; for (int i = 2; i <= lastCells; i++) { try { var pointSo = new PointSoUd ( dataSheet.Cells[i, 1].Text, dataSheet.Cells[i, 2].Text, Double.Parse(dataSheet.Cells[i, 3].Text.Replace(",", ".")), Double.Parse(dataSheet.Cells[i, 4].Text.Replace(",", ".")), dataSheet.Cells[i, 8].Text, "СО" ); pointSoUds.Add(pointSo); } catch (Exception) { Console.WriteLine($"Ошибка данных в строке{i - 1} СО"); } try { var pointUd = new PointSoUd ( null, dataSheet.Cells[i, 5].Text, Double.Parse(dataSheet.Cells[i, 6].Text.Replace(",", ".")), Double.Parse(dataSheet.Cells[i, 7].Text.Replace(",", ".")), dataSheet.Cells[i, 8].Text, "УД" ); pointSoUds.Add(pointUd); } catch (Exception) { Console.WriteLine($"Ошибка данных в строке{i - 1} УД"); } } var kml = new KmlFileUsers(styleDocs, nameDocumentKml); var folderCompl = kml.AddFolder("Построено"); var folderNo = kml.AddFolder("Запланировано"); foreach (var point in pointSoUds) { if (point.BuildSatus == "Построено") { string id = point.Type == "УД" ? "greenUD" : "svetoforGreen"; kml.AddPoint(point, id, point.DicExtDataKml(), folderCompl); } else { string id = point.Type == "УД" ? "yellowUD" : "svetoforYellow"; kml.AddPoint(point, id, point.DicExtDataKml(), folderNo); } } kml.SaveKmz(pathKmz); }
public static async Task Main(string[] args) { Rootobject rootobject; using (FileStream fs = new FileStream(pathJson, FileMode.Open)) { rootobject = await JsonSerializer.DeserializeAsync <Rootobject>(fs); } var kml = new KmlFileUsers(styleDocs, nameDocumentKml); foreach (var rootobj in rootobject.features) { if (rootobj.type == "placemark") { var point = new Point { Name = rootobj.title, Lat = rootobj.coordinates[1], Lon = rootobj.coordinates[0] }; kml.AddPoint(point, "niir", new Dictionary <string, string> { { "Наименование", rootobj.title } }); } else if (rootobj.type == "line") { var line = new Line { Name = rootobj.title, Color = rootobj.stroke.color, Coordinates = rootobj.geometry.Coordinates .Select(p => new LatLonStruct { Lat = p.Lat, Lon = p.Lon }).ToArray(), Width = rootobj.stroke.width, Opacity = (int)Math.Round(rootobj.stroke.opacity * 100, 0) }; kml.AddLine(line, new Dictionary <string, string> { { "Наименование", rootobj.title } }); } else if (rootobj.type == "polygon") { LatLonStruct[] latLonStruct = rootobj.geometry.Coordinates .Select(p => new LatLonStruct { Lat = p.Lat, Lon = p.Lon }).ToArray(); var polygon = new Polygon(rootobj.title, rootobj.stroke.color, rootobj.fill.color, rootobj.stroke.width, latLonStruct); polygon.OpacityLine = (int)Math.Round(rootobj.stroke.opacity * 100, 0); polygon.OpacityPoly = (int)Math.Round(rootobj.fill.opacity * 100, 0); kml.AddPoligon(polygon, new Dictionary <string, string> { { "Наименование", rootobj.title } }); } } kml.SaveKmz(pathKmz); }