Intersections of cells in a GridCoverage with a LineString

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Intersections of cells in a GridCoverage with a LineString

Pete Ballack
Hello,
 
I posted the same question on the geotools-user-list and Michael Bedward responded as follows
 
"However, I suggest you pose the same question on the JTS list where
Martin Davis and the other geometric gurus might be able to help."
 
So here is my message...

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
Pete
 
here is the link to my posting on the geotools-mailing-list
 
 
 
_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Intersections of cells in a GridCoverage with a LineString

Martin Davis
How about creating a set of polygons equal in shape to your grid cells,
and then intersect the line string with each polygon that it touches?  
You can use a spatial index (STRtree) to speed up finding candidate
polygons.

Martin

Pete Ballack wrote:

> Hello,
>  
> I posted the same question on the geotools-user-list and Michael
> Bedward responded as follows
>  
> "However, I suggest you pose the same question on the JTS list where
> Martin Davis and the other geometric gurus might be able to help."
>  
> So here is my message...
>
> 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
> Pete
>  
> here is the link to my posting on the geotools-mailing-list
> http://n2.nabble.com/Intersections-of-cells-in-a-GridCoverage-with-a-LineString-td2405815.html
>  
>  
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

> Hello,
>  
> I posted the same question on the geotools-user-list and Michael
> Bedward responded as follows
>  
> "However, I suggest you pose the same question on the JTS list where
> Martin Davis and the other geometric gurus might be able to help."
>  
> So here is my message...
>
> 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
> Pete
>  
> here is the link to my posting on the geotools-mailing-list
> http://n2.nabble.com/Intersections-of-cells-in-a-GridCoverage-with-a-LineString-td2405815.html
>  
>  
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

> Hello,
>  
> I posted the same question on the geotools-user-list and Michael
> Bedward responded as follows
>  
> "However, I suggest you pose the same question on the JTS list where
> Martin Davis and the other geometric gurus might be able to help."
>  
> So here is my message...
>
> 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
> Pete
>  
> here is the link to my posting on the geotools-mailing-list
> http://n2.nabble.com/Intersections-of-cells-in-a-GridCoverage-with-a-LineString-td2405815.html
>  
>  
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

> Hello,
>  
> I posted the same question on the geotools-user-list and Michael
> Bedward responded as follows
>  
> "However, I suggest you pose the same question on the JTS list where
> Martin Davis and the other geometric gurus might be able to help."
>  
> So here is my message...
>
> 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
> Pete
>  
> here is the link to my posting on the geotools-mailing-list
> http://n2.nabble.com/Intersections-of-cells-in-a-GridCoverage-with-a-LineString-td2405815.html
>  
>  
>  
> ------------------------------------------------------------------------
>
> _______________________________________________
> jts-devel mailing list
> [hidden email]
> http://lists.refractions.net/mailman/listinfo/jts-devel
>  

--
Martin Davis
Senior Technical Architect
Refractions Research, Inc.
(250) 383-3022

_______________________________________________
jts-devel mailing list
[hidden email]
http://lists.refractions.net/mailman/listinfo/jts-devel
Loading...