Hi Michael,

Thank you for your help. I was able to use your code snippet. Worked great for 
what I needed. Gave very good incite on the VectorToRasterProcess magic! 

Mike

On Apr 5, 2011, at 4:43 AM, Michael Bedward wrote:

> Hi Mike,
> 
> I've just tried your code (slightly modified). The problem is a bug in
> VectorToRasterProcess.
> 
> I'm not sure it's had much use with point features - other folk have
> used it for polygons and lines so you may be forging a new path :)  I
> haven't worked out what the problem is but there is definitely a
> problem.  However, I'm afraid I won't be able to get to it for some
> time.
> 
> Meanwhile, if you don't mind getting your hands dirty with some JAI
> code you could rasterize your points as in the snippet below. If you
> try it, let me know how it goes.
> 
> Michael
> 
> 
>        GridCoverageFactory gcf =
> CoverageFactoryFinder.getGridCoverageFactory(null);
>        WritableRaster raster =
> RasterFactory.createBandedRaster(DataBuffer.TYPE_FLOAT, numCols,
> numRows, 1, new java.awt.Point(0, 0));
>        GridCoverage2D cov = gcf.create("mycov", raster, new
> ReferencedEnvelope(minx, maxx, miny, maxy, crs));
> 
>        GridGeometry2D gg = cov.getGridGeometry();
>        SimpleFeatureIterator iter = collection.features();
> 
>        try {
>            while (iter.hasNext()) {
>                SimpleFeature feature = iter.next();
>                Geometry p = (Geometry) feature.getDefaultGeometry();
>                Float value = (Float) feature.getAttribute("value");
> 
>                Coordinate pcoord = p.getCoordinate();
>                DirectPosition pos = new DirectPosition2D(pcoord.x, pcoord.y);
> 
>                GridCoordinates2D gc = gg.worldToGrid(pos);
>                raster.setSample(gc.x, gc.y, 0, value);
>            }
>        } finally {
>            iter.close();
>        }
> 
> 
> Michael
> 
> On 2 April 2011 12:17, Mike O'Toole <[email protected]> wrote:
>> Thank You Michael.
>> 
>> That solved my problem perfectly. I'm now having an issue with the evaluate 
>> returning 0.0 every time. The following is a simplified version of my code. 
>> I have a latitude, longitude, and value for points that I'm creating a 
>> feature collection with. I then use the VectorToRasterProcess to create my 
>> GridCoverage. I've read through all the documentation and can't seem to 
>> figure out what I'm missing. Again pointing me in the right direction is 
>> greatly appreciated.
>> 
>> -Mike
>> 
>> // Setup CRS
>> Hints hints = new Hints( Hints.CRS, DefaultEngineeringCRS.CARTESIAN_2D );
>> GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( hints 
>> );
>> 
>> SimpleFeatureType TYPE = 
>> DataUtilities.createType("location","geom:Point,value:Float");
>> 
>> SimpleFeatureCollection collection = 
>> FeatureCollections.newCollection("ExampleSetFeatureCollection");
>> 
>> // Loop and add features
>> Coordinate coord1 = new Coordinate( currentLat, currentLon);
>> Point point1 = geometryFactory.createPoint( coord1 );
>> SimpleFeature feature = SimpleFeatureBuilder.build( TYPE, new Object[]{ 
>> point1, currentDoubleValue.floatValue() }, null );
>> collection.add( feature );
>> 
>> // Setup for process
>> ProgressListener progress = new ProgressWindow(null);
>> Dimension gridDim = new Dimension(1000,1000);
>> 
>> GridCoverage2D gridCoverage = VectorToRasterProcess.process(
>>                collection,
>>                "value",
>>                gridDim,
>>                collection.getBounds(),
>>                "ExampleSetGridCoverage",
>>                progress);
>> 
>> // Create point with known location from my raw data.
>> DirectPosition point = new 
>> DirectPosition2D(DefaultEngineeringCRS.CARTESIAN_2D, 38.969614330552, 
>> -121.512359247084);
>> float[] value = (float[]) gridCoverage.evaluate(point);
>> 
>> // This shows the point to be 0.0 no matter the location I give it.
>> System.out.println("Known Point: Lat:38.969614330552 Lon:-121.512359247084 
>> value:" + value[0]);
>> 
>> 
>> On Mar 29, 2011, at 11:12 PM, Michael Bedward wrote:
>> 
>>> Hi Mike,
>>> 
>>> It's just Java's typing being a bit painful.  A DirectPosition2D
>>> object is a Point2D object with geospatial extras.
>>> 
>>> What I usually do use DirectPosition references instead which avoids
>>> the ambiguity...
>>> 
>>>        DirectPosition pos = new DirectPosition2D(myCRS, x, y);
>>>        dest = cov.evaluate(pos, dest);
>>> 
>>> The only hassle with this is that you can no longer say pos.x and
>>> pos.y. Instead you have to say pos.getOrdinate(0) and
>>> pos.getOrdinate(1) which is clunky.
>>> 
>>> The other option of course is to explicitly cast...
>>> 
>>>        DirectPosition2D pos = new DirectPosition2D(myCRS, x, y);
>>>        dest = cov.evaluate( (DirectPosition2D)pos, dest);
>>> 
>>> Your mission is to decide which of these is the least worst :)
>>> 
>>> Hope that helps,
>>> 
>>> Michael
>>> 
>>> 
>>> On 30 March 2011 15:38, Mike O'Toole <[email protected]> wrote:
>>>> Hello all,
>>>> I'm brand new to GeoTools. I'm trying to use the evaluate() method on my
>>>> GridCoverge2D object. However I get a reference to evaluate is ambiguous
>>>> error.
>>>> Error:
>>>> reference to evaluate is ambiguous, both method
>>>> evaluate(org.opengis.geometry.DirectPosition,double[]) in
>>>> org.geotools.coverage.AbstractCoverage and method
>>>> evaluate(java.awt.geom.Point2D,double[]) in
>>>> org.geotools.coverage.grid.GridCoverage2D match
>>>> 
>>>> Here is the code snippet:
>>>> DirectPosition2D nextPoint = new DirectPosition2D(sphericalMercator, x, y);
>>>> 
>>>> double[] dest = gridCoverage.evaluate(nextPoint, dest);
>>>> 
>>>> Any help pointing me in the right direction is greatly appreciated and let
>>>> me know if more information is needed.
>>>> Thank You,
>>>> Mike
>>>> ------------------------------------------------------------------------------
>>>> Enable your software for Intel(R) Active Management Technology to meet the
>>>> growing manageability and security demands of your customers. Businesses
>>>> are taking advantage of Intel(R) vPro (TM) technology - will your software
>>>> be a part of the solution? Download the Intel(R) Manageability Checker
>>>> today! http://p.sf.net/sfu/intel-dev2devmar
>>>> _______________________________________________
>>>> Geotools-gt2-users mailing list
>>>> [email protected]
>>>> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>>>> 
>>>> 
>> 
>> 


------------------------------------------------------------------------------
Forrester Wave Report - Recovery time is now measured in hours and minutes
not days. Key insights are discussed in the 2010 Forrester Wave Report as
part of an in-depth evaluation of disaster recovery service providers.
Forrester found the best-in-class provider in terms of services and vision.
Read this report now!  http://p.sf.net/sfu/ibm-webcastpromo
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to