示例#1
0
 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);
     }
 }
示例#2
0
        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);
                }
            }
        }