Hello again Mike, Point rasterizing should now work with the VectorToRasterProcess class. Some issues with registration of vector and raster feature coordinates have also been fixed. Details are here:
http://jira.codehaus.org/browse/GEOT-3509 http://jira.codehaus.org/browse/GEOT-3510 If you want to try the new code you can use either GeoTools version 2.7-SNAPSHOT or 8.0-SNAPSHOT. Details on how to use the snapshot builds with maven are here: http://docs.geotools.org/stable/userguide/quickstart.html#what-is-a-geotools-snapshot-version-and-how-do-i-use-it Michael On 13 April 2011 12:49, Michael Bedward <[email protected]> wrote: > Hi Mike, > > That's good to hear. I'll add that code to the VectorToRasterProcess > class to deal with point data. > > Thanks for being a guinea pig :) > > Michael > > > On 13 April 2011 11:23, Mike O'Toole <[email protected]> wrote: >> 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 >>>>>> >>>>>> >>>> >>>> >> >> > ------------------------------------------------------------------------------ Benefiting from Server Virtualization: Beyond Initial Workload Consolidation -- Increasing the use of server virtualization is a top priority.Virtualization can reduce costs, simplify management, and improve application availability and disaster protection. Learn more about boosting the value of server virtualization. http://p.sf.net/sfu/vmware-sfdev2dev _______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
