Example #1
0
        public static LatLng FromHACoord(HACoord HACoord)
        {
            double x = HACoord.doubleX / 5.0 + 588086.0;
            double y = -HACoord.doubleY / 5.0 + 6140036.0;

            GPS.GPS.UTM utm = new GPS.GPS.UTM(y, x, 32);
            return(new LatLng(utm.Latitude.GetDecimalCoordinate(), utm.Longitude.GetDecimalCoordinate()));
        }
        public void ProcessRequest(HttpContext context)
        {
            string function = routeData.Values["function"].ToString();

            if (function == "" || function.Contains("/"))
            {
                context.Response.ContentType = "text/html";
                return;
            }

            Common.SendStats(context, "compute/" + function);
            switch (function)
            {
            case "getHACoord":
                decimal lat = decimal.Parse(context.Request.Params["latitude"], CultureInfo.InvariantCulture);
                decimal lng = decimal.Parse(context.Request.Params["longitude"], CultureInfo.InvariantCulture);
                Common.WriteOutput(HACoord.FromLatLng(new LatLng(lat, lng)), context);
                break;
            }
        }
Example #3
0
        private void GetHAGeos(HttpContext context, bool needDistance)
        {
            int tagscategory = -1; //all

            if (context.Request.Params["tagscategory"] != null)
            {
                Int32.TryParse(context.Request.Params["tagscategory"], out tagscategory);
            }

            string sqlTagSearch = "";

            if (!string.IsNullOrEmpty(context.Request.Params["includetags"]))
            {
                List <string> includeTags = new List <string>(context.Request.Params["includetags"].Split(new char[] { ',' }));
                sqlTagSearch = " AND GeoID IN (SELECT GeoID FROM Tag_Geo WHERE TagID IN (" + string.Join(",", includeTags) + "))";
            }

            string sqlOrderBy = "";

            if (center != null && llBox == null)
            {
                HACoord coord = HACoord.FromLatLng(center);
                sqlOrderBy = " ORDER BY POWER((GeoX - " + coord.x + ") / 10000.0, 2) + POWER((GeoY - " + coord.y + ") / 10000.0, 2)";
            }

            using (SqlConnection conn = new SqlConnection(WebConfigurationManager.ConnectionStrings["hadb"].ConnectionString))
            {
                conn.Open();

                var cmd = new SqlCommand("SELECT" + (count > -1 ? " TOP " + count : "") + " GeoID, Title, GeoX, GeoY FROM Geo WHERE Online = 1" + (llBox == null ? "" : " AND GeoX > " + HACoord.FromLatLng(llBox.llLatLng).x + " AND GeoX < " + HACoord.FromLatLng(llBox.urLatLng).x + " AND GeoY > " + HACoord.FromLatLng(llBox.urLatLng).y + " AND GeoY < " + HACoord.FromLatLng(llBox.llLatLng).y) + sqlTagSearch + sqlOrderBy, conn);

                using (SqlDataReader dr = cmd.ExecuteReader())
                {
                    while (dr.Read())
                    {
                        LatLng ll  = LatLng.FromHACoord(new HACoord((int)dr["GeoX"], (int)dr["GeoY"]));
                        Geo    geo = new Geo()
                        {
                            id = (int)dr["GeoID"], title = dr["Title"].ToString(), lat = ll.latitude, lng = ll.longitude
                        };

                        if (center != null && needDistance)
                        {
                            geo.distFromCenter = ll.Distance(center);
                        }

                        SqlCommand cmdTags;
                        if (tagscategory == -1)
                        {
                            cmdTags = new SqlCommand("SELECT TagID FROM Tag_Geo WHERE GeoID = " + geo.id, conn);
                        }
                        else
                        {
                            cmdTags = new SqlCommand("SELECT Tag_Geo.TagID FROM Tag_Geo, Tag WHERE Tag_Geo.TagID = Tag.TagID AND Tag.Category = " + tagscategory + " AND GeoID = " + geo.id, conn);
                        }

                        using (SqlDataReader drTags = cmdTags.ExecuteReader())
                            while (drTags.Read())
                            {
                                geo.tagids.Add((int)drTags["TagID"]);
                            }

                        geos.Add(geo);
                    }
                }
            }
        }