private void button7_Click(object sender, EventArgs e) { List <string> Prov2Letter = new List <string>() { "BC", "NB", "NL", "NS", "PE", "QC" }; List <string> ProvFull = new List <string>() { "British Columbia", "New Brunswick", "Newfoundland and Labrador", "Nova Scotia", "Prince Edward Island", "Québec" }; StringBuilder sb = new StringBuilder(); sb.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>"); sb.AppendLine(@"<kml xmlns=""http://www.opengis.net/kml/2.2"" xmlns:gx=""http://www.google.com/kml/ext/2.2"" xmlns:kml=""http://www.opengis.net/kml/2.2"" xmlns:atom=""http://www.w3.org/2005/Atom"">"); sb.AppendLine(@" <Document>"); sb.AppendLine(@" <name>Tide Location</name>"); sb.AppendLine(@" <Style id=""s_ylw-pushpin"">"); sb.AppendLine(@" <IconStyle>"); sb.AppendLine(@" <scale>1.1</scale>"); sb.AppendLine(@" <Icon>"); sb.AppendLine(@" <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>"); sb.AppendLine(@" </Icon>"); sb.AppendLine(@" <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"); sb.AppendLine(@" </IconStyle>"); sb.AppendLine(@" <LineStyle>"); sb.AppendLine(@" <color>ffff00ff</color>"); sb.AppendLine(@" </LineStyle>"); sb.AppendLine(@" <PolyStyle>"); sb.AppendLine(@" <fill>0</fill>"); sb.AppendLine(@" </PolyStyle>"); sb.AppendLine(@" </Style>"); sb.AppendLine(@" <StyleMap id=""msn_grn-pushpin"">"); sb.AppendLine(@" <Pair>"); sb.AppendLine(@" <key>normal</key>"); sb.AppendLine(@" <styleUrl>#sn_grn-pushpin</styleUrl>"); sb.AppendLine(@" </Pair>"); sb.AppendLine(@" <Pair>"); sb.AppendLine(@" <key>highlight</key>"); sb.AppendLine(@" <styleUrl>#sh_grn-pushpin</styleUrl>"); sb.AppendLine(@" </Pair>"); sb.AppendLine(@" </StyleMap>"); sb.AppendLine(@" <Style id=""sh_grn-pushpin"">"); sb.AppendLine(@" <IconStyle>"); sb.AppendLine(@" <scale>1.3</scale>"); sb.AppendLine(@" <Icon>"); sb.AppendLine(@" <href>http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png</href>"); sb.AppendLine(@" </Icon>"); sb.AppendLine(@" <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"); sb.AppendLine(@" </IconStyle>"); sb.AppendLine(@" <ListStyle>"); sb.AppendLine(@" </ListStyle>"); sb.AppendLine(@" <LineStyle>"); sb.AppendLine(@" <color>ffff00ff</color>"); sb.AppendLine(@" </LineStyle>"); sb.AppendLine(@" <PolyStyle>"); sb.AppendLine(@" <fill>0</fill>"); sb.AppendLine(@" </PolyStyle>"); sb.AppendLine(@" </Style>"); sb.AppendLine(@" <StyleMap id=""m_ylw-pushpin"">"); sb.AppendLine(@" <Pair>"); sb.AppendLine(@" <key>normal</key>"); sb.AppendLine(@" <styleUrl>#s_ylw-pushpin</styleUrl>"); sb.AppendLine(@" </Pair>"); sb.AppendLine(@" <Pair>"); sb.AppendLine(@" <key>highlight</key>"); sb.AppendLine(@" <styleUrl>#s_ylw-pushpin_hl</styleUrl>"); sb.AppendLine(@" </Pair>"); sb.AppendLine(@" </StyleMap>"); sb.AppendLine(@" <Style id=""sn_grn-pushpin"">"); sb.AppendLine(@" <IconStyle>"); sb.AppendLine(@" <scale>1.1</scale>"); sb.AppendLine(@" <Icon>"); sb.AppendLine(@" <href>http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png</href>"); sb.AppendLine(@" </Icon>"); sb.AppendLine(@" <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"); sb.AppendLine(@" </IconStyle>"); sb.AppendLine(@" <ListStyle>"); sb.AppendLine(@" </ListStyle>"); sb.AppendLine(@" <LineStyle>"); sb.AppendLine(@" <color>ffff00ff</color>"); sb.AppendLine(@" </LineStyle>"); sb.AppendLine(@" <PolyStyle>"); sb.AppendLine(@" <fill>0</fill>"); sb.AppendLine(@" </PolyStyle>"); sb.AppendLine(@" </Style>"); sb.AppendLine(@" <Style id=""s_ylw-pushpin_hl"">"); sb.AppendLine(@" <IconStyle>"); sb.AppendLine(@" <scale>1.3</scale>"); sb.AppendLine(@" <Icon>"); sb.AppendLine(@" <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>"); sb.AppendLine(@" </Icon>"); sb.AppendLine(@" <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"); sb.AppendLine(@" </IconStyle>"); sb.AppendLine(@" <LineStyle>"); sb.AppendLine(@" <color>ffff00ff</color>"); sb.AppendLine(@" </LineStyle>"); sb.AppendLine(@" <PolyStyle>"); sb.AppendLine(@" <fill>0</fill>"); sb.AppendLine(@" </PolyStyle>"); sb.AppendLine(@" </Style>"); using (CSSPDBEntities db = new CSSPDBEntities()) { for (int i = 0, count = Prov2Letter.Count; i < count; i++) { string Full = ProvFull[i]; TVItem tvItemProv = (from c in db.TVItems from cl in db.TVItemLanguages where c.TVItemID == cl.TVItemID && cl.TVText == Full select c).FirstOrDefault(); if (tvItemProv == null) { richTextBox1.AppendText("could not find " + ProvFull[i]); return; } sb.AppendLine(@" <Folder>"); sb.AppendLine(@" <name>" + Prov2Letter[i] + "</name>"); string prov = Prov2Letter[i]; List <TideLocation> tideLocationList = (from c in db.TideLocations where c.Prov == prov && c.Lat != 0 select c).ToList(); foreach (TideLocation tideLocation in tideLocationList) { button7.Text = tideLocation.sid.ToString(); button7.Refresh(); Application.DoEvents(); sb.AppendLine(@" <Placemark>"); sb.AppendLine(@" <name>" + tideLocation.sid + "," + tideLocation.Name + "</name>"); sb.AppendLine(@" <styleUrl>#msn_grn-pushpin</styleUrl>"); sb.AppendLine(@" <Point>"); sb.AppendLine(@" <coordinates>" + tideLocation.Lng + "," + tideLocation.Lat + ",0 </coordinates>"); sb.AppendLine(@" </Point>"); sb.AppendLine(@" </Placemark>"); } sb.AppendLine(@" </Folder>"); } db.SaveChanges(); } sb.AppendLine(@" </Document>"); sb.AppendLine(@"</kml>"); FileInfo fi = new FileInfo(@"c:\WindowsFormsApplication1\WindowsFormsApplication1\TideLocation.kml"); StreamWriter sw = fi.CreateText(); sw.Write(sb.ToString()); sw.Close(); }
private void button6_Click(object sender, EventArgs e) { List <string> Prov2Letter = new List <string>() { "BC", "NB", "NL", "NS", "PE", "QC" }; List <string> ProvFull = new List <string>() { "British Columbia", "New Brunswick", "Newfoundland and Labrador", "Nova Scotia", "Prince Edward Island", "Québec" }; StringBuilder sb = new StringBuilder(); StringBuilder sbRTB = new StringBuilder(); sb.AppendLine(@"<?xml version=""1.0"" encoding=""UTF-8""?>"); sb.AppendLine(@"<kml xmlns=""http://www.opengis.net/kml/2.2"" xmlns:gx=""http://www.google.com/kml/ext/2.2"" xmlns:kml=""http://www.opengis.net/kml/2.2"" xmlns:atom=""http://www.w3.org/2005/Atom"">"); sb.AppendLine(@" <Document>"); sb.AppendLine(@" <name>Subsector and Tide Location</name>"); sb.AppendLine(@" <Style id=""s_ylw-pushpin"">"); sb.AppendLine(@" <IconStyle>"); sb.AppendLine(@" <scale>1.1</scale>"); sb.AppendLine(@" <Icon>"); sb.AppendLine(@" <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>"); sb.AppendLine(@" </Icon>"); sb.AppendLine(@" <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"); sb.AppendLine(@" </IconStyle>"); sb.AppendLine(@" <LineStyle>"); sb.AppendLine(@" <color>ffff00ff</color>"); sb.AppendLine(@" </LineStyle>"); sb.AppendLine(@" <PolyStyle>"); sb.AppendLine(@" <fill>0</fill>"); sb.AppendLine(@" </PolyStyle>"); sb.AppendLine(@" </Style>"); sb.AppendLine(@" <StyleMap id=""msn_grn-pushpin"">"); sb.AppendLine(@" <Pair>"); sb.AppendLine(@" <key>normal</key>"); sb.AppendLine(@" <styleUrl>#sn_grn-pushpin</styleUrl>"); sb.AppendLine(@" </Pair>"); sb.AppendLine(@" <Pair>"); sb.AppendLine(@" <key>highlight</key>"); sb.AppendLine(@" <styleUrl>#sh_grn-pushpin</styleUrl>"); sb.AppendLine(@" </Pair>"); sb.AppendLine(@" </StyleMap>"); sb.AppendLine(@" <Style id=""sh_grn-pushpin"">"); sb.AppendLine(@" <IconStyle>"); sb.AppendLine(@" <scale>1.3</scale>"); sb.AppendLine(@" <Icon>"); sb.AppendLine(@" <href>http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png</href>"); sb.AppendLine(@" </Icon>"); sb.AppendLine(@" <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"); sb.AppendLine(@" </IconStyle>"); sb.AppendLine(@" <ListStyle>"); sb.AppendLine(@" </ListStyle>"); sb.AppendLine(@" <LineStyle>"); sb.AppendLine(@" <color>ffff00ff</color>"); sb.AppendLine(@" </LineStyle>"); sb.AppendLine(@" <PolyStyle>"); sb.AppendLine(@" <fill>0</fill>"); sb.AppendLine(@" </PolyStyle>"); sb.AppendLine(@" </Style>"); sb.AppendLine(@" <StyleMap id=""m_ylw-pushpin"">"); sb.AppendLine(@" <Pair>"); sb.AppendLine(@" <key>normal</key>"); sb.AppendLine(@" <styleUrl>#s_ylw-pushpin</styleUrl>"); sb.AppendLine(@" </Pair>"); sb.AppendLine(@" <Pair>"); sb.AppendLine(@" <key>highlight</key>"); sb.AppendLine(@" <styleUrl>#s_ylw-pushpin_hl</styleUrl>"); sb.AppendLine(@" </Pair>"); sb.AppendLine(@" </StyleMap>"); sb.AppendLine(@" <Style id=""sn_grn-pushpin"">"); sb.AppendLine(@" <IconStyle>"); sb.AppendLine(@" <scale>1.1</scale>"); sb.AppendLine(@" <Icon>"); sb.AppendLine(@" <href>http://maps.google.com/mapfiles/kml/pushpin/grn-pushpin.png</href>"); sb.AppendLine(@" </Icon>"); sb.AppendLine(@" <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"); sb.AppendLine(@" </IconStyle>"); sb.AppendLine(@" <ListStyle>"); sb.AppendLine(@" </ListStyle>"); sb.AppendLine(@" <LineStyle>"); sb.AppendLine(@" <color>ffff00ff</color>"); sb.AppendLine(@" </LineStyle>"); sb.AppendLine(@" <PolyStyle>"); sb.AppendLine(@" <fill>0</fill>"); sb.AppendLine(@" </PolyStyle>"); sb.AppendLine(@" </Style>"); sb.AppendLine(@" <Style id=""s_ylw-pushpin_hl"">"); sb.AppendLine(@" <IconStyle>"); sb.AppendLine(@" <scale>1.3</scale>"); sb.AppendLine(@" <Icon>"); sb.AppendLine(@" <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>"); sb.AppendLine(@" </Icon>"); sb.AppendLine(@" <hotSpot x=""20"" y=""2"" xunits=""pixels"" yunits=""pixels""/>"); sb.AppendLine(@" </IconStyle>"); sb.AppendLine(@" <LineStyle>"); sb.AppendLine(@" <color>ffff00ff</color>"); sb.AppendLine(@" </LineStyle>"); sb.AppendLine(@" <PolyStyle>"); sb.AppendLine(@" <fill>0</fill>"); sb.AppendLine(@" </PolyStyle>"); sb.AppendLine(@" </Style>"); using (CSSPDBEntities db = new CSSPDBEntities()) { for (int i = 0, count = Prov2Letter.Count; i < count; i++) { string Full = ProvFull[i]; TVItem tvItemProv = (from c in db.TVItems from cl in db.TVItemLanguages where c.TVItemID == cl.TVItemID && cl.TVText == Full select c).FirstOrDefault(); if (tvItemProv == null) { richTextBox1.AppendText("could not find " + ProvFull[i]); return; } var tvItemList = (from c in db.TVItems from cl in db.TVItemLanguages where c.TVItemID == cl.TVItemID && c.TVPath.StartsWith(tvItemProv.TVPath + "p") && c.TVType == 20 && cl.Language == "en" orderby cl.TVText select new { c, cl }).ToList(); sb.AppendLine(@" <Folder>"); sb.AppendLine(@" <name>" + Prov2Letter[i] + "</name>"); foreach (var tvItem in tvItemList) { button6.Text = tvItem.cl.TVText; button6.Refresh(); Application.DoEvents(); List <MapInfoPoint> mapInfoPointList = (from c in db.MapInfos from p in db.MapInfoPoints where c.MapInfoID == p.MapInfoID && c.TVItemID == tvItem.c.TVItemID && c.TVType == 20 && c.MapInfoDrawType == 3 // polygon select p).ToList(); if (mapInfoPointList.Count == 0) { continue; } sb.AppendLine(@" <Folder>"); sb.AppendLine(@" <name>" + tvItem.cl.TVText + "</name>"); sb.AppendLine(@" <Placemark>"); sb.AppendLine(@" <name>" + tvItem.cl.TVText + "</name>"); sb.AppendLine(@" <styleUrl>#m_ylw-pushpin</styleUrl>"); sb.AppendLine(@" <Polygon>"); sb.AppendLine(@" <outerBoundaryIs>"); sb.AppendLine(@" <LinearRing>"); sb.AppendLine(@" <coordinates>"); foreach (MapInfoPoint mapInfoPoint in mapInfoPointList) // should only be 1 { sb.Append(mapInfoPoint.Lng + "," + mapInfoPoint.Lat + ",0 "); } sb.AppendLine(@" </coordinates>"); sb.AppendLine(@" </LinearRing>"); sb.AppendLine(@" </outerBoundaryIs>"); sb.AppendLine(@" </Polygon>"); sb.AppendLine(@" </Placemark>"); mapInfoPointList = (from c in db.MapInfos from p in db.MapInfoPoints where c.MapInfoID == p.MapInfoID && c.TVItemID == tvItem.c.TVItemID && c.TVType == 20 && c.MapInfoDrawType == 1 // point, 3 polygon select p).ToList(); if (mapInfoPointList.Count == 0) { continue; } sb.AppendLine(@" <Placemark>"); sb.AppendLine(@" <name>" + tvItem.cl.TVText + "</name>"); sb.AppendLine(@" <styleUrl>#m_ylw-pushpin</styleUrl>"); sb.AppendLine(@" <Point>"); foreach (MapInfoPoint mapInfoPoint in mapInfoPointList) // should only be 1 { sb.AppendLine(@" <coordinates>" + mapInfoPoint.Lng + "," + mapInfoPoint.Lat + ",0 </coordinates>"); } sb.AppendLine(@" </Point>"); sb.AppendLine(@" </Placemark>"); double factor = 0.01D; List <TideLocation> tideLocationList = new List <TideLocation>(); while (tideLocationList.Count < 3) { double MinLat = mapInfoPointList[0].Lat - factor; double MaxLat = mapInfoPointList[0].Lat + factor; double MinLng = mapInfoPointList[0].Lng - factor; double MaxLng = mapInfoPointList[0].Lng + factor; string prov = Prov2Letter[i]; List <TideLocation> tideLocationTempList = (from c in db.TideLocations where c.Lat != 0 && c.Lat > MinLat && c.Lat <MaxLat && c.Lng> MinLng && c.Lng < MaxLng select c).ToList(); foreach (TideLocation tideLocation in tideLocationTempList) { if (!tideLocationList.Contains(tideLocation)) { tideLocationList.Add(tideLocation); } } factor += 0.01D; } sbRTB.Append("" + tvItem.c.TVItemID + "\t" + tvItem.cl.TVText + "\t"); foreach (TideLocation tideLocation in tideLocationList) { sbRTB.Append("" + tideLocation.sid + "," + tideLocation.Name + "\t"); sb.AppendLine(@" <Placemark>"); sb.AppendLine(@" <name>" + tideLocation.sid + "," + tideLocation.Name + "</name>"); sb.AppendLine(@" <styleUrl>#msn_grn-pushpin</styleUrl>"); sb.AppendLine(@" <Point>"); sb.AppendLine(@" <coordinates>" + tideLocation.Lng + "," + tideLocation.Lat + ",0 </coordinates>"); sb.AppendLine(@" </Point>"); sb.AppendLine(@" </Placemark>"); } sbRTB.AppendLine(""); sb.AppendLine(@" </Folder>"); } sb.AppendLine(@" </Folder>"); } db.SaveChanges(); } sb.AppendLine(@" </Document>"); sb.AppendLine(@"</kml>"); FileInfo fi = new FileInfo(@"c:\WindowsFormsApplication1\WindowsFormsApplication1\SubsectorAndTideLocation.kml"); StreamWriter sw = fi.CreateText(); sw.Write(sb.ToString()); sw.Close(); richTextBox1.Text = sbRTB.ToString(); }