Here is some code that I use to subdivide envelopes. 

  /**
     * Create a grid of Envelopes for an Envelope with a number of rows and 
columns
     * @param envelope The Envelope
     * @param numberOfRows The number of rows
     * @param numberOfColumns The number of columns
     * @return An array of Envelopes
     */
    public Envelope[] createGrid(Envelope envelope, int numberOfRows, int 
numberOfColumns) {

        // Extract the origin, width, and height
        double minX = envelope.getMinX();
        double minY = envelope.getMinY();
        double width = envelope.getWidth();
        double height = envelope.getHeight();

        // Calculate the cell width and height
        double cellWidth = width / numberOfColumns;
        double cellHeight = height / numberOfRows;

        // Calculate the number of cells (Envelopes)
        int numberOfCells = numberOfRows * numberOfColumns;

        // Create the Envelope array
        Envelope[] envs = new Envelope[numberOfCells];

        // Fill the Envelope array
        int i = 0;
        for (int r = 0; r < numberOfRows; r++) {
            for (int c = 0; c < numberOfColumns; c++) {
                double x = minX + (r * cellWidth);
                double y = minY + (c * cellHeight);
                envs[i] = new Envelope(x, x + cellWidth, y, y + cellHeight);
                i++;
            }
        }

        return envs;
    }

Jared Erickson

>>> Sunburned Surveyor <[email protected]> 1/27/2009 4:49 PM >>>
Does anyone know of (or have) code that will take an envelope and
break it up into smaller envelopes of equal size? (I didn't see a
method in the Envelope class that performed this operation.)

Here is my use case:

I've got some shapefiles that are too large to work with in OpenJUMP.
I want to split one of these large shapefiles into a smaller shapefile
that I can work with. To do this I thought I could access the envelope
that covers all features in the Shapefile. I'd split this into a
number of smaller envelopes of equal size. I'll then use code from
deegree/Geotools to iteratively access each feature in the Shapefile
on disk. I'll determine which envelope each feature fits in, and I'll
stick that feature in a new Shapefile.

Thanks for any thoughts. I'll whip up some new code if no one has
existing code to do the trick.

The Sunburned Surveyor
_______________________________________________
jts-devel mailing list
[email protected] 
http://lists.refractions.net/mailman/listinfo/jts-devel

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

Reply via email to