Java Code Examples for org.geotools.data.simple.SimpleFeatureCollection#getBounds()

The following examples show how to use org.geotools.data.simple.SimpleFeatureCollection#getBounds() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NwwUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private static SimpleFeatureCollection reprojectToWGS84( SimpleFeatureCollection fc ) {
    // BOUNDS
    ReferencedEnvelope bounds = fc.getBounds();
    CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem();
    if (!CRS.equalsIgnoreMetadata(crs, GPS_CRS)) {
        try {
            fc = new ReprojectingFeatureCollection(fc, GPS_CRS);
        } catch (Exception e) {
            throw new IllegalArgumentException("The data need to be of WGS84 lat/lon projection.", e);
        }
    }
    return fc;
}
 
Example 2
Source File: RasterizedShapefilesFolderNwwLayer.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
private static GTRenderer getRenderer(File shapeFilesFolder) {
    File[] shpFiles = shapeFilesFolder.listFiles(new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.toLowerCase().endsWith(".shp");
        }
    });

    MapContent mapContent = new MapContent();
    for (File shpFile : shpFiles) {
        try {
            SimpleFeatureCollection readFC = NwwUtilities.readAndReproject(shpFile.getAbsolutePath());
            ReferencedEnvelope tmpBounds = readFC.getBounds();
            if (tmpBounds.getWidth() == 0 || tmpBounds.getHeight() == 0) {
                System.err.println("Ignoring: " + shpFile);
                continue;
            }
            // if (bounds == null) {
            // bounds = new ReferencedEnvelope(tmpBounds);
            // } else {
            // bounds.expandToInclude(tmpBounds);
            // }
            Style style = SldUtilities.getStyleFromFile(shpFile);
            if (style == null)
                style = SLD.createSimpleStyle(readFC.getSchema());

            FeatureLayer layer = new FeatureLayer(readFC, style);
            mapContent.addLayer(layer);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    GTRenderer renderer = new StreamingRenderer();
    renderer.setMapContent(mapContent);
    return renderer;
}
 
Example 3
Source File: DatabaseController.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
protected void showInMapFrame( boolean withLayers, SimpleFeatureCollection[] fcs, Style[] styles ) {
    if (mapFrame == null || !mapFrame.isVisible()) {
        Class<DatabaseController> class1 = DatabaseController.class;
        ImageIcon icon = new ImageIcon(class1.getResource("/org/hortonmachine/images/hm150.png"));
        mapFrame = new HMMapframe("Geometries Viewer");
        mapFrame.setIconImage(icon.getImage());
        mapFrame.enableToolBar(true);
        mapFrame.enableStatusBar(false);
        mapFrame.enableLayerTable(withLayers);
        mapFrame.enableTool(Tool.PAN, Tool.ZOOM, Tool.RESET);
        mapFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        if (withLayers) {
            mapFrame.setSize(900, 600);
        } else {
            mapFrame.setSize(600, 600);
        }
        mapFrame.setVisible(true);

    }
    ReferencedEnvelope renv = null;
    for( int i = 0; i < fcs.length; i++ ) {
        SimpleFeatureCollection fc = fcs[i];
        if (styles != null) {
            mapFrame.addLayer(fc, styles[i]);
        } else {
            mapFrame.addLayer(fc);
        }
        ReferencedEnvelope bounds = fc.getBounds();
        if (renv == null) {
            renv = bounds;
        } else {
            renv.expandToInclude(bounds);
        }
    }

    mapFrame.getMapPane().setDisplayArea(renv);
}
 
Example 4
Source File: GeopaparazziMapsCreator.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    checkNull(inROI, outFolder);

    SimpleFeatureCollection boundsVector = OmsVectorReader.readVector(inROI);
    ReferencedEnvelope bounds = boundsVector.getBounds();
    // bounds.expandBy(50.0);

    OmsTmsGenerator gen = new OmsTmsGenerator();
    if (inRaster1 != null || inRaster2 != null) {
        List<String> inRasters = new ArrayList<String>();
        if (inRaster1 != null)
            inRasters.add(inRaster1);
        if (inRaster2 != null)
            inRasters.add(inRaster2);
        gen.inRasterFile = FileUtilities.stringListAsTmpFile(inRasters).getAbsolutePath();
    }
    if (inVector1 != null || inVector2 != null || inVector3 != null || inVector4 != null || inVector5 != null) {
        List<String> inVectors = new ArrayList<String>();
        if (inVector1 != null)
            inVectors.add(inVector1);
        if (inVector2 != null)
            inVectors.add(inVector2);
        if (inVector3 != null)
            inVectors.add(inVector3);
        if (inVector4 != null)
            inVectors.add(inVector4);
        if (inVector5 != null)
            inVectors.add(inVector5);
        gen.inVectorFile = FileUtilities.stringListAsTmpFile(inVectors).getAbsolutePath();
    }
    gen.pMinzoom = pMinZoom;
    gen.pMaxzoom = pMaxZoom;
    gen.pName = pName;
    gen.inPath = outFolder;
    gen.pWest = bounds.getMinX();
    gen.pEast = bounds.getMaxX();
    gen.pNorth = bounds.getMaxY();
    gen.pSouth = bounds.getMinY();
    // gen.pEpsg = "EPSG:32632";
    gen.dataCrs = bounds.getCoordinateReferenceSystem();
    gen.doMbtiles = true;

    gen.inZoomLimitVector = inZoomLimitROI;
    gen.pZoomLimit = pZoomLimit;

    switch( pImageType ) {
    case "jpg":
        gen.pImagetype = 1;
        break;
    case "png":
    default:
        gen.pImagetype = 0;
        break;
    }
    gen.pm = pm;
    gen.process();

}