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); } }
private void WriteWorldFile(IRasterDataProvider prd, string bmpFilename) { try { double minx = prd.CoordEnvelope.MinX; double maxy = prd.CoordEnvelope.MaxY; double resolutionX = prd.ResolutionX; double resolutionY = prd.ResolutionY; GeoDo.Project.ISpatialReference spatial = prd.SpatialRef; WorldFile worldFile = new WorldFile(); worldFile.CreatWorldFile(resolutionX, -resolutionY, minx, maxy, bmpFilename); worldFile.CreatXmlFile(spatial == null ? GeoDo.Project.SpatialReference.GetDefault() : spatial, bmpFilename); } catch { } }
public static bool SetAOIArugment(string[] fnames, IMonitoringSubProduct msp, bool multiSelect, out CoordEnvelope selectedEnvelope) { float maxResultion = 0f; IRasterDataProvider prd = null; CoordEnvelope envelope = new CoordEnvelope(double.MaxValue, double.MinValue, double.MaxValue, double.MinValue); GeoDo.Project.ISpatialReference prdSpatialRef = null; foreach (string item in fnames) { try { prd = GeoDataDriver.Open(item) as IRasterDataProvider; maxResultion = Math.Max(maxResultion, prd.ResolutionX); envelope = envelope.Union(new CoordEnvelope(prd.CoordEnvelope.MinX, prd.CoordEnvelope.MinX + prd.ResolutionX * prd.Width, prd.CoordEnvelope.MinY, prd.CoordEnvelope.MinY + prd.ResolutionY * prd.Height)); prdSpatialRef = prd.SpatialRef; } catch { throw new ArgumentException("选择的文件:“" + Path.GetFileName(item) + "”无法进行面积统计。"); } finally { if (prd != null) { prd.Dispose(); prd = null; } } } Size size = new Size((int)(envelope.Width / maxResultion), (int)(envelope.Height / maxResultion)); using (frmStatSubRegionTemplates frm = new frmStatSubRegionTemplates(size, envelope, maxResultion)) { frm.listView1.MultiSelect = multiSelect; if (prdSpatialRef != null) { frm.SpatialRef = prdSpatialRef; } if (frm.ShowDialog() == DialogResult.OK) { //Feature[] features = frm.GetSelectedFeatures(); //AOIProvider aoiProvider = new AOIProvider(null); //aoiProvider.GetBitmapIndexes msp.ArgumentProvider.SetArg("AOI", frm.GetFeatureAOIIndex()); msp.ArgumentProvider.SetArg("AOIFeatures", frm.GetSelectedFeatures()); CodeCell.AgileMap.Core.Envelope env = frm.GetSelectedEnvelope(); if (env != null) { selectedEnvelope = new CoordEnvelope(env.MinX, env.MaxX, env.MinY, env.MaxY); } else { selectedEnvelope = null; } return(true); } else { selectedEnvelope = null; return(false); } } }