Java Code Examples for org.geotools.feature.simple.SimpleFeatureBuilder#addAll()

The following examples show how to use org.geotools.feature.simple.SimpleFeatureBuilder#addAll() . 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: TestScanLineRasterizer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private SimpleFeatureCollection doCollection( RegionMap envelopeParams ) {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("typename");
        b.setCRS(crs);
        b.add("the_geom", Polygon.class);
        b.add("cat", Double.class);
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Object[] values = new Object[]{polygon, 1.0};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(null);
        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        newCollection.add(feature);
        return newCollection;
    }
 
Example 2
Source File: OmsLW04_BankfullWidthAnalyzer.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private DefaultFeatureCollection getWidthLines( CoordinateReferenceSystem crs,
        ConcurrentLinkedQueue<Object[]> validPointsLineList ) throws Exception {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("net");
    b.setCRS(crs);
    b.add("the_geom", LineString.class);
    b.add(PFAF, String.class);
    b.add(LINKID, Integer.class);
    b.add(ARiverSectionsExtractor.FIELD_SECTION_ID, Integer.class);
    b.add(ARiverSectionsExtractor.FIELD_PROGRESSIVE, Double.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);

    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();

    for( Object[] objects : validPointsLineList ) {
        builder.addAll(objects);
        SimpleFeature feature = builder.buildFeature(null);
        newCollection.add(feature);
    }

    return newCollection;
}
 
Example 3
Source File: TinHandler.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public SimpleFeatureCollection toFeatureCollectionOthers() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("points");
    b.setCRS(crs);

    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    b.add("the_geom", Point.class);
    b.add("elev", Double.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    for( Coordinate c : leftOverCoordinateList ) {
        Object[] values = new Object[]{gf.createPoint(c), c.z};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(null);
        newCollection.add(feature);
    }
    return newCollection;
}
 
Example 4
Source File: TestFeatureUtils.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("nls")
public void testFeatureUtils() throws Exception {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("typename");
    b.setCRS(DefaultGeographicCRS.WGS84);
    b.add("the_geom", Point.class);
    b.add("AttrName", String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Object[] values = new Object[]{GeometryUtilities.gf().createPoint(new Coordinate(0, 0)), "test"};
    builder.addAll(values);
    SimpleFeature feature = builder.buildFeature(type.getTypeName());

    Object attr = FeatureUtilities.getAttributeCaseChecked(feature, "attrname");
    assertEquals("test", attr.toString());
    attr = FeatureUtilities.getAttributeCaseChecked(feature, "attrnam");
    assertNull(attr);
}
 
Example 5
Source File: TinHandler.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
public SimpleFeatureCollection toFeatureCollectionTinPoints() {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("points");
    b.setCRS(crs);

    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    b.add("the_geom", Point.class);
    b.add("elev", Double.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    for( Coordinate c : tinCoordinateList ) {
        Object[] values = new Object[]{gf.createPoint(c), c.z};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(null);
        newCollection.add(feature);
    }
    return newCollection;
}
 
Example 6
Source File: TestProfile.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private SimpleFeatureCollection doCollection() {
    CoordinateReferenceSystem crs = HMTestMaps.getCrs();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("typename");
    b.setCRS(crs);
    b.add("the_geom", LineString.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);

    Coordinate one = new Coordinate(westNorth.x + ep.getXres() / 2, centerCoord.y + ep.getYres() / 2);
    Coordinate two = new Coordinate(eastSouth.x - ep.getXres() / 2, centerCoord.y + ep.getYres() / 2);

    LineString lineString = GeometryUtilities.gf().createLineString(new Coordinate[]{one, two});
    Object[] values = new Object[]{lineString};
    builder.addAll(values);
    SimpleFeature feature = builder.buildFeature(null);
    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    newCollection.add(feature);
    return newCollection;
}
 
Example 7
Source File: OmsGridsGenerator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private void createPoints( CoordinateReferenceSystem crs, GeometryFactory gf, List<LineString> verticals,
        List<LineString> horizontals ) {
    outMap = new DefaultFeatureCollection();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(POINT);
    b.setCRS(crs);
    b.add("the_geom", Point.class);
    b.add("id", Long.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type);

    Geometry gVer = gf.createMultiLineString(verticals.toArray(new LineString[0]));
    Geometry gHor = gf.createMultiLineString(horizontals.toArray(new LineString[0]));

    Geometry intersection = gHor.intersection(gVer);

    long index = 0;
    int numGeometries = intersection.getNumGeometries();
    for( int i = 0; i < numGeometries; i++ ) {
        Geometry geometry = intersection.getGeometryN(i);
        Object[] values = new Object[]{geometry, index++};
        fbuilder.addAll(values);
        SimpleFeature feature = fbuilder.buildFeature(null);
        ((DefaultFeatureCollection) outMap).add(feature);
    }
}
 
Example 8
Source File: OmsGridsGenerator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
private void createPolygons( CoordinateReferenceSystem crs, GeometryFactory gf, List<Geometry> polygons ) {
    outMap = new DefaultFeatureCollection();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(POLYGON);
    b.setCRS(crs);
    b.add("the_geom", Polygon.class);
    b.add("id", Long.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder fbuilder = new SimpleFeatureBuilder(type);

    long index = 0;
    int numGeometries = polygons.size();
    for( int i = 0; i < numGeometries; i++ ) {
        Geometry geometry = polygons.get(i);
        Object[] values = new Object[]{geometry, index++};
        fbuilder.addAll(values);
        SimpleFeature feature = fbuilder.buildFeature(null);
        ((DefaultFeatureCollection) outMap).add(feature);
    }
}
 
Example 9
Source File: GeometryTranslator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Builds a line feature from a dwg polyline 3D.
 * 
 * TODO handle these as contourlines
 * 
 */
public SimpleFeature convertDwgPolyline3D( String typeName, String layerName,
        DwgPolyline3D polyline3d, int id ) {
    double[][] ptos = polyline3d.getPts();
    CoordinateList coordList = new CoordinateList();
    if (ptos != null) {
        for( int j = 0; j < ptos.length; j++ ) {
            Coordinate coord = new Coordinate(ptos[j][0], ptos[j][1], ptos[j][2]);
            coordList.add(coord);
        }

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName(typeName);
        b.setCRS(crs);
        b.add(THE_GEOM, LineString.class);
        b.add(LAYER, String.class);
        SimpleFeatureType type = b.buildFeatureType();
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
        Object[] values = new Object[]{lineString, layerName};
        builder.addAll(values);
        return builder.buildFeature(typeName + "." + id);
    }
    return null;
}
 
Example 10
Source File: GeometryTranslator.java    From hortonmachine with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Builds a line feature from a dwg line.
 * 
 */
public SimpleFeature convertDwgLine( String typeName, String layerName, DwgLine line, int id ) {
    double[] p1 = line.getP1();
    double[] p2 = line.getP2();
    Point2D[] ptos = new Point2D[]{new Point2D.Double(p1[0], p1[1]),
            new Point2D.Double(p2[0], p2[1])};
    CoordinateList coordList = new CoordinateList();
    for( int j = 0; j < ptos.length; j++ ) {
        Coordinate coord = new Coordinate(ptos[j].getX(), ptos[j].getY(), 0.0);
        coordList.add(coord);
    }

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(typeName);
    b.setCRS(crs);
    b.add(THE_GEOM, LineString.class);
    b.add(LAYER, String.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Geometry lineString = gF.createLineString(coordList.toCoordinateArray());
    Object[] values = new Object[]{lineString, layerName};
    builder.addAll(values);
    return builder.buildFeature(typeName + "." + id);
}
 
Example 11
Source File: MonitoringPoint.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a featurecollection from a list of monitoringpoints. Based on the position of the
 * points and some of their attributes.
 * 
 * @param monitoringPointsList
 * @return the featurecollection
 */
public SimpleFeatureCollection toFeatureCollection(
        List<MonitoringPoint> monitoringPointsList ) {

    // create the feature type
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    // set the name
    b.setName("monitoringpoints");
    // add a geometry property
    b.add("the_geom", Point.class);
    // add some properties
    b.add("id", Integer.class);
    b.add("relatedid", Integer.class);
    b.add("pfaf", String.class);
    // build the type
    SimpleFeatureType type = b.buildFeatureType();
    // create the feature
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);

    GeometryFactory gF = new GeometryFactory();
    /*
     * insert them in inverse order to get them out of the collection in the same order as the
     * list
     */
    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    for( int i = 0; i < monitoringPointsList.size(); i++ ) {
        MonitoringPoint mp = monitoringPointsList.get(monitoringPointsList.size() - i - 1);

        Object[] values = new Object[]{gF.createPoint(mp.getPosition()), mp.getID(),
                mp.getRelatedID(), mp.getPfatstetterNumber().toString()};
        // add the values
        builder.addAll(values);
        // build the feature with provided ID
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + i);
        newCollection.add(feature);
    }

    return newCollection;
}
 
Example 12
Source File: TinHandler.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a {@link SimpleFeatureCollection FeatureCollection} from the current tin triangles
 * with information about the vertexes elevation.
 * 
 * @return the feature collection of the tin.
 */
public SimpleFeatureCollection toFeatureCollection() {
    checkTinGeometries();
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("triangle");
    b.setCRS(crs);

    DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
    b.add("the_geom", Polygon.class);
    b.add("elev0", Double.class);
    b.add("elev1", Double.class);
    b.add("elev2", Double.class);
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    for( Geometry g : tinGeometries ) {
        Coordinate[] coordinates = g.getCoordinates();

        Object[] values;
        int windingRule = GeometryUtilities.getTriangleWindingRule(coordinates[0], coordinates[1], coordinates[2]);
        if (windingRule > 0) {
            // need to reverse the triangle
            values = new Object[]{g, coordinates[0].z, coordinates[2].z, coordinates[1].z};
        } else {
            values = new Object[]{g, coordinates[0].z, coordinates[1].z, coordinates[2].z};
        }

        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(null);
        newCollection.add(feature);
    }
    return newCollection;
}
 
Example 13
Source File: TestLineSmootherJaitools.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void testVectorReader() throws Exception {

        SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
        b.setName("test");
        b.setCRS(DefaultGeographicCRS.WGS84);
        b.add("the_geom", LineString.class);
        b.add("id", Integer.class);

        DefaultFeatureCollection newCollection = new DefaultFeatureCollection();
        SimpleFeatureType type = b.buildFeatureType();

        Geometry line = new WKTReader().read("LINESTRING (0 0, 1 1, 2 0)");//2 2, 3 3, 4 4, 5 3, 6 2, 7 1, 8 0)");
        SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
        Object[] values = new Object[]{line, 0};
        builder.addAll(values);
        SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0");
        newCollection.add(feature);

        OmsLineSmootherJaitools smoother = new OmsLineSmootherJaitools();
        smoother.inVector = newCollection;
        smoother.pAlpha = 1;
        smoother.process();
        SimpleFeatureCollection outFeatures = smoother.outVector;

        List<Geometry> geomList = FeatureUtilities.featureCollectionToGeometriesList(outFeatures, false, null);
        Geometry geometry = geomList.get(0);
        
        int newLength = geometry.getCoordinates().length;

        Geometry densifiedline = new WKTReader()
                .read("LINESTRING (0 0, 0.0342935528120713 0.0342935528120713, 0.1262002743484225 0.1262002743484225, 0.2592592592592592 0.2592592592592592, 0.4170096021947873 0.4170096021947873, 0.5829903978052127 0.5829903978052127, 0.7407407407407407 0.7407407407407407, 0.8737997256515775 0.8737997256515775, 0.9657064471879286 0.9657064471879286, 1 1, 1.0342935528120714 0.9657064471879288, 1.1262002743484225 0.8737997256515775, 1.2592592592592593 0.7407407407407408, 1.4170096021947873 0.5829903978052127, 1.5829903978052127 0.4170096021947874, 1.7407407407407407 0.2592592592592593, 1.8737997256515775 0.1262002743484225, 1.9657064471879289 0.0342935528120714, 2 0)");
        int expectedLength = densifiedline.getCoordinates().length;

        assertEquals(expectedLength, newLength);

    }
 
Example 14
Source File: FeatureUtilities.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public static SimpleFeature toDummyFeature( Geometry geom, CoordinateReferenceSystem crs ) {
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("dummy");
    if (crs != null)
        b.setCRS(crs);
    b.add("the_geom", geom.getClass());
    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    Object[] values = new Object[]{geom};
    builder.addAll(values);
    SimpleFeature feature = builder.buildFeature(null);
    return feature;
}
 
Example 15
Source File: OmsZonalStats.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    checkNull(inVector, inRaster);

    boolean hasUserTotalMean = false;
    if (pTotalMean != null) {
        hasUserTotalMean = true;
        tm_usertm_tactivecells[1] = pTotalMean;
    }

    ReferencedEnvelope bounds = inVector.getBounds();
    CoordinateReferenceSystem crs = bounds.getCoordinateReferenceSystem();

    SimpleFeatureBuilder featureBuilder = createFeatureBuilder(crs, hasUserTotalMean);

    outVector = new DefaultFeatureCollection();
    List<Geometry> geometriesList = FeatureUtilities.featureCollectionToGeometriesList(inVector, true, null);

    // pm.message("" + readEnvelope);
    GridGeometry2D gridGeometry = inRaster.getGridGeometry();
    RandomIter readIter = CoverageUtilities.getRandomIterator(inRaster);
    pm.beginTask("Processing polygons...", geometriesList.size());
    for( Geometry geometry : geometriesList ) {
        double[] polygonStats = polygonStats(geometry, gridGeometry, readIter, hasUserTotalMean, tm_usertm_tactivecells,
                pPercentageThres, pm);
        if (polygonStats == null) {
            continue;
        }

        Object[] values;
        if (!hasUserTotalMean) {
            values = new Object[]{geometry, //
                    polygonStats[0], //
                    polygonStats[1], //
                    polygonStats[2], //
                    polygonStats[3], //
                    polygonStats[4], //
                    polygonStats[5], //
                    (int) polygonStats[6], //
                    (int) polygonStats[7] //
            };
        } else {
            values = new Object[]{geometry, //
                    polygonStats[0], //
                    polygonStats[1], //
                    polygonStats[2], //
                    polygonStats[3], //
                    polygonStats[4], //
                    polygonStats[5], //
                    polygonStats[6], //
                    (int) polygonStats[7], //
                    (int) polygonStats[8] //
            };
        }

        featureBuilder.addAll(values);
        SimpleFeature feature = featureBuilder.buildFeature(null);
        ((DefaultFeatureCollection) outVector).add(feature);
        pm.worked(1);
    }
    pm.done();

    if (!hasUserTotalMean) {
        tm_usertm_tactivecells[0] = tm_usertm_tactivecells[0] / tm_usertm_tactivecells[2];
        pm.message("Total mean: " + tm_usertm_tactivecells[0]);
    }
}
 
Example 16
Source File: DxfLINE.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
public static DxfGroup readEntity( RandomAccessFile raf,
        DefaultFeatureCollection entities ) throws IOException {

    double x1 = Double.NaN, y1 = Double.NaN, z1 = Double.NaN;
    double x2 = Double.NaN, y2 = Double.NaN, z2 = Double.NaN;
    DxfGroup group;

    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(DxfFile.DXF_LINESCHEMA);
    String layer = "";
    String ltype = "";
    Double elevation = new Double(0.0);
    Double thickness = new Double(0.0);
    Integer color = new Integer(256);
    String text = "";
    Double text_height = new Double(0.0);
    String text_style = "";

    while( null != (group = DxfGroup.readGroup(raf)) && group.getCode() != 0 ) {
        if (group.getCode() == 8)
            layer = group.getValue();
        else if (group.getCode() == 6)
            ltype = group.getValue();
        else if (group.getCode() == 39)
            thickness = new Double(group.getDoubleValue());
        else if (group.getCode() == 62)
            color = new Integer(group.getIntValue());
        else if (group.getCode() == 10)
            x1 = group.getDoubleValue();
        else if (group.getCode() == 20)
            y1 = group.getDoubleValue();
        else if (group.getCode() == 30)
            z1 = group.getDoubleValue();
        else if (group.getCode() == 11)
            x2 = group.getDoubleValue();
        else if (group.getCode() == 21)
            y2 = group.getDoubleValue();
        else if (group.getCode() == 31)
            z2 = group.getDoubleValue();
        else {
        }
    }
    if (!Double.isNaN(x1) && !Double.isNaN(y1) && !Double.isNaN(x2) && !Double.isNaN(y2)) {
        Object[] values = new Object[]{
                gF.createLineString(new Coordinate[]{new Coordinate(x1, y1, z1),
                        new Coordinate(x2, y2, z2)}), layer, ltype, elevation, thickness,
                color, text, text_height, text_style};
        builder.addAll(values);
        StringBuilder featureId = new StringBuilder();
        featureId.append(DxfFile.DXF_LINESCHEMA.getTypeName());
        featureId.append(".");
        featureId.append(DxfFile.getNextFid());
        SimpleFeature feature = builder.buildFeature(featureId.toString());
        entities.add(feature);
    }
    return group;
}
 
Example 17
Source File: InLineFeatureModel.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Update CRS.
 *
 * @param selectedValue the selected value
 */
public void updateCRS(ValueComboBoxData selectedValue) {
    if (selectedValue != null) {
        String crsCode = selectedValue.getKey();

        CoordinateReferenceSystem newCRS = CoordManager.getInstance().getCRS(crsCode);

        SimpleFeatureType newFeatureType =
                SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), newCRS);

        String typeName = userLayer.getInlineFeatureType().getTypeName();
        try {
            SimpleFeatureSource featureSource =
                    userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);

            SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);

            ArrayList<SimpleFeature> featureList = new ArrayList<>();

            SimpleFeatureIterator it = featureSource.getFeatures().features();
            try {
                while (it.hasNext()) {
                    SimpleFeature sf = it.next();
                    List<Object> attributeValueList = sf.getAttributes();
                    sfb.addAll(attributeValueList);
                    featureList.add(sfb.buildFeature(null));
                }
            } finally {
                it.close();
            }

            SimpleFeatureCollection collection =
                    new ListFeatureCollection(newFeatureType, featureList);

            featureCollection = collection;
            cachedFeature = null;
            lastRow = -1;
            DataStore dataStore = DataUtilities.dataStore(collection);
            userLayer.setInlineFeatureDatastore(dataStore);
            userLayer.setInlineFeatureType(newFeatureType);

        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }

        this.fireTableStructureChanged();
        this.fireTableDataChanged();

        if (parentObj != null) {
            parentObj.inlineFeatureUpdated();
        }
    }
}
 
Example 18
Source File: ALasDataManager.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Retrieve all the envelope features that intersect the geometry.
 *
 * <p>an elev attribute is added with the max elev contained in the envelope.
 *
 * @param checkGeom the {@link org.locationtech.jts.geom.Geometry} to use to check.
 * @param doOnlyEnvelope check for the geom envelope instead of a intersection with it.
 * @param minMaxZI an array to be filled with the [minz,maxz, minintensity, maxintensity] to be used as style.
 * @param doPoints if <code>true</code>, create points instead of polygons.
 * @return the features of the envelopes contained in the supplied geometry.
 * @throws Exception
 */
public synchronized SimpleFeatureCollection getEnvelopeFeaturesInGeometry( Geometry checkGeom, boolean doOnlyEnvelope,
        double[] minMaxZI, boolean doPoints ) throws Exception {
    List<Geometry> envelopesInGeometry = getEnvelopesInGeometry(checkGeom, doOnlyEnvelope, null);

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("overview");
    b.setCRS(crs);
    if (!doPoints) {
        b.add("the_geom", Polygon.class);
    } else {
        b.add("the_geom", Point.class);
    }
    b.add("elev", Double.class);
    b.add("intensity", Double.class);

    SimpleFeatureType type = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type);
    double minZ = Double.POSITIVE_INFINITY;
    double maxZ = Double.NEGATIVE_INFINITY;
    double minI = Double.POSITIVE_INFINITY;
    double maxI = Double.NEGATIVE_INFINITY;

    DefaultFeatureCollection newFeatures = new DefaultFeatureCollection();
    for( int i = 0; i < envelopesInGeometry.size(); i++ ) {
        Geometry geom = envelopesInGeometry.get(i);
        if (doPoints) {
            Envelope envelope = geom.getEnvelopeInternal();
            Coordinate centre = envelope.centre();
            geom = gf.createPoint(centre);
        }

        double elev = -9999.0;
        double intens = -9999.0;
        Object userData = geom.getUserData();
        if (userData instanceof double[]) {
            double[] data = (double[]) userData;
            elev = data[0];
            intens = data[1];
        }

        if (minMaxZI != null) {
            minZ = Math.min(minZ, elev);
            maxZ = Math.max(maxZ, elev);
            minI = Math.min(minI, intens);
            maxI = Math.max(maxI, intens);
        }

        Object[] objs = new Object[]{geom, elev, intens};
        builder.addAll(objs);
        SimpleFeature feature = builder.buildFeature(null);
        newFeatures.add(feature);
    }

    if (minMaxZI != null) {
        minMaxZI[0] = minZ;
        minMaxZI[1] = maxZ;
        minMaxZI[2] = minI;
        minMaxZI[3] = maxI;
    }
    return newFeatures;
}
 
Example 19
Source File: InLineFeatureModel.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/** Adds the new column. */
public void addNewColumn() {
    if (featureCollection != null) {
        String attributeName = getUniqueAttributeName();

        columnList.add(attributeName);

        // Populate field names
        SimpleFeatureTypeBuilder featureTypeBuilder = new SimpleFeatureTypeBuilder();
        featureTypeBuilder.init(featureCollection.getSchema());
        featureTypeBuilder.add(attributeName, String.class);

        SimpleFeatureType newFeatureType = featureTypeBuilder.buildFeatureType();

        String typeName = userLayer.getInlineFeatureType().getTypeName();
        try {
            SimpleFeatureSource featureSource =
                    userLayer.getInlineFeatureDatastore().getFeatureSource(typeName);

            SimpleFeatureBuilder sfb = new SimpleFeatureBuilder(newFeatureType);

            ArrayList<SimpleFeature> featureList = new ArrayList<>();

            SimpleFeatureIterator it = featureSource.getFeatures().features();
            try {
                while (it.hasNext()) {
                    SimpleFeature sf = it.next();
                    sfb.addAll(sf.getAttributes());
                    sfb.add(new String(""));
                    featureList.add(sfb.buildFeature(null));
                }
            } finally {
                it.close();
            }

            SimpleFeatureCollection collection =
                    new ListFeatureCollection(newFeatureType, featureList);

            featureCollection = collection;
            cachedFeature = null;
            lastRow = -1;
            DataStore dataStore = DataUtilities.dataStore(collection);
            userLayer.setInlineFeatureDatastore(dataStore);
            userLayer.setInlineFeatureType(newFeatureType);

        } catch (IOException e) {
            ConsoleManager.getInstance().exception(this, e);
        }

        this.fireTableStructureChanged();
        this.fireTableDataChanged();

        if (parentObj != null) {
            parentObj.inlineFeatureUpdated();
        }
    }
}
 
Example 20
Source File: OmsGeopaparazzi3Converter.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
private void simpleNotesToShapefile( Connection connection, File outputFolderFile, IHMProgressMonitor pm ) throws Exception {
    File outputShapeFile = new File(outputFolderFile, "simplenotes.shp");

    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName("gpsimplenotes"); //$NON-NLS-1$
    b.setCRS(crs);
    b.add("the_geom", Point.class); //$NON-NLS-1$
    b.add("DESCR", String.class);
    b.add("TIMESTAMP", String.class);
    b.add("ALTIM", Double.class);

    SimpleFeatureType featureType = b.buildFeatureType();
    SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType);

    pm.beginTask("Import simple notes...", -1);
    SimpleFeatureCollection newCollection = new DefaultFeatureCollection();

    try (Statement statement = connection.createStatement()) {
        statement.setQueryTimeout(30); // set timeout to 30 sec.

        ResultSet rs = statement.executeQuery("select lat, lon, altim, ts, text, form from notes");
        while( rs.next() ) {
            String form = rs.getString("form");
            if (form != null && form.trim().length() != 0) {
                continue;
            }

            double lat = rs.getDouble("lat");
            double lon = rs.getDouble("lon");
            double altim = rs.getDouble("altim");
            String dateTimeString = rs.getString("ts");
            String text = rs.getString("text");

            if (lat == 0 || lon == 0) {
                continue;
            }

            // and then create the features
            Coordinate c = new Coordinate(lon, lat);
            Point point = gf.createPoint(c);

            Object[] values = new Object[]{point, text, dateTimeString, altim};
            builder.addAll(values);
            SimpleFeature feature = builder.buildFeature(null);
            ((DefaultFeatureCollection) newCollection).add(feature);
        }

    } finally {
        pm.done();
    }
    dumpVector(newCollection, outputShapeFile.getAbsolutePath());
}