public XmlDocument getKML(int connID) { String serverPath = "http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"] + ":" + HttpContext.Current.Request.ServerVariables["SERVER_PORT"]; //create new connection a populate fields to get the connection name for KMLGenerator Connection conn = new Connection(connID); conn.populateFields(); string name = conn.getConnInfo().getConnectionName(); //create a new kml genereator with the connection name as the placemark name KMLGenerator kmlGen = new KMLGenerator(name, serverPath); string kml = ""; //generate the kml for the given connID try { kml = kmlGen.generateKML(connID); } catch (Exception e) { //if there was an error generating kml, return a kml file that contains only a screen overlay that states there was an error generating kml kml = "<ScreenOverlay> <name>KML Error</name> <Icon> <href>"+ serverPath + "/graphics/kml-error.png</href> </Icon> <overlayXY x=\"0.5\" y=\"0.5\" xunits=\"fraction\" yunits=\"fraction\"/> <screenXY x=\"0.5\" y=\"0.5\" xunits=\"fraction\" yunits=\"fraction\"/> <rotationXY x=\"0\" y=\"0\" xunits=\"fraction\" yunits=\"fraction\"/> <size x=\"1\" y=\"0.2\" xunits=\"fraction\" yunits=\"fraction\"/></ScreenOverlay>"; } //add the kml to an XMLDoc and return XmlDocument kmlDoc = new XmlDocument(); kmlDoc.LoadXml(kml); return(kmlDoc); }
public static void CrimeDataTest() { DataBase database = new DataBase(); m_dataBase = database; var watch0 = System.Diagnostics.Stopwatch.StartNew(); // TODO: takes 8895 ms for database small //AddDatasetSmall(database); // TODO: takes 34 seconds for load dataset1 AddDataset1(database); //AddDataset2(database); watch0.Stop(); Console.WriteLine("Process data takes " + watch0.ElapsedMilliseconds + " ms"); database.Display(); /// /// Test get coordinates in bounding box /// TODO: search coordinates in bbox take much more time than searching in bcircle var watch2 = System.Diagnostics.Stopwatch.StartNew(); var c2 = database.BboxCoordinates(41.85776407, -87.73420671, 41.89993156, -87.60380377, mLevel); watch2.Stop(); var elapsedMs2 = watch2.ElapsedMilliseconds; Console.WriteLine("BboxCoordinates, Time elapsed: " + elapsedMs2 + " ms | " + c2.Length + " results get"); KMLGenerator.GenerateKMLcoordinates(c2, "box coordinates"); /// /// Display search process /// /// /// Test get coordinates in bounding circle /// var watch = System.Diagnostics.Stopwatch.StartNew(); Coordinates[] c = database.BcircleCoordinates(mLat, mLon, mRadius, mLevel, mLimit); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Console.WriteLine("BcircleCoordinates, Time elapsed: " + elapsedMs + " ms | " + c.Length + " results get"); KMLGenerator.GenerateKMLcoordinates(c, "circle coordinates"); /// /// Display search process /// }
public static void BoundingCircleTest() { Coordinates c = new Coordinates { Lat = mLat, Lon = mLon }; Console.WriteLine("point latitude " + c.Lat + ", longitude " + c.Lon); var encoded = GeoHash.Encode(c.Lat, c.Lon, mLevel); Console.WriteLine("encoded = " + encoded); var decoded = GeoHash.Decode(encoded); var latitude = decoded.Coordinates.Lat; var longitude = decoded.Coordinates.Lon; Console.WriteLine("decoded box latitude " + latitude + ", longitude " + longitude); BoundingBox box = GeoHash.DecodeBbox(encoded); var maxLat = box.Maximum.Lat; var minLat = box.Minimum.Lat; var maxLon = box.Maximum.Lon; var minLon = box.Minimum.Lon; // Measure the box size in meters var oneSide = DataBase.Measure(maxLat, minLon, minLat, minLon); var anotherSide = DataBase.Measure(maxLat, maxLon, maxLat, minLon); // Bounding circle var watch = System.Diagnostics.Stopwatch.StartNew(); string[] hashList = DataBase.Bcircle(c.Lat, c.Lon, mRadius, mLevel); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; //foreach (var h in hashList) //{ // Console.WriteLine(h); //} Console.WriteLine("box size: " + oneSide + " meters * " + anotherSide + " meters"); Console.WriteLine("bounding circle radius " + mRadius + " meters, level " + mLevel); Console.WriteLine("Get bounding circle, time elapsed: " + elapsedMs + " ms | " + hashList.Length + " results get"); string filename = "bounding circle" + c.Lat.ToString() + "-" + c.Lon.ToString() + "-" + mRadius.ToString() + "-" + mLevel.ToString(); KMLGenerator.GenerateKMLBoundingCircle(hashList, c.Lat, c.Lon, mRadius, filename); Console.WriteLine("save as file name " + filename); }
public static void BoundingBoxTest() { // Bounding box Coordinates coor1 = new Coordinates { Lat = 41.85776407, Lon = -87.73420671 }; Coordinates coor2 = new Coordinates { Lat = 41.89993156, Lon = -87.60380377 }; var watch = System.Diagnostics.Stopwatch.StartNew(); string[] hashlist = GeoHash.Bboxes(coor1.Lat, coor1.Lon, coor2.Lat, coor2.Lon, mLevel); watch.Stop(); var elapsedMs = watch.ElapsedMilliseconds; Console.WriteLine("Get bounding box, time elapsed: " + elapsedMs + " ms | " + hashlist.Length + " results get"); KMLGenerator.GenerateKMLBoundingBoxes(hashlist, coor1, coor2, "bounding box"); }