public static geKML ToKML(IEnumerable <Location> locations) { geDocument doc = new geDocument(); doc.Name = "Locations exported"; foreach (var loc in locations) { gePlacemark pm = new gePlacemark(); //Create some coordinates for the point at which //this placemark will sit. (Lat / Lon) geCoordinates coords = new geCoordinates(new geAngle90(loc.Latitude), new geAngle180(loc.Longitude)); //Create a point with these new coordinates gePoint point = new gePoint(coords); //Assign the point to the Geometry property of the //placemark. pm.Geometry = point; //Now lets add some other properties to our placemark pm.Name = loc.Name; pm.Description = "Visit at: " + loc.Time.ToString(); //Finally, add the placemark to the document doc.Features.Add(pm); } //Now that we have our document, lets create our KML geKML kml = new geKML(doc); return(kml); }
public static geKML RunExample(string FileName) { // Use a Document as the root of the KML geDocument doc = new geDocument(); doc.Name = "My Root Document"; // Create a new style to be added the doc geStyle myStyle = new geStyle("myStyle"); //add a new IconStyle to the style myStyle.IconStyle = new geIconStyle(); myStyle.IconStyle.Icon = new geIcon("Example2.png"); myStyle.IconStyle.Scale = 2F; //or (float)2 //Add the style doc.StyleSelectors.Add(myStyle); //Create a Placemark to put in the document //This placemark is going to be a point //but it could be anything in the Geometry class gePlacemark pm = new gePlacemark(); //Create some coordinates for the point at which //this placemark will sit. (Lat / Lon) geCoordinates coords = new geCoordinates( new geAngle90(37.422067), new geAngle180(-122.084437)); //Create a point with these new coordinates gePoint point = new gePoint(coords); //Assign the point to the Geometry property of the //placemark. pm.Geometry = point; //Set the placemark's style to the style we created above pm.StyleUrl = "#myStyle"; //Now lets add some other properties to our placemark pm.Name = "My Placemark"; pm.Snippet = "This is where I put my Placemark"; pm.Description = "I wonder where this is...GOOGLE!"; //Finally, add the placemark to the document doc.Features.Add(pm); //Now that we have our document, lets create our KML geKML kml = new geKML(doc); //Add supporting files to the KMZ (assuming it's going to be rendered as KMZ byte[] myFile = File.ReadAllBytes(AppDomain.CurrentDomain.BaseDirectory + "\\images\\Example2.png"); kml.Files.Add("Example2.png", myFile); return(kml); }
public static string AsKML(this SqlGeography geog, string docname, string pname, string description) { Utilities u = new Utilities(); if (u.IsNullOrEmpty(geog)) { return(""); } geDocument doc = u.SqlGeogInstanceToKmlDoc(geog, docname, pname, description); geKML kml = new geKML(doc); return(System.Text.Encoding.ASCII.GetString(kml.ToKML())); }
public static geKML RunExample(string FileName) { Utilities util = new Utilities(); // Point geFolder fld = util.SqlGeogCommandToKmlFolder( "server=.;database=geonames;integrated security=sspi", "select top(10) geog, name from geonames", "Sample Folder"); //Now that we have our document, lets create our KML geKML kml = new geKML(fld); return(kml); }
public static geKML RunExample(string FileName) { Utilities util = new Utilities(); // Point /* * geDocument doc = util.SqlGeogCommandToKmlDoc("SQL Server Spatial Sample Doc", * "server=.;database=geonames;integrated security=sspi", * "select top(1) geog, name from geonames"); * * // LineString * geDocument doc = util.SqlGeogCommandToKmlDoc("SQL Server Spatial Sample Doc", * "server=.;database=Sample_USA;integrated security=sspi", * "select geog, signt + ' ' + signn from Highways where id = 1132"); */ // Polygon /* * geDocument doc = util.SqlGeogCommandToKmlDoc("SQL Server Spatial Sample Doc", * "server=.;database=Sample_USA;integrated security=sspi", * "select geog, name_2 from counties where id = 847"); */ // Multi-ring polygon /* * geDocument doc = util.SqlGeogCommandToKmlDoc("SQL Server Spatial Sample Doc", * "server=.;database=SpatialSamples;integrated security=sspi", * "select geog, cntry_name from cntry00 where fips_cntry = 'WE'"); */ // MultiLineString geDocument doc = util.SqlGeogCommandToKmlDoc("SQL Server Spatial Sample Doc", " Data Source=localhost;Initial Catalog=JiangMengGnInterface;Integrated Security=True", "select geom,cell from MCOMSite_region where id=1"); //Now that we have our document, lets create our KML geKML kml = new geKML(doc); return(kml); }
public static geKML RunExample(string FileName) { // Use a Document as the root of the KML geDocument doc = new geDocument(); doc.Name = "My Root Document"; //Create a Placemark to put in the document //This placemark is going to be a point //but it could be anything in the Geometry class gePlacemark pm = new gePlacemark(); //Create some coordinates for the point at which //this placemark will sit. (Lat / Lon) geCoordinates coords = new geCoordinates( new geAngle90(37.422067), new geAngle180(-122.084437)); //Create a point with these new coordinates gePoint point = new gePoint(coords); //Assign the point to the Geometry property of the //placemark. pm.Geometry = point; //Now lets add some other properties to our placemark pm.Name = "My Placemark"; pm.Snippet = "This is where I put my Placemark"; pm.Description = "I wonder where this is..."; //Finally, add the placemark to the document doc.Features.Add(pm); //Now that we have our document, lets create our KML geKML kml = new geKML(doc); return(kml); }
public void Generate(string path, ProgressBar pBar) { //generates document at path. shows progress using progressbar pBar this.Path = path; kmlDocument.Name = System.IO.Path.GetFileName(path);; kmlDocument.StyleSelectors.Add(defaultStyle); //create a step in the progressbar for each layer int nrLayers = kmlLayers.Count; pBar.Minimum = 0; pBar.Maximum = nrLayers + 1; pBar.Step = 1; //should generate a kml document at path... //first, iterate layers. Each layer makes a folder foreach (LayerProperties lp in kmlLayers) { //create a folder for the layer geFolder folder = new geFolder(); folder.Name = lp.name; folder.Open = true; folder.Description = lp.Layeru.Name; processLayerProperties(lp, folder); kmlDocument.Features.Add(folder); pBar.PerformStep(); } //no more layers, get document :) geKML kml = new geKML(kmlDocument); File.WriteAllBytes(path, kml.ToKML()); pBar.PerformStep(); //ProcessStartInfo psInfNotepad = new ProcessStartInfo("notepad.exe", path); //Process.Start(psInfNotepad); }
public static geKML RunExample(string FileName) { // Use a Document as the root of the KML geDocument doc = new geDocument(); doc.Name = "My Root Document"; gePlacemark pm = new gePlacemark(); //Always complete the boundary by adding an end point that matches your beginning point List <geCoordinates> outerCoords = new List <geCoordinates>(); outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-114))); outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-108))); outerCoords.Add(new geCoordinates(new geAngle90(31), new geAngle180(-108))); outerCoords.Add(new geCoordinates(new geAngle90(31), new geAngle180(-114))); outerCoords.Add(new geCoordinates(new geAngle90(37), new geAngle180(-114))); List <geCoordinates> innerCoords1 = new List <geCoordinates>(); innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-113))); innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-112))); innerCoords1.Add(new geCoordinates(new geAngle90(35), new geAngle180(-112))); innerCoords1.Add(new geCoordinates(new geAngle90(35), new geAngle180(-113))); innerCoords1.Add(new geCoordinates(new geAngle90(36), new geAngle180(-113))); List <geCoordinates> innerCoords2 = new List <geCoordinates>(); innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-113))); innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-112))); innerCoords2.Add(new geCoordinates(new geAngle90(33), new geAngle180(-112))); innerCoords2.Add(new geCoordinates(new geAngle90(33), new geAngle180(-113))); innerCoords2.Add(new geCoordinates(new geAngle90(34), new geAngle180(-113))); geOuterBoundaryIs outer = new geOuterBoundaryIs(new geLinearRing(outerCoords)); gePolygon poly = new gePolygon(outer); geInnerBoundaryIs inner1 = new geInnerBoundaryIs(new geLinearRing(innerCoords1)); geInnerBoundaryIs inner2 = new geInnerBoundaryIs(new geLinearRing(innerCoords2)); poly.InnerBoundaries.Add(inner1); poly.InnerBoundaries.Add(inner2); pm.Geometry = poly; doc.Features.Add(pm); //Lets add a Line somewhere too... geStyle myLineStyle = new geStyle("myLineStyle"); myLineStyle.LineStyle = new geLineStyle(); myLineStyle.LineStyle.Color.SysColor = Color.Yellow; myLineStyle.LineStyle.Width = 4; //This may or may not work, depends on the end user's video card doc.StyleSelectors.Add(myLineStyle); gePlacemark pmLine = new gePlacemark(); pmLine.StyleUrl = "#myLineStyle"; pmLine.Name = "Example Line"; pmLine.Description = "Some description"; List <geCoordinates> lineCoords = new List <geCoordinates>(); lineCoords.Add(new geCoordinates(new geAngle90(35), new geAngle180(-117))); lineCoords.Add(new geCoordinates(new geAngle90(35), new geAngle180(-106))); geLineString line = new geLineString(lineCoords); pmLine.Geometry = line; doc.Features.Add(pmLine); //Now that we have our document, lets create our KML geKML kml = new geKML(doc); return(kml); }
void _analyze_Click(object sender, EventArgs e) { IPhoneBackup backup = SelectedBackup; IPhoneApp app = backup.GetApps().FirstOrDefault(t => t.Name == "System"); IPhoneFile dbFile = app.Files.FirstOrDefault(t => t.Path.Contains("consolidated")); IEnumerable <IPhoneFile> imgs = app.Files.Where(t => t.Path.Contains("DCIM/100APPLE") && t.Domain == "MediaDomain"); FileInfo fileInfo = FileManager.GetWorkingFile(backup, dbFile); Model.InvokeAsync(delegate(object w, DoWorkEventArgs a) { BackgroundWorker worker = w as BackgroundWorker; if (!worker.CancellationPending) { List <Location> locations = new List <Location>(); using (SQLiteConnection con = new SQLiteConnection(@"Data Source=" + fileInfo.FullName)) { con.Open(); var cmd = new SQLiteCommand(); cmd.Connection = con; cmd.CommandText = "SELECT * FROM WifiLocation;"; var reader = cmd.ExecuteReader(); while (reader.Read()) { locations.Add(new Location { Name = "[Wifi] MAC: " + reader.GetString(0), Time = new DateTime(2001, 1, 1, 0, 0, 0).AddSeconds(reader.GetDouble(1)), Latitude = reader.GetDouble(2), Longitude = reader.GetDouble(3) }); } reader.Close(); worker.ReportProgress(33); cmd.CommandText = "SELECT * FROM CellLocation"; reader = cmd.ExecuteReader(); while (reader.Read()) { locations.Add(new Location { Name = "[Cell] MCC: " + reader.GetInt32(0) + " MNC: " + reader.GetInt32(1) + " LAC: " + reader.GetInt32(2) + " CELL ID:" + reader.GetInt32(3), Time = new DateTime(2001, 1, 1, 0, 0, 0).AddSeconds(reader.GetDouble(4)), Latitude = reader.GetDouble(5), Longitude = reader.GetDouble(6) }); } worker.ReportProgress(33); } //Gives incorrect results.. FIXIT //int count = imgs.Count() + 66, current = 66; //foreach (IPhoneFile file in imgs) //{ // FileInfo info = FileManager.GetWorkingFile(backup, file); // ExifTagCollection er = new ExifTagCollection(info.FullName); // //not working... // Location location = new Location(); // double lat = 0, lon = 0; // foreach (ExifTag tag in er) // { // if (tag.FieldName == "GPSLatitude") // { // string dec = Regex.Match(tag.Value, @"\d+\.\d+").ToString(); // double.TryParse(dec, out lat); // } // else if (tag.FieldName == "GPSLongitude") // { // string dec = Regex.Match(tag.Value, @"\d+\.\d+").ToString(); // double.TryParse(dec, out lon); // } // } // location.Latitude = lat; // location.Longitude = lon; // location.Name = "[Image] " + info.Name; // locations.Add(location); // worker.ReportProgress(Util.Percent(current++, count)); //} geKML kml = Location.ToKML(locations.OrderBy(x => x.Time)); a.Result = kml; } else { a.Cancel = true; return; } }, delegate(object w, RunWorkerCompletedEventArgs a) { geKML kml = a.Result as geKML; FileDialog dialog = new SaveFileDialog(); dialog.DefaultExt = "kmz"; dialog.FileName = "locations.kmz"; dialog.Filter = "Google earth|*.kmz"; if (dialog.ShowDialog(Model.Window) == DialogResult.OK) { using (FileStream s = new FileStream(dialog.FileName, FileMode.Create)) { using (BinaryWriter wr = new BinaryWriter(s)) { wr.Write(kml.ToKMZ()); } } } }, "Analyzing location", false); }
// This method is to be called once all the targets // are loaded via AddNewTarget. Once KML is created the list // will be emptied. public void BuildKML() { string exampleFileName = ""; string exampleFileExt = "kmz"; string file_name = "ASTX_TO_KML"; // Use a Document as the root of the KML geDocument doc = new geDocument(); doc.Name = "Asterix to KML"; // Create a new style to be added the doc geStyle myStyle = new geStyle("myStyle"); //add a new IconStyle to the style myStyle.IconStyle = new geIconStyle(); myStyle.IconStyle.Icon = new geIcon("ac_image.png"); myStyle.IconStyle.Scale = 1.0F; //or (float)1 myStyle.LabelStyle = new geLabelStyle(); myStyle.LabelStyle.Color.SysColor = Color.White; myStyle.LineStyle = new geLineStyle(); myStyle.LineStyle.Color.SysColor = Color.Black; myStyle.LineStyle.Width = 4; //Add the style doc.StyleSelectors.Add(myStyle); foreach (DynamicDisplayBuilder.TargetType Target in TargetList) { //Create a Placemark to put in the document //This placemark is going to be a point //but it could be anything in the Geometry class gePlacemark pm = new gePlacemark(); //Create some coordinates for the point at which //this placemark will sit. (Lat / Lon) geCoordinates coords = new geCoordinates( new geAngle90(Target.Lat), new geAngle180(Target.Lon)); double LevelInMeeters = 0.0; // Assign the altitude if (Target.ModeC != null) { if (Target.ModeC != "---") { LevelInMeeters = (double.Parse(Target.ModeC) * 100.00) * SharedData.FeetToMeeters; } } coords.Altitude = (float)LevelInMeeters; //Create a point with these new coordinates gePoint point = new gePoint(coords); point.AltitudeMode = geAltitudeModeEnum.absolute; point.Extrude = true; //Assign the point to the Geometry property of the //placemark. pm.Geometry = point; //Set the placemark's style to the style we created above pm.StyleUrl = "#myStyle"; if (Properties.Settings.Default.GE_Show_ModeA) { pm.Name = Target.ModeA; } if (Properties.Settings.Default.GE_Show_ModeC) { if (Properties.Settings.Default.Show_ModeC_as_FL) { pm.Name = pm.Name + " " + "FL:" + Target.ModeC; } else { pm.Name = pm.Name + " " + LevelInMeeters.ToString() + "m"; } } if (Properties.Settings.Default.GE_Show_ModeC) { pm.Name = pm.Name + " " + Target.ACID_Mode_S; } pm.Snippet = "Snipet Test"; pm.Description = "Blaa Bla Blaaaa"; //Finally, add the placemark to the document doc.Features.Add(pm); } geKML kml = new geKML(doc); //Add supporting files to the KMZ (assuming it's going to be rendered as KMZ byte[] myFile = File.ReadAllBytes(@"C:\ASTERIX\GE\ac_image.png"); kml.Files.Add("ac_image.png", myFile); exampleFileName = Properties.Settings.Default.GE_Dest_Path + "\\" + file_name + "." + exampleFileExt; File.WriteAllBytes(exampleFileName, kml.ToKMZ()); // Clear the list TargetList.Clear(); }
public static geKML RunExample(string FileName) { // Use a Document as the root of the KML geDocument doc = new geDocument(); doc.Name = "My Root Document"; /* * * //Create a Placemark to put in the document * //This placemark is going to be a point * //but it could be anything in the Geometry class * gePlacemark pm = new gePlacemark(); * * //Create some coordinates for the point at which * //this placemark will sit. (Lat / Lon) * geCoordinates coords = new geCoordinates( * new geAngle90(37.422067), * new geAngle180(-122.084437)); * * //Create a point with these new coordinates * gePoint point = new gePoint(coords); * * //Assign the point to the Geometry property of the * //placemark. * pm.Geometry = point; * * //Now lets add some other properties to our placemark * pm.Name = "My Placemark"; * pm.Snippet = "This is where I put my Placemark"; * pm.Description = * "I wonder where this is..."; */ Utilities util = new Utilities(); // Point /* * gePlacemark pm = util.SqlGeogCommandToKmlPlacemark( * "server=.;database=geonames;integrated security=sspi", * "select top(1) geog, name from geonames"); * * // LineString * gePlacemark pm = util.SqlGeogCommandToKmlPlacemark( * "server=.;database=Sample_USA;integrated security=sspi", * "select geog, signt + ' ' + signn from Highways where id = 1132"); */ // Polygon /* * gePlacemark pm = util.SqlGeogCommandToKmlPlacemark( * "server=.;database=Sample_USA;integrated security=sspi", * "select geog, name_2 from counties where id = 847"); */ // Multi-ring polygon /* * gePlacemark pm = util.SqlGeogCommandToKmlPlacemark( * "server=.;database=SpatialSamples;integrated security=sspi", * "select geog, cntry_name from cntry00 where fips_cntry = 'WE'"); */ // MultiLineString gePlacemark pm = util.SqlGeogCommandToKmlPlacemark( "server=.;database=Sample_USA;integrated security=sspi", "select geog, signt + ' ' + signn from Highways where id = 6315"); //Finally, add the placemark to the document doc.Features.Add(pm); //Now that we have our document, lets create our KML geKML kml = new geKML(doc); return(kml); }