static private PixelPosition_T RasterationPoint(IPoint pt, Raster_T ras) { int row = (int)((pt.Y - ras.Originpt.Y) / ras.Pixelsize); int col = (int)((pt.X - ras.Originpt.X) / ras.Pixelsize); PixelPosition_T pp = new PixelPosition_T(row, col); return(pp); }
static private List <PixelPosition_T> RasterationPolygon(IFeature polyFea, Raster_T ras, double xmin, double xMax) { List <PixelPosition_T> pypixel = new List <PixelPosition_T>(); IPointCollection pygonPtCol = polyFea.Shape as IPointCollection; Dictionary <IPoint, double> ptDic = new Dictionary <IPoint, double>(); for (int i = 0; i < pygonPtCol.PointCount; i++) { //IPoint ppt = GetGeo( axMapControl1.ActiveView,pygonPtCol.get_Point(i).X, pygonPtCol.get_Point(i).Y); IPoint ppt = pygonPtCol.get_Point(i); ptDic.Add(ppt, ppt.Y); } Dictionary <IPoint, double> dicYValue = SortByXYvalue(ptDic); PixelPosition_T ppmax = RasterationPoint(dicYValue.Keys.ElementAt(dicYValue.Count - 1), ras); PixelPosition_T ppmin = RasterationPoint(dicYValue.Keys.ElementAt(0), ras); for (int i = 0; i <= (ppmax.Row - ppmin.Row); i++) { double y = (ppmin.Row + i + 0.5) * ras.Pixelsize + ras.Originpt.Y; IPoint pt1 = new PointClass(); pt1.X = xmin;// ras.Originpt.X; pt1.Y = y; pt1.Z = 100; IPoint pt2 = new PointClass(); pt2.X = xMax;// ras.Originpt.X + ras.Cols * ras.Pixelsize; pt2.Y = y; pt2.Z = 100; IPolyline plyLine = new PolylineClass(); plyLine.FromPoint = pt1; plyLine.ToPoint = pt2; ITopologicalOperator topoLyr = plyLine as ITopologicalOperator; Dictionary <IPoint, double> interpts = new Dictionary <IPoint, double>(); for (int j = 0; j < pygonPtCol.PointCount - 1; j++) { IPolyline partLy = new PolylineClass(); partLy.FromPoint = pygonPtCol.get_Point(j); partLy.ToPoint = pygonPtCol.get_Point(j + 1); IGeometry pgeo = topoLyr.Intersect(partLy as IGeometry, esriGeometryDimension.esriGeometry0Dimension); if (pgeo.IsEmpty == false) { IPointCollection ptC = pgeo as IPointCollection; interpts.Add(ptC.get_Point(0), ptC.get_Point(0).X); } } Dictionary <IPoint, double> newPts = SortByXYvalue(interpts); for (int j = 0; j < newPts.Count - 1; j = j + 2) { IPolyline pline = new PolylineClass(); pline.FromPoint = newPts.Keys.ElementAt(j); pline.ToPoint = newPts.Keys.ElementAt(j + 1); List <PixelPosition_T> cpixel = RasterationHonLine(pline, ras); pypixel.AddRange(cpixel); } } return(pypixel); }
static private List <PixelPosition_T> RasterationHonLine(IPolyline line, Raster_T ras) { List <PixelPosition_T> pixels = new List <PixelPosition_T>(); PixelPosition_T ppmax = RasterationPoint(line.ToPoint, ras); PixelPosition_T ppmin = RasterationPoint(line.FromPoint, ras); pixels.Add(ppmin); for (int i = 1; i < ppmax.Col - ppmin.Col; i++)// { PixelPosition_T cpp = new PixelPosition_T(ppmin.Row, ppmin.Col + i); pixels.Add(cpp); } pixels.Add(ppmax); return(pixels); }
static private Dictionary <IPoint, IFeature> RaterPtToVectorPt(IFeature pFeature) { Dictionary <IPoint, IFeature> feaAndCenterRaterPt = new Dictionary <IPoint, IFeature>(); newPiexlList = new List <PixelPosition_T>(); IPoint opt = new PointClass(); opt.X = 0; opt.Y = 0; double pixelsize = 1; IPolyline pFeaPly = pFeature.Shape as IPolyline; IEnvelope envelop = pFeaPly.Envelope; double xMin = envelop.XMin; double xMax = envelop.XMax; double yMin = envelop.YMin; double yMax = envelop.YMax; int rs = (int)((yMax - yMin) / pixelsize); int cs = (int)((xMax - xMin) / pixelsize); Raster_T mapras = new Raster_T(rs, cs, pixelsize, opt); mapras.Originpt.Y = yMax; mapras.Originpt.X = xMin; List <PixelPosition_T> pypixel = RasterationPolygon(pFeature, mapras, xMin, xMax); PixelPosition_T pp1 = pypixel[pypixel.Count - 1]; List <PixelPosition_T> newPiexl = new List <PixelPosition_T>(); Bitmap bmp = new Bitmap(mapras.Cols + 3, mapras.Rows + 2); foreach (PixelPosition_T pp in pypixel) { PixelPosition_T pix_T = new PixelPosition_T(); pix_T.Code = 1; pix_T.Col = Math.Abs(pp.Col) + 1; pix_T.Row = Math.Abs(pp.Row) + 1; newPiexl.Add(pix_T); } newPiexl.Reverse(); newPiexlList = ArrangePixel(newPiexl); PixelPosition_T[,] p1 = OneDemiConvertToTwo(rs + 2, cs + 3); PixelPosition_T[,] p2 = CalOne(p1); Dictionary <int, PixelPosition_T[, ]> p3 = CalTwo(p2); List <PixelPosition_T> test = TestDistanceSkeletonThinning(p3); IPoint newPeakPt = new PointClass(); if (test.Count == 1) { newPeakPt.X = xMin + test[0].Col; newPeakPt.Y = yMax - test[0].Row; newPeakPt.Z = 100; feaAndCenterRaterPt.Add(newPeakPt, pFeature); } else { double X = 0; double Y = 0; for (int i = 0; i < test.Count; i++) { X += xMin + test[i].Col; Y += yMax - test[i].Row; } newPeakPt.X = X / test.Count; newPeakPt.Y = Y / test.Count; newPeakPt.Z = 100; feaAndCenterRaterPt.Add(newPeakPt, pFeature); } return(feaAndCenterRaterPt); }