//public IFeatureClass createPolygons3() //{ // createFeatureClass(); //} public IFeatureClass createPolygons2() { createFeatureClass(); IRasterProps rsProp = (IRasterProps)inputRaster; int bndCnt = ((IRasterBandCollection)inputRaster).Count; IPnt rsPnt = rsProp.MeanCellSize(); double cellArea = rsPnt.X * rsPnt.Y; double tCells = minArea / cellArea; IFunctionRasterDataset sDset = rsUtil.createMeanShiftFuction(inputRaster, (int)tCells); FunctionRasters.meanShiftFunctionDataset rFunc = (FunctionRasters.meanShiftFunctionDataset)sDset.Function; IRaster2 rs2 = (IRaster2)rsUtil.createRaster(sDset); IRasterCursor rsCur = rs2.CreateCursorEx(null); IRasterDomainExtractor dExt = new RasterDomainExtractorClass(); do { IPixelBlock pb = rsCur.PixelBlock; IFunctionRasterDataset pbDset = rsUtil.PixelBlockToRaster(pb, rsCur.TopLeft, sDset); IRaster rs = rsUtil.createRaster(pbDset); int numClusters = rFunc.NumClusters; for (int c = 0; c < numClusters; c++) { IFunctionRasterDataset fd = rsUtil.calcEqualFunction(pbDset, c); IFunctionRasterDataset fd2 = rsUtil.setNullValue(fd, 0); IPolygon polys = dExt.ExtractDomain(rsUtil.createRaster(fd2), true); } } while (rsCur.Next() == true); System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur); return(outftr); }
private void splitFeature(IPolygon4 subPoly, ref HashSet <IPolygon4>[] polys) { IRaster clipRs = rsUtil.createRaster(rsUtil.clipRasterFunction(inputRaster, subPoly, esriRasterClippingType.esriRasterClippingOutside)); esriUtil.Statistics.dataPrepClusterBinary dpClus = new Statistics.dataPrepClusterBinary(clipRs, specificity, 100000, 0.001); IFunctionRasterDataset clusRs = rsUtil.calcClustFunctionBinary(inputRaster, dpClus); IFunctionRasterDataset clipRs2 = rsUtil.clipRasterFunction(clusRs, subPoly, esriRasterClippingType.esriRasterClippingOutside); IRasterDomainExtractor domExtract = new RasterDomainExtractorClass(); for (int i = 0; i < specificity; i++) { IFunctionRasterDataset bRs = rsUtil.calcEqualFunction(clipRs2, i); IRaster mRs = rsUtil.createRaster(rsUtil.setNullValue(bRs, 0)); IPolygon4 poly = (IPolygon4)domExtract.ExtractDomain(mRs, false); IGeometryBag geoBag = poly.ConnectedComponentBag; IGeometryCollection geoColl = (IGeometryCollection)geoBag; for (int j = 0; j < geoColl.GeometryCount; j++) { IPolygon4 sp = (IPolygon4)geoColl.get_Geometry(j); double subPolyArea = ((IArea)sp).Area; //double subPolyLength = subPoly.Length; if (subPolyArea > maxArea) { splitFeature(sp, ref polys); // should split polygons. smaller than acceptable go into polys[0] ok go into polys[1] } else if (subPolyArea < minArea) { polys[0].Add(sp); } else { polys[1].Add(sp); } //segid++; } } }
private void extractDomains(IRaster clusRs, Statistics.dataPrepClusterBinary dpClus) { if (outftr == null) { mfldIndex = new int[bCnt]; segIndex = 0; IFields flds = new FieldsClass(); IFieldsEdit fldsE = (IFieldsEdit)flds; IField fld = new FieldClass(); IFieldEdit fldE = (IFieldEdit)fld; fldE.Name_2 = "SegID"; fldE.Type_2 = esriFieldType.esriFieldTypeInteger; fldsE.AddField(fldE); //IField fld2 = new FieldClass(); //IFieldEdit fldE2 = (IFieldEdit)fld2; //fldE2.Name_2 = "Cluster"; //fldE2.Type_2 = esriFieldType.esriFieldTypeInteger; //fldsE.AddField(fldE2); //for (int i = 0; i < bCnt; i++) //{ // IField mFld = new FieldClass(); // IFieldEdit mFldE = (IFieldEdit)mFld; // mFldE.Name_2 = "Band" + i.ToString(); // mFldE.Type_2 = esriFieldType.esriFieldTypeDouble; // fldsE.AddField(mFld); //} outftr = geoUtil.createFeatureClass((IWorkspace2)OutWorkSpace, OutName, flds, esriGeometryType.esriGeometryPolygon, ((IRasterProps)clusRs).SpatialReference); segIndex = outftr.FindField("SegID"); //clustIndex = outftr.FindField("Cluster"); //for (int i = 0; i < bCnt; i++) //{ // mfldIndex[i] = outftr.FindField("Band" + i.ToString()); //} } IRasterDomainExtractor domExtract = new RasterDomainExtractorClass(); IRasterProps rsp = (IRasterProps)clusRs; IRasterCursor rsCur = ((IRaster2)clusRs).CreateCursorEx(null); IPnt cellSizeRs = rsp.MeanCellSize(); double pSizeX = cellSizeRs.X; double pSizeY = cellSizeRs.Y; int blockCnt = 1; do { IPixelBlock pb = rsCur.PixelBlock; IFunctionRasterDataset fDset = rsUtil.PixelBlockToRaster(pb, rsCur.TopLeft, clusRs); Console.WriteLine(blockCnt); //rsUtil.saveRasterToDataset(rsUtil.createRaster(fDset), "bTest"+blockCnt.ToString(), OutWorkSpace); HashSet <IPolygon4>[] polys = new HashSet <IPolygon4> [2];//small,good polygons for (int h = 0; h < 2; h++) { polys[h] = new HashSet <IPolygon4>(); } for (int i = 0; i < specificity; i++) { //double[] means = ((Accord.MachineLearning.BinarySplit)dpClus.Model).Clusters[i].Mean; IFunctionRasterDataset bRs = rsUtil.calcEqualFunction(fDset, i); IRaster mRs = rsUtil.createRaster(rsUtil.setNullValue(bRs, 0)); IPolygon4 poly = (IPolygon4)domExtract.ExtractDomain(mRs, false); IGeometryBag geoBag = poly.ConnectedComponentBag; IGeometryCollection geoColl = (IGeometryCollection)geoBag; for (int j = 0; j < geoColl.GeometryCount; j++) { IPolygon4 subPoly = (IPolygon4)geoColl.get_Geometry(j); double subPolyArea = ((IArea)subPoly).Area; double subPolyLength = subPoly.Length; if (subPolyArea > maxArea) { splitFeature(subPoly, ref polys); // should split polygons. smaller than acceptable go into polys[0] ok go into polys[1] } else if (subPolyArea < minArea) { polys[0].Add(subPoly); } else { polys[1].Add(subPoly); } //segid++; } //addToNeighboringFeature(ref polys); IFeatureCursor ftrCur = outftr.Insert(true); IFeatureBuffer nFtr = outftr.CreateFeatureBuffer(); Console.WriteLine("\tFTR Count small " + polys[0].Count.ToString()); Console.WriteLine("\tFTR Count big " + polys[1].Count.ToString()); foreach (IPolygon4 p in polys[1]) { nFtr.Shape = (IGeometry)p; nFtr.set_Value(segIndex, segid); ftrCur.InsertFeature(nFtr); segid++; } foreach (IPolygon p in polys[0]) { nFtr.Shape = (IGeometry)p; nFtr.set_Value(segIndex, segid); ftrCur.InsertFeature(nFtr); segid++; } ftrCur.Flush(); System.Runtime.InteropServices.Marshal.ReleaseComObject(nFtr); System.Runtime.InteropServices.Marshal.ReleaseComObject(ftrCur); } blockCnt++; } while (rsCur.Next() == true); System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur); }
private void splitFeature(IPolygon4 subPoly, ref HashSet<IPolygon4>[] polys) { IRaster clipRs = rsUtil.createRaster(rsUtil.clipRasterFunction(inputRaster, subPoly, esriRasterClippingType.esriRasterClippingOutside)); esriUtil.Statistics.dataPrepClusterBinary dpClus = new Statistics.dataPrepClusterBinary(clipRs, specificity,100000,0.001); IFunctionRasterDataset clusRs = rsUtil.calcClustFunctionBinary(inputRaster, dpClus); IFunctionRasterDataset clipRs2 = rsUtil.clipRasterFunction(clusRs, subPoly, esriRasterClippingType.esriRasterClippingOutside); IRasterDomainExtractor domExtract = new RasterDomainExtractorClass(); for (int i = 0; i < specificity; i++) { IFunctionRasterDataset bRs = rsUtil.calcEqualFunction(clipRs2, i); IRaster mRs = rsUtil.createRaster(rsUtil.setNullValue(bRs, 0)); IPolygon4 poly = (IPolygon4)domExtract.ExtractDomain(mRs, false); IGeometryBag geoBag = poly.ConnectedComponentBag; IGeometryCollection geoColl = (IGeometryCollection)geoBag; for (int j = 0; j < geoColl.GeometryCount; j++) { IPolygon4 sp = (IPolygon4)geoColl.get_Geometry(j); double subPolyArea = ((IArea)sp).Area; //double subPolyLength = subPoly.Length; if (subPolyArea > maxArea) { splitFeature(sp, ref polys); // should split polygons. smaller than acceptable go into polys[0] ok go into polys[1] } else if (subPolyArea < minArea) { polys[0].Add(sp); } else { polys[1].Add(sp); } //segid++; } } }
private void extractDomains(IRaster clusRs, Statistics.dataPrepClusterBinary dpClus) { if (outftr == null) { mfldIndex=new int[bCnt]; segIndex = 0; IFields flds = new FieldsClass(); IFieldsEdit fldsE = (IFieldsEdit)flds; IField fld = new FieldClass(); IFieldEdit fldE = (IFieldEdit)fld; fldE.Name_2 = "SegID"; fldE.Type_2 = esriFieldType.esriFieldTypeInteger; fldsE.AddField(fldE); //IField fld2 = new FieldClass(); //IFieldEdit fldE2 = (IFieldEdit)fld2; //fldE2.Name_2 = "Cluster"; //fldE2.Type_2 = esriFieldType.esriFieldTypeInteger; //fldsE.AddField(fldE2); //for (int i = 0; i < bCnt; i++) //{ // IField mFld = new FieldClass(); // IFieldEdit mFldE = (IFieldEdit)mFld; // mFldE.Name_2 = "Band" + i.ToString(); // mFldE.Type_2 = esriFieldType.esriFieldTypeDouble; // fldsE.AddField(mFld); //} outftr = geoUtil.createFeatureClass((IWorkspace2)OutWorkSpace, OutName, flds, esriGeometryType.esriGeometryPolygon, ((IRasterProps)clusRs).SpatialReference); segIndex = outftr.FindField("SegID"); //clustIndex = outftr.FindField("Cluster"); //for (int i = 0; i < bCnt; i++) //{ // mfldIndex[i] = outftr.FindField("Band" + i.ToString()); //} } IRasterDomainExtractor domExtract = new RasterDomainExtractorClass(); IRasterProps rsp = (IRasterProps)clusRs; IRasterCursor rsCur = ((IRaster2)clusRs).CreateCursorEx(null); IPnt cellSizeRs = rsp.MeanCellSize(); double pSizeX = cellSizeRs.X; double pSizeY = cellSizeRs.Y; int blockCnt = 1; do { IPixelBlock pb = rsCur.PixelBlock; IFunctionRasterDataset fDset = rsUtil.PixelBlockToRaster(pb, rsCur.TopLeft, clusRs); Console.WriteLine(blockCnt); //rsUtil.saveRasterToDataset(rsUtil.createRaster(fDset), "bTest"+blockCnt.ToString(), OutWorkSpace); HashSet<IPolygon4>[] polys = new HashSet<IPolygon4>[2];//small,good polygons for (int h = 0; h < 2; h++) { polys[h] = new HashSet<IPolygon4>(); } for (int i = 0; i < specificity; i++) { //double[] means = ((Accord.MachineLearning.BinarySplit)dpClus.Model).Clusters[i].Mean; IFunctionRasterDataset bRs = rsUtil.calcEqualFunction(fDset, i); IRaster mRs = rsUtil.createRaster(rsUtil.setNullValue(bRs, 0)); IPolygon4 poly = (IPolygon4)domExtract.ExtractDomain(mRs, false); IGeometryBag geoBag = poly.ConnectedComponentBag; IGeometryCollection geoColl = (IGeometryCollection)geoBag; for (int j = 0; j < geoColl.GeometryCount; j++) { IPolygon4 subPoly = (IPolygon4)geoColl.get_Geometry(j); double subPolyArea = ((IArea)subPoly).Area; double subPolyLength = subPoly.Length; if (subPolyArea > maxArea) { splitFeature(subPoly, ref polys); // should split polygons. smaller than acceptable go into polys[0] ok go into polys[1] } else if (subPolyArea < minArea) { polys[0].Add(subPoly); } else { polys[1].Add(subPoly); } //segid++; } //addToNeighboringFeature(ref polys); IFeatureCursor ftrCur = outftr.Insert(true); IFeatureBuffer nFtr = outftr.CreateFeatureBuffer(); Console.WriteLine("\tFTR Count small " + polys[0].Count.ToString()); Console.WriteLine("\tFTR Count big " + polys[1].Count.ToString()); foreach (IPolygon4 p in polys[1]) { nFtr.Shape = (IGeometry)p; nFtr.set_Value(segIndex, segid); ftrCur.InsertFeature(nFtr); segid++; } foreach (IPolygon p in polys[0]) { nFtr.Shape = (IGeometry)p; nFtr.set_Value(segIndex, segid); ftrCur.InsertFeature(nFtr); segid++; } ftrCur.Flush(); System.Runtime.InteropServices.Marshal.ReleaseComObject(nFtr); System.Runtime.InteropServices.Marshal.ReleaseComObject(ftrCur); } blockCnt++; } while (rsCur.Next() == true); System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur); }
//public IFeatureClass createPolygons3() //{ // createFeatureClass(); //} public IFeatureClass createPolygons2() { createFeatureClass(); IRasterProps rsProp = (IRasterProps)inputRaster; int bndCnt = ((IRasterBandCollection)inputRaster).Count; IPnt rsPnt = rsProp.MeanCellSize(); double cellArea = rsPnt.X * rsPnt.Y; double tCells = minArea / cellArea; IFunctionRasterDataset sDset = rsUtil.createMeanShiftFuction(inputRaster, (int)tCells); FunctionRasters.meanShiftFunctionDataset rFunc = (FunctionRasters.meanShiftFunctionDataset)sDset.Function; IRaster2 rs2 = (IRaster2)rsUtil.createRaster(sDset); IRasterCursor rsCur = rs2.CreateCursorEx(null); IRasterDomainExtractor dExt = new RasterDomainExtractorClass(); do { IPixelBlock pb = rsCur.PixelBlock; IFunctionRasterDataset pbDset = rsUtil.PixelBlockToRaster(pb, rsCur.TopLeft, sDset); IRaster rs = rsUtil.createRaster(pbDset); int numClusters = rFunc.NumClusters; for (int c = 0; c < numClusters; c++) { IFunctionRasterDataset fd = rsUtil.calcEqualFunction(pbDset, c); IFunctionRasterDataset fd2 = rsUtil.setNullValue(fd, 0); IPolygon polys = dExt.ExtractDomain(rsUtil.createRaster(fd2), true); } } while (rsCur.Next() == true); System.Runtime.InteropServices.Marshal.ReleaseComObject(rsCur); return outftr; }
public IGeometry extractDomain(IRaster rs, bool pCenterbased=false) { IRaster rs1 = rs; if (((IRasterBandCollection)rs1).Count > 1) { rs1 = createRaster(getBand(rs, 0)); } IRasterDomainExtractor dEx = new RasterDomainExtractorClass(); IPolygon poly = dEx.ExtractDomain(rs1,pCenterbased); return (IGeometry)poly; }