/// <summary> /// 计算单张瓦片层级号的四支范围 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <returns></returns> public static RectExtent GetTileExtent(int x, int y, int z) { Coord leftUpCoord = TileToWorldPos(x, y, z); Coord rightDownCoord = TileToWorldPos(x + 1, y + 1, z); RectExtent result = new RectExtent(); result.LeftUp = leftUpCoord; result.Width = rightDownCoord.Lon - leftUpCoord.Lon; result.Height = leftUpCoord.Lat - rightDownCoord.Lat; return(result); }
/// <summary> /// 获取计算范围内的坐标 /// </summary> /// <param name="calculateRect"></param> /// <param name="zoom"></param> /// <returns></returns> public static Rectangle GetTileSeqsFromGeoExtent(RectExtent calculateRect, int zoom) { var leftUpP = WorldToTilePos(calculateRect.LeftUp.Lon, calculateRect.LeftUp.Lat, zoom); var rightDownP = WorldToTilePos(calculateRect.RightDown.Lon, calculateRect.RightDown.Lat, zoom); Rectangle result = new Rectangle(); result.Location = leftUpP; result.Width = rightDownP.X - leftUpP.X; result.Height = rightDownP.Y - leftUpP.Y; return(result); }
public static RectExtent EnvelopeToRectExtent(Envelope envelope) { RectExtent result = new RectExtent(); result.LeftUp = new Coord() { Lon = envelope.MinX, Lat = envelope.MaxY }; result.Width = envelope.MaxX - envelope.MinX; result.Height = envelope.MaxY - envelope.MinY; return(result); }
public static Geometry RectExtentToGeometry(RectExtent rectExtent) { Geometry ring = new Geometry(wkbGeometryType.wkbLinearRing); ring.AddPoint_2D(rectExtent.LeftUp.Lon, rectExtent.LeftUp.Lat); ring.AddPoint_2D(rectExtent.RightUp.Lon, rectExtent.RightUp.Lat); ring.AddPoint_2D(rectExtent.RightDown.Lon, rectExtent.RightDown.Lat); ring.AddPoint_2D(rectExtent.LeftDown.Lon, rectExtent.LeftDown.Lat); ring.AddPoint_2D(rectExtent.LeftUp.Lon, rectExtent.LeftUp.Lat); Geometry geometry = new Geometry(wkbGeometryType.wkbPolygon); geometry.AddGeometry(ring); return(geometry); }
/// <summary> /// 生成矢量切片 /// </summary> /// <param name="srcLayer"></param> /// <param name="rectExtent"></param> /// <param name="format"></param> /// <param name="saveFile"></param> /// <param name="trgSrs">输出投影</param> /// <param name="simplifyDiff">设置两个最小相似点的距离,越大点越容易合并。值类型与图层数据类型(经纬度或长度)保持一致</param> /// <param name="createEmptyFile">设置两个最小相似点的距离,越大点越容易合并。值类型与图层数据类型(经纬度或长度)保持一致</param> /// <returns></returns> public static bool CreateTileFile(Layer srcLayer, RectExtent rectExtent, string format, string saveFile, OSGeo.OSR.SpatialReference trgSrs, double simplifyDiff, bool createEmptyFile) { Geometry rectG = CommonUtils.RectExtentToGeometry(rectExtent); srcLayer.SetSpatialFilter(rectG); int featureCount = srcLayer.GetFeatureCount(1); if (featureCount == 0 && !createEmptyFile) { return(true); } OSGeo.OGR.Driver driver = Ogr.GetDriverByName(format); var trgDataset = driver.CreateDataSource(saveFile, null); var trgLayerName = System.IO.Path.GetFileNameWithoutExtension(saveFile); var trgLayer = trgDataset.CreateLayer(trgLayerName, trgSrs, srcLayer.GetGeomType(), null); Feature feature = null; int flag; srcLayer.ResetReading(); while ((feature = srcLayer.GetNextFeature()) != null) { var geometry = feature.GetGeometryRef(); //Douglas - Peucker algorithm算法进行抽稀 if (simplifyDiff > 0) { var simGeo = geometry.SimplifyPreserveTopology(simplifyDiff); feature.SetGeometry(simGeo); } flag = trgLayer.CreateFeature(feature); } return(true); }
public void SetCalculateRect(RectExtent rect) { CalculateRect = rect; }