Hi Linda

> I am trying the following: I want to receive a shape file from the user, put
> it into another crs and then rasterize it by give the user the opportunity
> to choose an attribute. the other attributes shall be put in kind of a
> matrix like an appendix. and every cell needs a new and unique identifier.
> is this possible? how can I do this.

Nice question :-)

VectorToRasterProcess in the gt-process module is your friend to
rasterize the shapefile. In that class there is a static method
"process" which is the easiest way to setup and call the rasterizing
process...

    public static GridCoverage2D process(
            FeatureCollection<SimpleFeatureType, SimpleFeature> features,
            String attributeName,
            Dimension gridDim,
            Envelope bounds,
            String covName,
            ProgressListener monitor) throws VectorToRasterException

The attributeName parameter is the name of a numeric feature
attribute.  So, at the moment, you need a unique integer id attribute
in the shapefile that you can use for cell values and then as the
index into the associated attribute table (your "matrix").

Thinking...  (very slow process)...  It would be nice to extend the
rasterizing class so that you could pass in an
org.opengis.filter.expression.Expression parameter instead of a String
attribute name.  That would allow you to specify a filter function to
generate unique integer Ids from the text feature ids in the shapefile
plus do lots of other cool things like recoding and interpolating
feature values.

Just created an issue for that:
http://jira.codehaus.org/browse/GEOT-3007

> Is there a possibility to set very special parameters for a grid coverage? I
> want to set the resolution of one cell in meter or kilometer, the origin in
> the lower left corner and grid orientation and stuff like that. Is this
> possible?
>

If you mean the grid coverage that you get from rasterizing features,
that is handled by the 'gridDim' and 'bounds' parameters that you pass
to the process method.  For example...

FeatureCollection<SimpleFeatureType, SimpleFeature> coll = ...  //
features from shapefile

double gridCellWidth = ...  // desired cell width in world distance units
ReferencedEnvelope gridEnv = createEnclosingEnvelope(coll.getBounds(),
gridCellWidth);

Dimension gridDim = new Dimension(
    (int) (gridEnv.getWidth() / gridCellWidth),
    (int) (gridEnv.getHeight() / gridCellWidth) );

Where the functions called by the above code snippet are:

    private ReferencedEnvelope
createEnclosingEnvelope(ReferencedEnvelope env, double gridCellWidth)
{
        double minX = roundOrdinate(env.getMinimum(0), gridCellWidth, false);
        double maxX = roundOrdinate(env.getMaximum(0), gridCellWidth, true);
        double minY = roundOrdinate(env.getMinimum(1), gridCellWidth, false);
        double maxY = roundOrdinate(env.getMaximum(1), gridCellWidth, true);

        return new ReferencedEnvelope(minX, maxX, minY, maxY,
env.getCoordinateReferenceSystem());
    }

    private static final double EPS = 1.0E-8D;
    private double roundOrdinate(double ordinate, double divisor,
boolean roundUp) {
        if (roundUp) {
            double x = ordinate / divisor;
            int up = (x - (long)x) > EPS ? 1 : 0;
            return divisor * (up + (long) x);
        } else {
            return divisor * (long) (ordinate / divisor);
        }
    }

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to