private void DoSomething() { double[] fullExent = new double[] { minX, minY, maxX, maxY }; for (int i = minZoom; i < maxZoom + 1; i++) { RowColumns rc = MapTool.GeRowColomns(fullExent, resolutions.ToArray(), i); k = 0; count = 0; this.cutDataJson(i); } }
/// <summary> /// 以arcgis的格式切片,进行切片行列号的获取 /// </summary> /// <param name="bounds">切片对应的区域大小,经纬度</param> /// <param name="origin">切片原点</param> /// <param name="resolution">分辨率</param> /// <returns>行列号</returns> public static RowColumns GetTileRowColomns(double[] bounds, double[] origin, double resolution) { double originTileX = (origin[0] + (resolution * tileSize[0])); double originTileY = (origin[1] - (resolution * tileSize[1])); double centerX = (bounds[0] + bounds[2]) / 2; double centerY = (bounds[1] + bounds[3]) / 2; int x = (int)(Math.Round(Math.Abs((centerX - originTileX) / (resolution * tileSize[0])))); int y = (int)(Math.Round(Math.Abs((originTileY - centerY) / (resolution * tileSize[1])))); RowColumns rc = new RowColumns(); rc.Col = y; rc.Row = x; return(rc); }
/// <summary> /// 计算指定范围内在某一级别中的行列号 /// </summary> /// <param name="minX">最小经度</param> /// <param name="minY">最小纬度</param> /// <param name="maxX">最大经度</param> /// <param name="maxY">最大纬度</param> /// <param name="zoom">层级数</param> /// <returns>行列号存储类型</returns> public static RowColumns GeRowColomns(double[] fullExent, double[] resolutions, int zoom) { double resolution = resolutions[zoom]; double tilelon = resolution * tileSize[0]; double tilelat = resolution * tileSize[1]; double originX = fullExent[0]; double originY = fullExent[1]; double offsetX = fullExent[2] - fullExent[0]; double offsetY = fullExent[3] - fullExent[1]; int col = (int)Math.Ceiling(offsetX / tilelon); int row = (int)Math.Ceiling(offsetY / tilelat); RowColumns rc = new RowColumns(); rc.Col = col; rc.Row = row; rc.tilelon = tilelon; rc.tilelat = tilelat; rc.zoom = zoom; return(rc); }
private void cutDataJson(int zoom) { string sql = "SELECT to_char(x, '999.999999999') as X,to_char(y, '99.999999999') as Y FROM " + this.tableName; DataSet datasetAllPoint = new DataSet(); NpgsqlDataAdapter dAllPoint = new NpgsqlDataAdapter(sql, dbcon); dAllPoint.Fill(datasetAllPoint); DataColumn X = datasetAllPoint.Tables[0].Columns["X"]; DataColumn Y = datasetAllPoint.Tables[0].Columns["Y"]; double[] fullExent = new double[] { minX, minY, maxX, maxY }; count = datasetAllPoint.Tables[0].Rows.Count; foreach (DataRow arow in datasetAllPoint.Tables[0].Rows) { k++; double ax = double.Parse(arow[X].ToString().Trim()); double ay = double.Parse(arow[Y].ToString().Trim()); GeoPoint point = new GeoPoint(); point.x = ax; point.y = ay; double[] bounds = MapTool.GetBoundsByPoint(point, fullExent, this.resolutions[zoom]); string sqlString = "SELECT Name,to_char(x, '999.999999999') as X,to_char(y, '99.999999999') as Y FROM " + this.tableName + " WHERE (x>" + bounds[0].ToString() + " AND x< " + bounds[2].ToString() + " AND y>" + bounds[1].ToString() + " AND y<" + bounds[3].ToString() + ")"; //string sqlString = "SELECT * FROM [" + this.tableName + "] WHERE (X>" + bounds[0].ToString() //+ " AND X< " + bounds[2].ToString() + " AND Y>" + bounds[1].ToString() + " AND Y<" + bounds[3].ToString() + ")"; DataSet dataset = new DataSet(); lock (lockObj) { NpgsqlDataAdapter da = new NpgsqlDataAdapter(sqlString, dbcon); da.Fill(dataset); //OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sqlString, OleConn); //OleDaExcel.Fill(dataset); } DataColumn cX = dataset.Tables[0].Columns["X"]; DataColumn cY = dataset.Tables[0].Columns["Y"]; DataColumn cName = dataset.Tables[0].Columns["NAME"]; TileObj to = new TileObj(); double res = resolutions[zoom]; foreach (DataRow row in dataset.Tables[0].Rows) { PointObj po = new PointObj(); geoObj geo = new geoObj(); proObj pro = new proObj(); double x = double.Parse(row[cX].ToString().Trim()); double y = double.Parse(row[cY].ToString().Trim()); geo.coordinates = new double[] { x, y }; pro.Name = row[cName].ToString(); po.geometry = geo; po.properties = pro; if (zoom > 8) { to.features.Add(po); } else { if (to.features.Count == 0) { to.features.Add(po); } else { bool isCluster = false; for (int index = 0; index < to.features.Count; index++) { PointObj p = to.features[index]; if (shouldCluster(p, po, res)) { isCluster = true; break; } } if (!isCluster) { to.features.Add(po); } } } } if (to.features.Count > 0) { RowColumns trc = MapTool.GetTileRowColomns(bounds, orgions.ToArray(), resolutions[zoom]); string id = zoom.ToString() + "_" + trc.Col.ToString() + "_" + trc.Row.ToString(); string tos = JsonHelper.JsonSerializer <TileObj>(to); string path = this.txbPath.Text.Trim() + "\\" + zoom.ToString() + "\\" + trc.Col.ToString(); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var file = Path.Combine(path, id + ".json"); if (!File.Exists(file)) { using (var fileStream = new FileStream(file, FileMode.OpenOrCreate)) { var content = tos; var buffer = System.Text.ASCIIEncoding.UTF8.GetBytes(content); fileStream.Write(buffer, 0, buffer.Length); } } } string msg1 = "正在生产第" + zoom.ToString() + "级数据,生成第" + k.ToString() + "条,共" + count.ToString() + "条"; if (this.OnProcessNotify != null) { this.OnProcessNotify(msg1, (k * 100) / count); } } }