Hi Ian,
Thanks for you very fast reply (and sorry for having used the wrong mailing
list)! We will investigate how to make the code more efficient, but this
will definitely help to get started with raster processing.
Cheers,
Jan
--------------------------------------
*Geodan*
Buitenhaven 27-A
5211 TP 's-Hertogenbosch (NL)
T +31 (0)73 - 692 5151
M +31 (0)6 - 2395 1191
E jan.boo...@geodan.nl
www.geodan.nl | disclaimer <http://www.geodan.nl/disclaimer>
--------------------------------------
2018-01-09 14:49 GMT+01:00 Ian Turton <ijtur...@gmail.com>:
> (Redirected to user list where it should live)
>
> Here is some working code (https://gist.github.com/ianturton/
> e54c41169ef32f48b1ac9b93c580e165) - but I suspect it could be much more
> efficient.
>
> Ian
>
> On 9 January 2018 at 11:27, Ian Turton <ijtur...@gmail.com> wrote:
>
>> There may be a better way than this but I would start by creating the new
>> raster
>>
>> WritableRaster writableRaster = RasterFactory.createBandedRast
>> er(java.awt.image.DataBuffer.TYPE_DOUBLE, width,
>> height, 1, null);
>> GridCoverageFactory factory = CoverageFactoryFinder.getGridC
>> overageFactory(null);
>> GridCoverage2D gc = factory.create("ResPop", writableRaster, bounds);
>>
>> copying the old one in to it and then clipping my raster to the envelope
>> of the polygon
>>
>> public GridCoverage2D clip(GridCoverage2D coverage, ReferencedEnvelope
>> envelope) {
>> CoverageProcessor processor = CoverageProcessor.getInstance();
>>
>> // An example of manually creating the operation and parameters we
>> want
>> final ParameterValueGroup param = processor.getOperation("Covera
>> geCrop").getParameters();
>> param.parameter("Source").setValue(coverage);
>> param.parameter("Envelope").setValue(envelope);
>>
>> return (GridCoverage2D) processor.doOperation(param);
>>
>> }
>>
>> and then step through the remaining pixels - checking if the centre(?)
>> was in the polygon and changing them as required
>>
>> GridEnvelope gridRange2D = grid.getGridGeometry().getGridRange();
>> for(int i=gridRange2D.getLow(0);i<gridRange2D.getHigh(0);i++) {
>> for(int j=gridRange2D.getLow(1);j<gridRange2D.getHigh(1);j++) {
>> Point2D p = grid.gridToWorld(new GridCoordinate2D(i,j));
>> if(poly.contains(p)){
>> int[] dest = new int[1];
>> grid.evaluate(new GridCoordinates2D(i, j), dest );
>> System.out.println(i+","+j+"="+dest[0]);
>> writableRaster.setDataElements(c.x, c.y, data);
>> }
>> }
>> }
>>
>> I haven't actually tested any of this but it looks plausible
>>
>> Ian
>>
>> On 9 January 2018 at 09:41, Jan Boonen <jan.boo...@geodan.nl> wrote:
>>
>>> Hi list,
>>>
>>> For a complex GIS editing application I want to use GeoTools to replace
>>> values in a coverage. The cells, whose values need to be replaced, must be
>>> selected using an intersection with a JTS Geometry. All editing may be done
>>> on in-memory coverages, only the end result will be written to a file.
>>>
>>> I have read through the tutorials and JavaDoc, but thus far I haven't
>>> been able to figure out how to do an intersection on a coverage and how to
>>> replace the value of individual cells. Would anybody be so kind to give me
>>> some hints?
>>>
>>> Thanks in advance!
>>>
>>> Cheers,
>>>
>>> Jan
>>>
>>> ------------------------------------------------------------
>>> ------------------
>>> Check out the vibrant tech community on one of the world's most
>>> engaging tech sites, Slashdot.org! http://sdm.link/slashdot
>>> _______________________________________________
>>> GeoTools-Devel mailing list
>>> geotools-de...@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/geotools-devel
>>>
>>>
>>
>>
>> --
>> Ian Turton
>>
>
>
>
> --
> Ian Turton
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users