private void Overlay(RasterOp basic, RasterOp city, string cityName) { for (int i = 0; i < basic.Width; i++) { for (int j = 0; j < basic.Height; j++) { if (basic.Read(i, j).HasValue) { float timeCost = (float)city.Read(i, j); if (Math.Abs(timeCost) < 10e-5) { if (_popDic.ContainsKey(cityName)) { float tt = (float)(3 * Math.Log10(_popDic[cityName] * 10)); basic.Write(i, j, (float)basic.Read(i, j) + CityValues[cityName] / tt); } } else { basic.Write(i, j, (float)basic.Read(i, j) + CityValues[cityName] / timeCost); } } } } }
/// <summary> /// /// </summary> /// <param name="basic"></param> /// <param name="rasterFolderPath"></param> /// <param name="fileName"></param> /// <param name="cityName"></param> private void Overlay(RasterOp basic, string rasterFolderPath, string fileName, string cityName) { RasterReader reader = new RasterReader(rasterFolderPath, fileName + ".tif"); RasterOp op = new RasterOp(reader); Overlay(basic, op, CityValues[cityName]); }
/// <summary> /// 计算一个高铁城市的在高铁未通车的时间成本 /// </summary> /// <returns>时间成本操作</returns> private RasterOp CalculationCity(string cityName) { RasterOp rasterOp = new RasterOp(_rasterReader); City city = _allCities.First(item => item.Name == cityName); Postion pos = _rasterReader.Coordinate(city.XCoord, city.YCoord); return(rasterOp.Calculator(pos)); }
public static void CopyGraphics(this Graphics g, Graphics gxDest, int width, int height, RasterOp op) { var srcDc = g.GetHdc(); var destDc = gxDest.GetHdc(); NativeMethods.BitBlt(destDc, 0, 0, width, height, srcDc, 0, 0, op); gxDest.ReleaseHdc(destDc); g.ReleaseHdc(srcDc); }
private void Init() { var firstCity = Cities.First(item => item.IsSelected); RasterReader reader = new RasterReader(HighTrainNoFolderPath, firstCity.Name + "_高铁未通车" + ".tif"); Info = reader.RasterInfo; RasterOp = new RasterOp(reader); RasterOp.Reset(); }
public static int BitBlt(HandleRef hdc, int x, int y, int cx, int cy, HandleRef hdcSrc, int x1, int y1, RasterOp rop) { int result = BitBlt(hdc.Handle, x, y, cx, cy, hdcSrc.Handle, x1, y1, rop); GC.KeepAlive(hdc.Wrapper); GC.KeepAlive(hdcSrc.Wrapper); return(result); }
private void Run(RasterReader reader, CalculatorCity city, string folderPath) { RasterOp rasterOp = new RasterOp(reader); Postion pos = reader.Coordinate(city.XCoord, city.YCoord); var result = rasterOp.Calculator(pos); RasterWriter writer = new RasterWriter(folderPath, city.Name + "_高铁未通车", reader.RasterInfo); result.WriteRaster(writer, "TIFF"); }
private static extern int BitBlt( IntPtr hdc, int x, int y, int cx, int cy, IntPtr hdcSrc, int x1, int y1, RasterOp rop );
public static void FillColor(this Graphics g, Rectangle rect, Color color, RasterOp op) { var hdc = g.GetHdc(); var hBrush = NativeMethods.CreateSolidBrush(color.ToWin32()); var hOldBrush = NativeMethods.SelectObject(hdc, hBrush); NativeMethods.PatBlt(hdc, rect.Left, rect.Top, rect.Width, rect.Height, op); NativeMethods.SelectObject(hdc, hOldBrush); NativeMethods.DeleteObject(hBrush); g.ReleaseHdc(hdc); }
private void Run(object p) { Hashtable para = p as Hashtable; var wait = para["wait"] as ProgressWait; var folderPath = para["folderPath"].ToString(); int totalCount = Cities.Count(item => item.IsSelected); int count = 0; wait.SetWaitCaption("计算高铁未通车"); RasterOp.Reset(); try { float sumM = SumM(); foreach (var calculatorCity in Cities) { if (calculatorCity.IsSelected) { wait.SetProgress((double)count++ / totalCount); Overlay(RasterOp, HighTrainNoFolderPath, calculatorCity.Name + "_高铁未通车", calculatorCity.Name); } } RasterOp.Overlay(item => item / sumM); Wirte(RasterOp, folderPath, "区位可达性_未通车"); GC.Collect(); //********************************************* count = 0; wait.SetWaitCaption("计算高铁通车后"); RasterOp.Reset(); foreach (var calculatorCity in Cities) { if (calculatorCity.IsSelected) { wait.SetProgress((double)count++ / totalCount); Overlay(RasterOp, HighTrainYesFolderPath, calculatorCity.Name + "_高铁通车后", calculatorCity.Name); } } RasterOp.Overlay(item => item / sumM); Wirte(RasterOp, folderPath, "区位可达性_通车后"); GC.Collect(); para["ret"] = true; } catch (Exception e) { _log.Error(e.Message + e.StackTrace); para["ret"] = false; } finally { wait.CloseWait(); } }
/// <summary> /// 计算一个城市对其中的影响 /// </summary> /// <param name="basic"></param> /// <param name="city"></param> /// <param name="value"></param> private void Overlay(RasterOp basic, RasterOp city, float value) { for (int i = 0; i < basic.Width; i++) { for (int j = 0; j < basic.Height; j++) { if (basic.Read(i, j).HasValue) { var timeCost = (float)city.Read(i, j); basic.Write(i, j, (float)basic.Read(i, j) + timeCost * value); } } } }
private void Run(object p) { Hashtable para = p as Hashtable; ContinuousWait wait = para["wait"] as ContinuousWait; var folderPath = para["folderPath"].ToString(); try { string preWorkSpace = Path.GetDirectoryName(_preRasterFilePath); string preFileName = Path.GetFileNameWithoutExtension(_preRasterFilePath); string aftWorkSpace = Path.GetDirectoryName(_aftRasterFilePath); string aftFileName = Path.GetFileNameWithoutExtension(_aftRasterFilePath); RasterReader preReader = new RasterReader(preWorkSpace, preFileName + ".tif"); RasterReader aftReader = new RasterReader(aftWorkSpace, aftFileName + ".tif"); RasterOp preOp = new RasterOp(preReader); RasterOp aftOp = new RasterOp(aftReader); RasterOp res = preOp.Clone(); res.Reset(); for (int i = 0; i < preOp.Width; i++) { for (int j = 0; j < preOp.Height; j++) { if (preOp.Read(i, j).HasValue) { float orgin = (float)preOp.Read(i, j); float now = (float)aftOp.Read(i, j); if (Math.Abs(orgin) > 10e-5) { float rate = (now - orgin) / orgin; res.Write(i, j, rate); } } } } RasterWriter writer = new RasterWriter(folderPath, RasterName, preReader.RasterInfo); res.WriteRaster(writer, "TIFF"); para["ret"] = true; } catch (Exception e) { _log.Error(e.GetType() + e.Message + e.StackTrace); para["ret"] = false; } finally { wait.CloseWait(); } }
private void Overlay(RasterOp basic, RasterOp city, string cityName) { for (int i = 0; i < basic.Width; i++) { for (int j = 0; j < basic.Height; j++) { if (basic.Read(i, j).HasValue) { var timecost = (float)city.Read(i, j); float shorestTimeCost = ShortestTimeCost(i, j, _cityPos[cityName]); if (Math.Abs(shorestTimeCost) < 10e-5) { continue; } basic.Write(i, j, (float)basic.Read(i, j) + timecost / shorestTimeCost * CityValues[cityName]); } } } }
private bool WriteTimeCostRaster(string folderPath) { try { //读取两个文件 var landReader = new RasterReader(folderPath, LandUse + ".tif"); var roadReader = new RasterReader(folderPath, TrafficRoad + ".tif"); RasterOp landOp = new RasterOp(landReader); RasterOp roadOp = new RasterOp(roadReader); //取最小值 landOp.Overlay(roadOp, RasterAlgorithm.MinPixel); ////写入文件 RasterWriter writer = new RasterWriter(folderPath, TimeCostName, landReader.RasterInfo); landOp.WriteRaster(writer, "TIFF"); return(true); } catch (Exception e) { _log.Error(e.Message + e.StackTrace); } return(false); }
public static extern int StretchDIBits(IntPtr hdc, int XDest, int YDest, int nDestWidth, int nDestHeight, int XSrc, int YSrc, int nSrcWidth, int nSrcHeight, IntPtr lpBits, [In] ref BITMAPINFOHEADER lpBitsInfo, uint iUsage, RasterOp dwRop);
internal static extern bool PatBlt(IntPtr hdc, int nXLeft, int nYLeft, int nWidth, int nHeight, RasterOp dwRop);
internal static extern bool BitBlt(IntPtr hObject, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hObjSource, int nXSrc, int nYSrc, RasterOp dwRop);
protected void Wirte(RasterOp op, string foldePath, string name) { RasterWriter writer = new RasterWriter(foldePath, name, Info); op.WriteRaster(writer, "TIFF"); }
private void Run(object p) { Hashtable para = p as Hashtable; var wait = para["wait"] as ProgressWait; string folderPath = para["folderPath"].ToString(); int totalCount = Cities.Count(item => item.IsSelected); int count = 0; try { wait.SetWaitCaption("计算高铁城市空间可达性"); foreach (string city in _dijkstra.GetCityEnumerator()) { wait.SetProgress((double)count++ / _dijkstra.Count); _highTrainStation.Add(city, CalculationCity(city)); } Dictionary <string, RasterOp> backup = new Dictionary <string, RasterOp>(_highTrainStation.Count); //backup foreach (var keyValue in _highTrainStation) { backup.Add(keyValue.Key, new RasterOp(keyValue.Value)); } //*********************************** wait.SetProgress(0); wait.SetWaitCaption("计算高铁城市叠加效应"); count = 0; foreach (string city in _dijkstra.GetCityEnumerator()) { wait.SetProgress((double)count++ / _dijkstra.Count); float[] times = _dijkstra.Dijkstra(city); foreach (var otherCity in _dijkstra.GetCityEnumerator()) { if (city != otherCity) { int cityIndex = _dijkstra.GetCityIndex(otherCity); backup[otherCity].Overlay(item => item + times[cityIndex]); _highTrainStation[city].Overlay(backup[otherCity], Math.Min); backup[otherCity].Overlay(item => item - times[cityIndex]); } } } //**************************************** backup.Clear(); //foreach (var keyValue in _highTrainStation) //{ // backup.Add(keyValue.Key, new RasterOp(keyValue.Value)); //} wait.SetWaitCaption("计算所有城市空间可达性"); wait.SetProgress(0); count = 0; foreach (var calculatorCity in Cities) { if (calculatorCity.IsSelected) { wait.SetProgress((double)count++ / totalCount); RasterOp res; if (_highTrainStation.ContainsKey(calculatorCity.Name)) { res = _highTrainStation[calculatorCity.Name]; } else { res = CalculationCity(calculatorCity.Name); RasterOp back = res.Clone(); foreach (var station in _highTrainStation) { //RasterOp op = back.Clone(); City city = _allCities.First(item => item.Name == station.Key); Postion pos = _rasterReader.Coordinate(city.XCoord, city.YCoord); float timecost = (float)back.Read(pos.XIndex, pos.YIndex); _highTrainStation[station.Key].Overlay(item => item + timecost); res.Overlay(_highTrainStation[station.Key], Math.Min); _highTrainStation[station.Key].Overlay(item => item - timecost); } } RasterWriter writer = new RasterWriter(folderPath, calculatorCity.Name + "_高铁通车后", _rasterReader.RasterInfo); res.WriteRaster(writer, "TIFF"); } } para["ret"] = true; } catch (Exception e) { _log.Error(e.Message + e.StackTrace); para["ret"] = false; } finally { wait.CloseWait(); } }
public static partial int BitBlt(IntPtr hdc, int x, int y, int cx, int cy, IntPtr hdcSrc, int x1, int y1, RasterOp rop);
public static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, RasterOp dwRop);