FillPolygon() public method

public FillPolygon ( SqlGeography geography, int i, object data = null ) : void
geography SqlGeography
i int
data object
return void
Esempio n. 1
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" };
            }
        }
        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);
                FeatureDataSet ds = new FeatureDataSet();
                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);
            }
        }