private void RenderShapeOnLayer(Shape shape, MapLayer layer) { switch (shape.Type) { case ShapeType.Point: ShapePoint point = shape as ShapePoint; layer.Children.Add(new Pushpin() { Location = new Location(point.Point.Y, point.Point.X) }); break; case ShapeType.PolyLine: ShapePolyLine polyline = shape as ShapePolyLine; for (int i = 0; i < polyline.Parts.Count; i++) { layer.Children.Add(new MapPolyline() { Locations = PointDArrayToLocationCollection(polyline.Parts[i]), Stroke = new SolidColorBrush(Color.FromArgb(150, 255, 0, 0)) }); } break; case ShapeType.Polygon: ShapePolygon polygon = shape as ShapePolygon; if (polygon.Parts.Count > 0) { //Only render the exterior ring of polygons for now. for (int i = 0; i < polygon.Parts.Count; i++) { //Note that the exterior rings in a ShapePolygon have a Clockwise order if (!IsCCW(polygon.Parts[i])) { layer.Children.Add(new MapPolygon() { Locations = PointDArrayToLocationCollection(polygon.Parts[i]), Fill = new SolidColorBrush(Color.FromArgb(150, 0, 0, 255)), Stroke = new SolidColorBrush(Color.FromArgb(150, 255, 0, 0)) }); } } } break; case ShapeType.MultiPoint: ShapeMultiPoint multiPoint = shape as ShapeMultiPoint; for (int i = 0; i < multiPoint.Points.Length; i++) { layer.Children.Add(new Pushpin() { Location = new Location(multiPoint.Points[i].Y, multiPoint.Points[i].X) }); } break; default: break; } }
public static void GetAllPolygonsFromShape(MapModel map, string geo) { using (var shp = new Shapefile(string.Format("./gis/{0}/alerts.shp", geo))) { foreach (Shape row in shp) { ShapePolygon p = row as ShapePolygon; map.StartNewPolygon(); foreach (var part in p.Parts) { foreach (var point in part) { map.AddPointToPolygon(new Location(point.Y, point.X)); } } var pol = map.FinishCurrentPolygon(); var center = pol.CenterPosition(); map.Marks.Add(new LocationMark() { Longitude = center.Longitude, Latitude = center.Latitude, }); } } }
private ShapePolygon ShapePolygonGeoToPrj(ShapePolygon shapePolygon) { if (shapePolygon == null || shapePolygon.IsProjected) { return(null); } GeoDo.RSS.Core.DrawEngine.ICoordinateTransform tran = _canvas.CoordTransform; double prjX; double prjY; int ringLength = shapePolygon.Rings.Length; ShapeRing[] ring = new ShapeRing[ringLength]; int potsLength = 0; for (int i = 0; i < ringLength; i++) { if (shapePolygon.Rings[i].Points == null) { continue; } potsLength = shapePolygon.Rings[i].Points.Length; ShapePoint[] shpPoint = new ShapePoint[potsLength]; for (int j = 0; j < shapePolygon.Rings[i].Points.Length; j++) { tran.Geo2Prj(shapePolygon.Rings[i].Points[j].X, shapePolygon.Rings[i].Points[j].Y, out prjX, out prjY); ShapePoint point = new ShapePoint(prjX, prjY); shpPoint[j] = point; } ring[i] = new ShapeRing(shpPoint); } ShapePolygon prjSp = new ShapePolygon(ring); return(prjSp); }
private void DrawFeature(Feature fet, Graphics g, IDrawArgs drawArgs, Brush brush) { if (fet == null) { return; } if (!fet.Projected) { ProjectFeature(fet); } Shape geometry = fet.Geometry; if (geometry is ShapePolygon) { _graphicsPath.Reset(); ShapePolygon plygon = geometry as ShapePolygon; foreach (ShapeRing ring in plygon.Rings) { Point[] pts = ToScreenPoints(ring.Points, drawArgs); if (pts != null && pts.Length > 3) { _graphicsPath.AddPolygon(pts); } } g.FillPath(brush, _graphicsPath); } }
private ShapePolygon ShapePolygonGeoToPrj(IProjectionTransform transform, ShapePolygon shapePolygon) { if (shapePolygon == null || shapePolygon.IsProjected) { return(null); } int ringLength = shapePolygon.Rings.Length; ShapeRing[] ring = new ShapeRing[ringLength]; int potsLength = 0; for (int i = 0; i < ringLength; i++) { if (shapePolygon.Rings[i].Points == null) { continue; } potsLength = shapePolygon.Rings[i].Points.Length; ShapePoint[] shpPoint = new ShapePoint[potsLength]; for (int j = 0; j < shapePolygon.Rings[i].Points.Length; j++) { //tran.Geo2Prj(shapePolygon.Rings[i].Points[j].X, shapePolygon.Rings[i].Points[j].Y, out prjX, out prjY);transform //ShapePoint point = new ShapePoint(prjX, prjY); //shpPoint[j] = point; ShapePoint point = shapePolygon.Rings[i].Points[j]; transform.Transform(point); shpPoint[j] = point; } ring[i] = new ShapeRing(shpPoint); } ShapePolygon prjSp = new ShapePolygon(ring); return(prjSp); }
private void Vector2Bitmap(ShapePolygon shapePolygon) { //矢量转成位图 Dictionary <ShapePolygon, Color> vectors = new Dictionary <ShapePolygon, Color>(); vectors.Add(shapePolygon, Color.Red); IVector2BitmapConverter c = new Vector2BitmapConverter(); int width = (int)(shapePolygon.Envelope.Width / 0.1f); int height = (int)(shapePolygon.Envelope.Height / 0.1f); Size size = new System.Drawing.Size(width, height); Bitmap buffer = new Bitmap(size.Width, size.Height, PixelFormat.Format24bppRgb); c.ToBitmap(vectors, Color.White, shapePolygon.Envelope, size, ref buffer); buffer.Save("f:\\1.bmp", ImageFormat.Bmp); //位图转成栅格索引 Bitmap2RasterConverter b2r = new Bitmap2RasterConverter(); int[] idxs = b2r.ToRaster(buffer, Color.Red); //栅格索引转成位图 BinaryBitmapBuilder b = new BinaryBitmapBuilder(); buffer = b.CreateBinaryBitmap(size, Color.Red, Color.White); b.Fill(idxs, size, ref buffer); buffer.Save("f:\\2.bmp", ImageFormat.Bmp); }
public static int[] GetAOI(Feature[] fets, Envelope dstEnvelope, Size size) { if (fets == null || fets.Length == 0) { return(null); } List <ShapePolygon> geometryslist = new List <ShapePolygon>(); ShapePolygon temp = null; foreach (Feature item in fets) { temp = item.Geometry as ShapePolygon; if (temp != null) { geometryslist.Add(temp); } } if (geometryslist.Count == 0) { return(null); } using (IVectorAOIGenerator gen = new VectorAOIGenerator()) { int[] aoi = gen.GetAOI(geometryslist.ToArray(), dstEnvelope, size); return(aoi); } }
void Read(ShapePolygon sp) { for (int p = 0; p < sp.numParts; p++) { uint max = sp.numPoints; if (p < sp.numParts - 1) { max = sp.parts[p + 1]; } uint len = sp.numPoints; if (p < sp.numParts - 1) { len = sp.parts[p + 1] - sp.parts[p]; } else { len = sp.numPoints - sp.parts[p]; } Point[] pnt = new Point[len]; int j = 0; for (uint i = sp.parts[p]; i < max; i++) { pnt[j].X = XTransform(sp.points[i].X); pnt[j].Y = YTransform(sp.points[i].Y); j++; } GPolygon gobj = new GPolygon(curType, pnt); } }
public ShapefilePOI(string filepath, Vector3 transform) { objects = new List <GameObject>(); shapefile = new Shapefile(filepath); GameObject prefab = Resources.Load <GameObject>("Prefabs/pole"); Material mat = Resources.Load <Material>("Materials/ribbon"); foreach (Shape shape in shapefile) { if (shape.Type == ShapeType.Polygon) { ShapePolygon poly = shape as ShapePolygon; string name = shape.GetMetadata("Area"); foreach (PointD[] part in poly.Parts) { GameObject obj = new GameObject(name); PointOfInterest poi = obj.AddComponent <PointOfInterest>(); poi.boundaries = new List <Vector3>(); poi.poleprefab = prefab; poi.ribbonMat = mat; foreach (PointD p in part) { poi.boundaries.Add(new Vector3((float)(p.X + transform.x), transform.y, (float)(p.Y + transform.z))); } objects.Add(obj); } } } }
//生成覆盖度矢量 private Feature[] CreateFeature(Envelope env, float xInterval, float yInterval, short[] data, Envelope dataEnv, Size dataSize) { int oid = 0; List <Feature> features = new List <Feature>(); double leftTopX = env.MinX; while (leftTopX < env.MaxX) { double leftTopY = env.MaxY; while (leftTopY > env.MinY) { ShapeRing ring = new ShapeRing( new ShapePoint[] { new ShapePoint(leftTopX, leftTopY), new ShapePoint(leftTopX + xInterval, leftTopY), new ShapePoint(leftTopX + xInterval, leftTopY - yInterval), new ShapePoint(leftTopX, leftTopY - yInterval) } ); ShapePolygon sp = new ShapePolygon(new ShapeRing[] { ring }); int degree = CalcIceDegree(sp, data, dataEnv, dataSize); Feature fet = new Feature(oid++, sp, new string[] { "覆盖度" }, new string[] { degree == 0 ? "" : degree.ToString() }, null); features.Add(fet); leftTopY -= yInterval; } leftTopX += xInterval; } return(features.ToArray()); }
static void ImportProvinceLayer(string path) { using (var shapefile = new Shapefile(path)) { foreach (var shape in shapefile) { ShapePolygon polygon = shape as ShapePolygon; Province province = new Province(); province.Name = shape.GetMetadata("name"); province.Country = shape.GetMetadata("country"); province.Shape = Poly2Str(polygon.Parts); province.ID = db.Id(1); long len = 0; foreach (var i in polygon.Parts) { len = len + i.Length; } Assert.Test(len < 65535, () => province.Country + len); db.Insert <Province>("Province", province); } } }
private void ProjectFeature(Feature fet) { double prjX = 0, prjY = 0; Shape geometry = fet.Geometry; if (geometry is ShapePolygon) { ShapePolygon plygon = geometry as ShapePolygon; int errorCount = 0; foreach (ShapeRing ring in plygon.Rings) { try { foreach (ShapePoint pt in ring.Points) { _coordTransform.Geo2Prj(pt.X, pt.Y, out prjX, out prjY); pt.X = prjX; pt.Y = prjY; } } catch { errorCount++; if (errorCount > 3) { break; } } } } fet.Projected = true; }
private ShapePolygon ShapePolygonPrjToGeo(GeoDo.Project.IProjectionTransform transform, ShapePolygon shapePolygon) { if (shapePolygon == null) { return(null); } double prjX; double prjY; int ringLength = shapePolygon.Rings.Length; ShapeRing[] ring = new ShapeRing[ringLength]; int potsLength = 0; for (int i = 0; i < ringLength; i++) { if (shapePolygon.Rings[i].Points == null) { continue; } potsLength = shapePolygon.Rings[i].Points.Length; ShapePoint[] shpPoint = new ShapePoint[potsLength]; for (int j = 0; j < shapePolygon.Rings[i].Points.Length; j++) { //ShapePoint point = new ShapePoint(shapePolygon.Rings[i].Points[j].X, shapePolygon.Rings[i].Points[j].Y); double[] x = new double[] { shapePolygon.Rings[i].Points[j].X }; double[] y = new double[] { shapePolygon.Rings[i].Points[j].Y }; transform.Transform(x, y); shpPoint[j] = new ShapePoint(x[0], y[0]);; } ring[i] = new ShapeRing(shpPoint); } ShapePolygon prjSp = new ShapePolygon(ring); return(prjSp); }
private void TryExportPolygon(Feature[] features, string shpFileName) { EsriShapeFilesWriterII w = new EsriShapeFilesWriterII(shpFileName, enumShapeType.Polygon); w.BeginWrite(); Feature feature = features[0]; string[] fieldNames = feature.FieldNames; Feature[] retFeature = new Feature[features.Length]; for (int i = 0; i < features.Length; i++) { ShapePolygon ply = (features[i].Geometry as ShapePolygon).Clone() as ShapePolygon; ShapeRing[] rings = ply.Rings; ShapeRing[] newRings = new ShapeRing[rings.Length]; for (int j = 0; j < rings.Length; j++) { ShapePoint[] points = rings[j].Points; ShapePoint[] newPoints = new ShapePoint[points.Length]; for (int p = 0; p < points.Length; p++) { double prjx = points[p].X; double prjy = points[p].Y; double geox, geoy; _canvas.CoordTransform.Prj2Geo(prjx, prjy, out geox, out geoy); newPoints[p] = new ShapePoint(geox, geoy); } newRings[j] = new ShapeRing(newPoints); } ShapePolygon newPly = new ShapePolygon(newRings); Feature fet = new Feature(features[i].OID, newPly, fieldNames, features[i].FieldValues, null); retFeature[i] = fet; } w.Write(retFeature); w.EndWriter(); }
public static IEnumerable <LocationMark> ConvertUGCtoPosition(IEnumerable <string> ugcs) { using (var shp = new Shapefile("./gis/us/fz25jn18.shp")) { foreach (var ugc in ugcs) { var state = ugc.Substring(0, 2); var zone = ugc.Substring(3, ugc.Length); foreach (Shape row in shp) { if ((string)row.DataRecord[0] == state && (string)row.DataRecord[1] == zone) { ShapePolygon p = row as ShapePolygon; yield return(new LocationMark() { Longitude = (double)row.DataRecord[7], Latitude = (double)row.DataRecord[8] }); break; } } } } }
private void ProjectFeature(Feature fet) { Shape geometry = fet.Geometry; double[] xs = new double[1]; double[] ys = new double[1]; if (geometry is ShapePolygon) { ShapePolygon plygon = geometry as ShapePolygon; foreach (ShapeRing ring in plygon.Rings) { foreach (ShapePoint pt in ring.Points) { xs[0] = pt.X; ys[0] = pt.Y; _coordTransform.Transform(xs, ys); pt.X = xs[0]; pt.Y = ys[0]; } ring.UpdateCentroid(); ring.UpdateEnvelope(); } plygon.UpdateCentroid(); plygon.UpdateEnvelope(); } else if (geometry is ShapePolyline) { ShapePolyline plyline = geometry as ShapePolyline; foreach (ShapeLineString line in plyline.Parts) { foreach (ShapePoint pt in line.Points) { xs[0] = pt.X; ys[0] = pt.Y; _coordTransform.Transform(xs, ys); pt.X = xs[0]; pt.Y = ys[0]; } line.UpdateCentroid(); line.UpdateEnvelope(); } plyline.UpdateCentroid(); plyline.UpdateEnvelope(); } else if (geometry is ShapePoint) { ShapePoint pt = geometry as ShapePoint; xs[0] = pt.X; ys[0] = pt.Y; _coordTransform.Transform(xs, ys); pt.X = xs[0]; pt.Y = ys[0]; pt.UpdateCentroid(); pt.UpdateEnvelope(); } fet.Geometry.UpdateCentroid(); fet.Geometry.UpdateEnvelope(); fet.Projected = true; }
/// <summary> /// Initializes the shape file. /// </summary> /// <param name="shapeKey">Shape key used.</param> private void Initialize(string shapeKey) { // construct shapefile with the path to the .shp file using (Shapefile shapefile = new Shapefile(this.shapeFilePath)) { // enumerate all shapes foreach (Shape shape in shapefile) { // cast shape based on the type switch (shape.Type) { case ShapeType.Polygon: // a polygon contains one or more parts - each part is a list of points which // are clockwise for boundaries and anti-clockwise for holes // see http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf ShapePolygon shapePolygon = shape as ShapePolygon; string shapeName = shape.GetMetadata(shapeKey); if (!string.IsNullOrEmpty(shapeName)) { shapeName = shapeName.Trim().ToLowerInvariant(); if (!this.shapesList.ContainsKey(shapeName)) { this.shapesList.Add(shapeName, shapePolygon.Parts); } else { this.shapesList[shapeName].AddRange(shapePolygon.Parts); } } break; default: // and so on for other types... break; } } } for (int h = 0; h < Constants.MaxHvalue; h++) { for (int v = 0; v < Constants.MaxVvalue; v++) { this.cells.Add(string.Format(CultureInfo.CurrentCulture, "h{0:D2}v{1:D2}", h, v), new List <string>()); } } // Initialize Region to HV Map. foreach (var region in System.IO.File.ReadAllLines(this.regionHVMapFilePath)) { string[] regionCellMap = region.Split(':'); string regionName = regionCellMap[0].ToLower(CultureInfo.CurrentCulture); foreach (var cell in regionCellMap[1].Split(',')) { this.cells[cell].Add(regionName); } } }
public Dictionary <string, int[]> GetFeatureAOIIndex() { int filedIndex = -1; GetFiledIndex(out filedIndex, cbFields.Text); if (_selectFeature == null || _selectFeature.Count == 0 || filedIndex == -1) { return(null); } Dictionary <string, int[]> result = new Dictionary <string, int[]>(); int featuresLength = _selectFeature.Count; List <int> tempInt = new List <int>(); VectorAOIGenerator vg = new VectorAOIGenerator(); int[] aoi = null; string currentFiledValue = string.Empty; for (int i = 0; i < featuresLength; i++) { Feature feature = _selectFeature[i]; if (_spatialReference != null && _spatialReference.ProjectionCoordSystem != null && !feature.Projected) { using (GeoDo.Project.IProjectionTransform transform = GeoDo.Project.ProjectionTransformFactory.GetProjectionTransform(GeoDo.Project.SpatialReference.GetDefault(), _spatialReference)) { using (ShapePolygon spolygon = ShapePolygonPrjToGeo(transform, feature.Geometry as ShapePolygon)) { aoi = vg.GetAOI(new ShapePolygon[] { spolygon }, _envelope, _size); } } } else { ShapePolygon spolygon = _selectFeature[i].Geometry as ShapePolygon; aoi = vg.GetAOI(new ShapePolygon[] { spolygon }, _envelope, _size); } if (aoi == null || aoi.Length == 0) { continue; } currentFiledValue = _selectFeature[i].FieldValues[filedIndex]; if (result.ContainsKey(currentFiledValue)) { tempInt.AddRange(result[currentFiledValue]); tempInt.AddRange(aoi); result[currentFiledValue] = tempInt.ToArray(); } else { result.Add(currentFiledValue, aoi); } tempInt.Clear(); } return(result.Count == 0 ? null : result); }
private object DrToEnvelope(IDataReader dr, int idx) { ShapePolygon ply = _adapter.DrToShape(dr, idx) as ShapePolygon; if (ply != null) { ShapeRing ring = ply.Rings[0]; return(new Envelope(ring.Points[0].X, ring.Points[2].Y, ring.Points[1].X, ring.Points[0].Y)); } return(new Envelope()); }
private Feature GetFeature() { ShapePoint[] pts = new ShapePoint[] { new ShapePoint(116, 39), new ShapePoint(117, 39), new ShapePoint(117, 38), new ShapePoint(116, 38) }; ShapeRing ring = new ShapeRing(pts); ShapePolygon ply = new ShapePolygon(new ShapeRing[] { ring }); Feature fet = new Feature(0, ply, null, null, null); return(fet); }
//计算覆盖度(百分比) private int CalcIceDegree(ShapePolygon sp, short[] data, Envelope env, Size size) { int[] aoi = GetAoi(sp, env, size); int degree = 0; int count = 0; foreach (int aoiindex in aoi) { if (data[aoiindex] == 1) { count++; } } degree = (int)(count * 100f / aoi.Length); return(degree); }
private static int[] GetAoi(ShapePolygon shpPolygon, Envelope env, Size size) { try { int[] aoi = null; using (VectorAOIGenerator vectorGen = new VectorAOIGenerator()) { aoi = vectorGen.GetAOI(new ShapePolygon[] { shpPolygon }, env, size); } return(aoi); } catch (Exception ex) { return(null); } }
private void DrawFeature(Feature fet, Graphics g, IDrawArgs drawArgs, Brush brush) { if (fet == null) { return; } if (!fet.Projected) { ProjectFeature(fet); } Shape geometry = fet.Geometry; if (geometry is ShapePolygon) { _graphicsPath.Reset(); ShapePolygon plygon = geometry as ShapePolygon; ShapeRing[] rings = plygon.Rings; int length = rings.Length; Point[] pts = null; int errorCount = 0; for (int i = 0; i < length; i++) { try { pts = ToScreenPoints(rings[i].Points, drawArgs); if (pts != null && pts.Length > 3) { //_graphicsPath.AddPolygon(pts); g.FillPolygon(brush, pts); } } catch { errorCount++; if (errorCount > 10) { break; } else { continue; } } } //g.FillPath(brush, _graphicsPath); } }
private Envelope GetMaskEnvelope(ShapePolygon shapePolygon) { if (shapePolygon == null) { return(null); } Envelope envelope = shapePolygon.Envelope; if (_activeCoordType == enumCoordType.GeoCoord) { return(envelope); } else if (_activeCoordType == enumCoordType.PrjCoord) { GeoDo.Project.ISpatialReference srcProj = GeoDo.Project.SpatialReference.GetDefault(); GeoDo.Project.ISpatialReference dstProj = _activeSpatialRef; GeoDo.Project.IProjectionTransform prj = GeoDo.Project.ProjectionTransformFactory.GetProjectionTransform(srcProj, dstProj); double[] xs = new double[] { shapePolygon.Rings[0].Points[0].X }; double[] ys = new double[] { shapePolygon.Rings[0].Points[0].Y }; prj.Transform(xs, ys); double minx = xs[0]; double maxx = xs[0]; double miny = ys[0]; double maxy = ys[0]; ShapePoint pt; foreach (ShapeRing ring in shapePolygon.Rings) { for (int pti = 0; pti < ring.Points.Length; pti++) { pt = ring.Points[pti]; xs = new double[] { pt.X }; ys = new double[] { pt.Y }; prj.Transform(xs, ys); minx = Math.Min(xs[0], minx); maxx = Math.Max(xs[0], maxx); miny = Math.Min(ys[0], miny); maxy = Math.Max(ys[0], maxy); } } Envelope corEnvelope = new Envelope(minx, miny, maxx, maxy); return(corEnvelope); } else { return(null); } }
public static IEnumerable <Polygon> ReadShapePolygon(ShapePolygon shapePolygon, double offset, string namePrefix) { for (int i = 0; i < shapePolygon.Parts.Count; i++) { Polygon polygon = null; try { polygon = new Polygon(shapePolygon, i, offset, namePrefix); } catch (InvalidOperationException exception) { Console.WriteLine("Ignored a polygon. " + exception.Message); } if (polygon != null) { yield return(polygon); } } }
/// <summary> /// 버퍼에 그리고 완성된 후 뷰. /// </summary> private void LodeViewBufferGraphics(Graphics g) { using (BufferedGraphics bufferedGraphics = BufferedGraphicsManager.Current.Allocate(g, ClientRectangle)) { bufferedGraphics.Graphics.Clear(Color.White); bufferedGraphics.Graphics.InterpolationMode = InterpolationMode.High; bufferedGraphics.Graphics.SmoothingMode = SmoothingMode.AntiAlias; bufferedGraphics.Graphics.TranslateTransform ( AutoScrollPosition.X, AutoScrollPosition.Y ); //Pen pen = new Pen(Color.FromArgb(111, 91, 160), 3); //bufferedGraphics.Graphics.DrawLine(pen, 0, 0, 100, 100); //pen.Dispose(); foreach (var shape in _shapeFile) { switch (shape.Type) { case ShapeType.Polygon: ShapePolygon shapePolygon = shape as ShapePolygon; foreach (var part in shapePolygon.Parts) { List <PointF> points = new List <PointF>(); foreach (var point in part) { float screenX = Convert.ToSingle(GetGisToScreen(point).X); float screenY = Convert.ToSingle(GetGisToScreen(point).Y); points.Add(new PointF(screenX, screenY)); } bufferedGraphics.Graphics.DrawPolygon(Pens.Black, points.ToArray()); //gOff.FillPolygon(Brushes.YellowGreen, points.ToArray()); //bufferedgraphic.Graphics.DrawPolygon(Pens.Black, points.ToArray()); } break; default: break; } } bufferedGraphics.Render(g); bufferedGraphics.Dispose(); } }
/// <summary> /// 矢量数据取AOI, /// 矢量与栅格坐标不一致时候,转矢量。 /// </summary> /// <param name="feature"></param> /// <returns></returns> private int[] GetIndexes(Feature feature) { GeoDo.RSS.Core.DrawEngine.ICoordinateTransform tran = _canvas.CoordTransform; IRasterDrawing rasterDrawing = _canvas.PrimaryDrawObject as IRasterDrawing; GeoDo.RSS.Core.DF.CoordEnvelope coordEvp = rasterDrawing.DataProvider.CoordEnvelope.Clone(); Size rasterSize = rasterDrawing.Size; Envelope rasterEnv = new Envelope(coordEvp.MinX, coordEvp.MinY, coordEvp.MaxX, coordEvp.MaxY); if (feature.Projected && rasterDrawing.DataProvider.CoordType == enumCoordType.GeoCoord) { using (ShapePolygon spPrj = ShapePolygonPrjToGeo(feature.Geometry as ShapePolygon)) { if (spPrj != null) { using (IVectorAOIGenerator gen = new VectorAOIGenerator()) { return(gen.GetAOI(new ShapePolygon[] { spPrj }, rasterEnv, rasterSize)); } } } } else if (!feature.Projected && rasterDrawing.DataProvider.CoordType == enumCoordType.PrjCoord) { using (ShapePolygon spPrj = ShapePolygonGeoToPrj(feature.Geometry as ShapePolygon)) { if (spPrj != null) { using (IVectorAOIGenerator gen = new VectorAOIGenerator()) { return(gen.GetAOI(new ShapePolygon[] { spPrj }, rasterEnv, rasterSize)); } } } } else { using (IVectorAOIGenerator gen = new VectorAOIGenerator()) { return(gen.GetAOI(new ShapePolygon[] { feature.Geometry as ShapePolygon }, rasterEnv, rasterSize)); } } return(null); }
private GraphicsPath ToGraphicsPath(Feature feature, ICanvas canvas) { if (feature == null) { return(null); } ShapePolygon ply = feature.Geometry as ShapePolygon; if (ply == null || ply.Rings == null || ply.Rings.Length == 0) { return(null); } GeoDo.RSS.Core.DrawEngine.ICoordinateTransform tran = canvas.CoordTransform; double prjX, prjY; int screenX, screenY; GraphicsPath path = new GraphicsPath(); foreach (ShapeRing ring in ply.Rings) { PointF[] pts = new PointF[ring.Points.Length]; if (pts == null || pts.Length == 0) { continue; } for (int i = 0; i < pts.Length; i++) { if (!feature.Projected) { tran.Geo2Prj(ring.Points[i].X, ring.Points[i].Y, out prjX, out prjY); } else { prjX = ring.Points[i].X; prjY = ring.Points[i].Y; } tran.Prj2Screen(prjX, prjY, out screenX, out screenY); pts[i].X = screenX; pts[i].Y = screenY; } path.AddPolygon(pts.ToArray()); } return(path); }
public static CodeCell.AgileMap.Core.Shape ToPolygon(ICanvas canvas, GeometryOfDrawed geometry) { if (canvas == null || geometry == null || geometry.RasterPoints == null || geometry.RasterPoints.Length == 0) { return(null); } int count = geometry.RasterPoints.Length; List <ShapePoint> pts = new List <ShapePoint>(count); double geoX = 0, geoY = 0; for (int i = 0; i < count; i++) { canvas.CoordTransform.Raster2Geo((int)geometry.RasterPoints[i].Y, (int)geometry.RasterPoints[i].X, out geoX, out geoY); pts.Add(new ShapePoint(geoX, geoY)); } ShapeRing ring = new ShapeRing(pts.ToArray()); ShapePolygon ply = new ShapePolygon(new ShapeRing[] { ring }); return(ply); }
static void ImportCountryLayer(string path) { using (var shapefile = new Shapefile(path)) { foreach (var shape in shapefile) { ShapePolygon polygon = shape as ShapePolygon; var country = new Country(); country.Name = shape.GetMetadata("COUNTRY"); country.Shape = Poly2Str(polygon.Parts); //country.ChineseName = shape.GetMetadata("cname"); country.ID = db.Id(1); db.Insert <Country>("Country", country); } } }