Hi Martin, many thanks for your help.
It took me a while to find the time to work on my problem again. I came up with a similar solution to your suggestion. I took the suggestion from Martin Davis ( http://lists.jump-project.org/pipermail/jts-devel/2009-March/002912.html ) and created an STRtree. This way i only need to create the „polygon raster“ once since I have many LineStrings of a strongly overlapping rectangular area. I decided not to work on the gridcoverage, because I couldn't figure out on how to access the original WritableRaster instance and I wanted to avoid to create a new GridCoverage after each change. I like your convertRealToRaster function. Now, since i am not working on the GrindCoverage i can't use the gridCoverage.getGridGeometry().getGridToCRS().inverse() function anymore. Your function works perfect to get the job done. I belief, I found one little thing in your code that needs to be fixed. Between line 207 and 213 you create the points of a linearRing to later test the intersection with. But you only create 3 individual points... shouldn't it be 4? Right now I think you create a triangle?! - I just started to work with this api, so I might be wrong. Thanks again Pete ps. my code... it's messy so i'll post the interesting part 1. creating strtree for (double y = worldMinY; y < worldMaxY; y += cellHeight) { for (double x = worldMinX; x < worldMaxX; x += cellWidth) { cellCoordinates = new Coordinate[5]; // x o // o o cellCoordinates[0] = new Coordinate( x, y ); // o x // o o cellCoordinates[1] = new Coordinate( x + cellWidth, y ); // o o // o x cellCoordinates[2] = new Coordinate( x + cellWidth, y + cellHeight ); // o o // x o cellCoordinates[3] = new Coordinate( x, y + cellHeight ); // x o // o o closing ring cellCoordinates[4] = cellCoordinates[0]; LinearRing lr = geometryFactory.createLinearRing( cellCoordinates ); Polygon p = geometryFactory.createPolygon( lr, null ); strTree.insert( p.getEnvelopeInternal(), p ); } } 2. get the overlapping rectangle ArrayListVisitor visitor = new ArrayListVisitor(); strTree.query( ls.getEnvelopeInternal(), visitor ); 3. check if an intersection exists Object[] geoms = visitor.getItems().toArray( new Object[visitor.getItems().size()] ); for (int i = 0; i < geoms.length; i++) { if ( !ls.intersects( (Geometry) geoms[i] ) ) { .... On Mon, Mar 2, 2009 at 7:29 PM, Martin Schmitz <[email protected]> wrote: > > Hey Pete, > > as promised attached a snapshot of my GridUtil class. > The method you maybe want to use is: > > WritableRaster getOverlappingCells(...) > or > GridCoverage2D getOverlappingCells(...) > > Note: The methods do NOT mark the cells in the source raster!! Instead a > new raster instance is returned! > > BTW: > The algorithm is not very intelligent! Similar to your idea, it checks > all raster cells within the bounding box of the given LineString (or > other Geometry). For each cells a polygon is created and checked for > intersection with the given LineString (or other Geometry). > In the case of intersection the cell is marked with a given value in an > output WritableRaster. > > Kind regards > > Martin > > Pete schrieb: > > Hi Martin, > > > > that would be awesome. > > > > I'm reading the API up and down trying to find a good solution... > > > > regards, > > Pete > > > > 2009/3/1 Martin Schmitz <[email protected]> > > > >> I think I already have a solution for you (Helper method in my own > >> library). > >> At the moment I am a little bit busy. So I will post it tomorrow, ok? > >> > >> Kind regards > >> > >> Martin Schmitz > >> > >> Pete schrieb: > >> > >>> Hello, > >>> > >>> I painted a small Graphic that should help to understand my current > >>> problem (I didn't want to post it on the mailing list directly) > >>> > >>> Here is the Link to the graphic. > >>> http://bayimg.com/oaNDJAaBn > >>> > >>> > >>> I created a GridCoverage with a specified cellsize to rasterize an area > >>> > >>> double width = envelope.getWidth(); // i.e. 1000m > >>> double height = envelope.getHeight(); // i.e. 1000m > >>> > >>> int numCellX = (int) Math.floor( width / cellSize ); // cellSize i.e. 10m > >>> int numCellY = (int) Math.floor( height / cellSize ); > >>> > >>> WritableRaster raster = RasterFactory.createBandedRaster( > >>> DataBuffer.TYPE_FLOAT, > >>> numCellX, numCellY, 1, null ); > >>> > >>> GridCoverage2D gridCoverage = factory.create( "My coverage", > >>> raster, > >>> envelope ); > >>> > >>> > >>> Now my Problem: > >>> > >>> The values of a cell in the raster depends on the length of the LineString > >>> covering the cell. > >>> (in my Image the green part of the LineString would determine the value of > >>> d;2) > >>> > >>> I belive that their is no function available doing that. > >>> So my idea to solve my problem is some workaround I'm not really satisfied > >>> with. > >>> > >>> 1.create a graph corresponding to the raster (width, height and cellsize) > >>> 2.for a given LineString find all intersection points with the created > >>> graph > >>> 3.for all following intersection points (i, i+1) > >>> a.calculate the length -> value for the cell > >>> b.get the middle point between (i, i+1) to find the corresponding > >>> cell > >>> c.add value to cell > >>> > >>> Maybe somebody has a smarter idea to solve my problem. > >>> > >>> Thanks > >>> > >>> > >>> ------------------------------------------------------------------------ > >>> > >>> > >>> ------------------------------------------------------------------------------ > >>> Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, > >>> CA > >>> -OSBC tackles the biggest issue in open source: Open Sourcing the > >>> Enterprise > >>> -Strategies to boost innovation and cut costs with open source > >>> participation > >>> -Receive a $600 discount off the registration fee with the source code: > >>> SFAD > >>> http://p.sf.net/sfu/XcvMzF8H > >>> > >>> > >>> ------------------------------------------------------------------------ > >>> > >>> _______________________________________________ > >>> Geotools-gt2-users mailing list > >>> [email protected] > >>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > >>> > >> > > ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
