@ SuppressWarnings ( "unchecked" ) @ Execute public void process ( ) throws Exception { checkNull ( inVector , pMaxOverlap , inRaster ) ; RandomIter rasterIter = CoverageUtilities . getRandomIterator ( inRaster ) ; GridGeometry2D gridGeometry = inRaster . getGridGeometry ( ) ; double [ ] tm_utm_tac = new double [ 3 ] ; STRtree circlesTree = FeatureUtilities . featureCollectionToSTRtree ( inVector ) ; List < SimpleFeature > circlesList = FeatureUtilities . featureCollectionToList ( inVector ) ; DefaultFeatureCollection outFC = new DefaultFeatureCollection ( ) ; for ( SimpleFeature circleFeature : circlesList ) { Geometry geometry = ( Geometry ) circleFeature . getDefaultGeometry ( ) ; Polygon circle = ( Polygon ) geometry . getGeometryN ( 0 ) ; PreparedGeometry preparedCircle = PreparedGeometryFactory . prepare ( circle ) ; List < SimpleFeature > circlesAround = circlesTree . query ( circle . getEnvelopeInternal ( ) ) ; List < Geometry > intersectedCircles = new ArrayList < Geometry > ( ) ; for ( SimpleFeature circleAround : circlesAround ) { if ( circleAround . equals ( circleFeature ) ) { continue ; } Geometry circleAroundGeometry = ( Geometry ) circleAround . getDefaultGeometry ( ) ; if ( preparedCircle . intersects ( circleAroundGeometry ) ) { intersectedCircles . add ( circleAroundGeometry ) ; } } Point centroid = circle . getCentroid ( ) ; int intersectionsCount = intersectedCircles . size ( ) ; if ( intersectionsCount != 0 ) { // check how many circles overlapped if ( intersectionsCount > pMaxOverlapCount ) { continue ; } // check if the circles overlap too much, i.e. cover their baricenter boolean intersected = false ; for ( Geometry intersectedCircle : intersectedCircles ) { if ( intersectedCircle . intersects ( centroid ) ) { intersected = true ; break ; } } if ( intersected ) { continue ; } } // check if the center has a raster value, i.e. is not empty double value = CoverageUtilities . getValue ( inRaster , centroid . getCoordinate ( ) ) ; if ( ! HMConstants . isNovalue ( value ) ) { continue ; } // check if the inner part of the circle is indeed rather empty // min, max, mean, var, sdev, activeCellCount, passiveCellCount double [ ] stats = OmsZonalStats . polygonStats ( circle , gridGeometry , rasterIter , false , tm_utm_tac , 0 , pm ) ; // if we have many more active cells than passive cells, that is not a circle double activeCells = stats [ 5 ] ; double novalues = stats [ 6 ] ; if ( activeCells * 1.5 > novalues ) { continue ; } // take it as valid circle outFC . add ( circleFeature ) ; } outCircles = outFC ; rasterIter . done ( ) ; }
VARS DESCR END