示例#1
0
 public void TestMethodWithPartiallyFillTileReturnsEmptyStringId()
 {
     using (var utfGrid = new Utf8Grid(1, 1, 1, 1))
     {
         var graphics = utfGrid.CreateGraphics();
         var brush    = Utf8Grid.CreateBrush(5);
         graphics.FillRectangle(brush, 0, 0, 10, 10);
         var json = utfGrid.CreateUtfGridJson();
         Assert.AreEqual(2, utfGrid.Keys.Count);
         Assert.AreEqual("", utfGrid.Keys[0]);
         Assert.AreEqual("5", utfGrid.Keys[1]);
     }
 }
示例#2
0
 public void TestMethod2()
 {
     for (int i = 255; i < 300; i = i + 1)
     {
         using (var utfGrid = new Utf8Grid(1, 1, 1, 1))
             using (var graphics = utfGrid.CreateGraphics())
                 using (var brush = Utf8Grid.CreateBrush(i))
                 {
                     graphics.FillRectangle(brush, 0, 0, 256, 256);
                     var json = utfGrid.CreateUtfGridJson();
                     Assert.AreEqual(1, utfGrid.Keys.Count, "With i=" + i.ToString());
                     Assert.AreEqual(i.ToString(), utfGrid.Keys[0], "With i=" + i.ToString());
                 }
     }
 }
示例#3
0
        public JsonResult GetData(string layer, int z, int x, int y)
        {
            if (String.IsNullOrEmpty(layer))
            {
                throw new ArgumentNullException("layer");
            }

            Map map = ShapefileHelper.Spherical();
            IQueryable <VectorLayer> coll = map.Layers
                                            .AsQueryable()
                                            .OfType <VectorLayer>()
                                            .Where(l => l.Enabled && l.IsQueryEnabled)
                                            .Where(l => String.Equals(l.LayerName, layer));
            VectorLayer query = coll.SingleOrDefault();

            if (query == null)
            {
                throw new ArgumentException("Layer not found: " + layer);
            }

            if (query.SRID != 4326)
            {
                throw new ArgumentException("Only EPSG:4326 supported");
            }

            using (Utf8Grid grid = new Utf8Grid(UtfGridResolution, x, y, z))
            {
                Envelope bbox = this.GetBoundingBoxInLatLngWithMargin(x, y, z);
                var      ds   = new FeatureCollectionSet();
                query.ExecuteIntersectionQuery(bbox, ds);
                IEnumerable <GeoJSON> data = GeoJSONHelper.GetData(ds);

                int i = 1;
                foreach (GeoJSON val in data)
                {
                    IGeometry geom = val.Geometry;
                    IDictionary <string, object> dict = val.Values;
                    grid.FillPolygon(geom, i, dict);
                    i = i + 1;
                }

                Utf8GridResults results = grid.CreateUtfGridJson();
                return(this.Json(new { keys = results.Keys, data = results.Data, grid = results.Grid, }, JsonRequestBehavior.AllowGet));
            }
        }
示例#4
0
        public ActionResult States(int x, int y, int z)
        {
            var key        = string.Format(@"states\{0}\{1}\{1}", x, y, z);
            var cachedJson = this.HttpContext.Cache[key] as string;

            if (cachedJson != null)
            {
                return(new ContentResult()
                {
                    Content = cachedJson, ContentType = "application/json"
                });
            }

            const int utfgridResolution = 2;

            using (var utf8Grid = new Utf8Grid(utfgridResolution, x, y, z))
            {
                var bbox = GetBoundingBoxInLatLngWithMargin(x, y, z);
                if (bbox.Bottom > 0)
                {
                    var states = new StatesRepository().Query(bbox.ToSqlGeography());
                    int i      = 1;
                    foreach (var state in states)
                    {
                        var geography = (SqlGeography)state["geom"];
                        var projected = ((SqlGeography)state["geom"]).FromLonLat().MakeValid();
                        var wkt       = projected.STAsText().ToSqlString().Value;
                        utf8Grid.FillPolygon(geography, i,
                                             new { NAME = state["STATE_NAME"], POP2005 = state["POP2000"], Wkt = wkt });
                        i = i + 1;
                    }
                }
                cachedJson = utf8Grid.CreateUtfGridJson();
                this.HttpContext.Cache.Insert(key, cachedJson);
                return(new ContentResult()
                {
                    Content = cachedJson, ContentType = "application/json"
                });
            }
        }