Java Code Examples for org.opengis.feature.type.GeometryDescriptor

The following examples show how to use org.opengis.feature.type.GeometryDescriptor. These examples are extracted from open source projects. 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 Project: sldeditor   Author: robward-scisys   File: DataSourceImpl.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<String> getAllAttributes(boolean includeGeometry) {
    List<String> attributeNameList = new ArrayList<>();

    Collection<PropertyDescriptor> descriptorList = getPropertyDescriptorList();

    if (descriptorList != null) {
        for (PropertyDescriptor property : descriptorList) {
            boolean isGeometry = (property instanceof GeometryDescriptor);
            if ((isGeometry && includeGeometry) || !isGeometry) {
                attributeNameList.add(property.getName().toString());
            }
        }
    }
    return attributeNameList;
}
 
Example #2
Source Project: elasticgeo   Author: ngageoint   File: ElasticGeometryFilterIT.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAlternateGeometry() throws Exception {
    init("active", "geo2");
    SimpleFeatureType schema = featureSource.getSchema();
    GeometryDescriptor gd = schema.getGeometryDescriptor();
    assertNotNull(gd);
    assertEquals("geo2", gd.getLocalName());

    FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory();
    BBOX bbox = ff.bbox("geo2", 6.5, 23.5, 7.5, 24.5, "EPSG:4326");
    SimpleFeatureCollection features = featureSource.getFeatures(bbox);
    assertEquals(1, features.size());
    SimpleFeatureIterator fsi = features.features();
    assertTrue(fsi.hasNext());
    assertEquals(fsi.next().getID(), "active.09");
}
 
Example #3
Source Project: hortonmachine   Author: TheHortonMachine   File: FeatureGeometrySubstitutor.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * @param oldFeatureType the {@link FeatureType} of the existing features.
 * @throws FactoryRegistryException 
 * @throws SchemaException
 */
public FeatureGeometrySubstitutor( SimpleFeatureType oldFeatureType, Class< ? > newGeometryType ) throws Exception {

    List<AttributeDescriptor> oldAttributeDescriptors = oldFeatureType.getAttributeDescriptors();

    // create the feature type
    SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder();
    b.setName(oldFeatureType.getName());
    b.setCRS(oldFeatureType.getCoordinateReferenceSystem());

    if (newGeometryType == null) {
        b.addAll(oldAttributeDescriptors);
    } else {
        for( AttributeDescriptor attributeDescriptor : oldAttributeDescriptors ) {
            if (attributeDescriptor instanceof GeometryDescriptor) {
                b.add("the_geom", newGeometryType);
            } else {
                b.add(attributeDescriptor);
            }
        }
    }
    newFeatureType = b.buildFeatureType();
}
 
Example #4
Source Project: hortonmachine   Author: TheHortonMachine   File: FeatureUtilities.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static LinkedHashMap<String, String> feature2AlphanumericToHashmap( SimpleFeature feature ) {
    LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
    List<AttributeDescriptor> attributeDescriptors = feature.getFeatureType().getAttributeDescriptors();
    int index = 0;
    for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
        if (!(attributeDescriptor instanceof GeometryDescriptor)) {
            String fieldName = attributeDescriptor.getLocalName();
            Object attribute = feature.getAttribute(index);
            if (attribute == null) {
                attribute = "";
            }
            String value = attribute.toString();
            attributes.put(fieldName, value);
        }
        index++;
    }
    return attributes;
}
 
Example #5
Source Project: hortonmachine   Author: TheHortonMachine   File: StyleUtilities.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a default {@link Style} for a featurecollection.
 * 
 * @return the default style.
 */
public static Style createDefaultStyle( SimpleFeatureCollection featureCollection ) {
    GeometryDescriptor geometryDescriptor = featureCollection.getSchema().getGeometryDescriptor();
    Style style = null;
    if (EGeometryType.isPoint(geometryDescriptor)) {
        style = createDefaultPointStyle();
    } else if (EGeometryType.isLine(geometryDescriptor)) {
        style = createDefaultLineStyle();
    } else if (EGeometryType.isPolygon(geometryDescriptor)) {
        style = createDefaultPolygonStyle();
    }
    if (style != null) {
        style.setName(featureCollection.getSchema().getTypeName());
    }
    return style;
}
 
Example #6
Source Project: hortonmachine   Author: TheHortonMachine   File: NwwUtilities.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static LinkedHashMap<String, String> feature2AlphanumericToHashmap( SimpleFeature feature ) {
    LinkedHashMap<String, String> attributes = new LinkedHashMap<>();
    List<AttributeDescriptor> attributeDescriptors = feature.getFeatureType().getAttributeDescriptors();
    int index = 0;
    for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
        if (!(attributeDescriptor instanceof GeometryDescriptor)) {
            String fieldName = attributeDescriptor.getLocalName();
            Object attribute = feature.getAttribute(index);
            if (attribute == null) {
                attribute = "";
            }
            String value = attribute.toString();
            attributes.put(fieldName, value);
        }
        index++;
    }
    return attributes;
}
 
Example #7
Source Project: snap-desktop   Author: senbox-org   File: CorrelativeFieldSelector.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void updatePointDataSource(Product product) {
    if (product != null) {
        final Class pointClass = org.locationtech.jts.geom.Point.class;
        final ProductNodeGroup<VectorDataNode> vectorDataGroup = product.getVectorDataGroup();
        final List<VectorDataNode> vectorDataNodes = new ArrayList<VectorDataNode>();
        for (VectorDataNode vectorDataNode : vectorDataGroup.toArray(new VectorDataNode[vectorDataGroup.getNodeCount()])) {
            final GeometryDescriptor geometryDescriptor = vectorDataNode.getFeatureType().getGeometryDescriptor();
            if (geometryDescriptor != null &&
                    pointClass.isAssignableFrom(geometryDescriptor.getType().getBinding())) {
                vectorDataNodes.add(vectorDataNode);
            }
        }
        final ValueSet valueSet = new ValueSet(vectorDataNodes.toArray());
        pointDataSourceProperty.getDescriptor().setValueSet(valueSet);
    } else {
        pointDataSourceProperty.getDescriptor().setValueSet(null);
        dataFieldProperty.getDescriptor().setValueSet(null);
        try {
            pointDataSourceProperty.setValue(null);
            dataFieldProperty.setValue(null);
        } catch (ValidationException ignore) {
        }
    }
}
 
Example #8
Source Project: sldeditor   Author: robward-scisys   File: SLDEditorBufferedImageLegendGraphicBuilder.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Clones the given schema, changing the geometry attribute to match the given dimensionality.
 *
 * @param schema schema to clone
 * @param dimensionality dimensionality for the geometry 1= points, 2= lines, 3= polygons
 */
private FeatureType cloneWithDimensionality(FeatureType schema, int dimensionality) {
    SimpleFeatureType simpleFt = (SimpleFeatureType) schema;
    SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
    builder.setName(schema.getName());
    builder.setCRS(schema.getCoordinateReferenceSystem());
    for (AttributeDescriptor desc : simpleFt.getAttributeDescriptors()) {
        if (isMixedGeometry(desc)) {
            GeometryDescriptor geomDescriptor = (GeometryDescriptor) desc;
            GeometryType geomType = geomDescriptor.getType();

            Class<?> geometryClass = getGeometryForDimensionality(dimensionality);

            GeometryType gt =
                    new GeometryTypeImpl(
                            geomType.getName(),
                            geometryClass,
                            geomType.getCoordinateReferenceSystem(),
                            geomType.isIdentified(),
                            geomType.isAbstract(),
                            geomType.getRestrictions(),
                            geomType.getSuper(),
                            geomType.getDescription());

            builder.add(
                    new GeometryDescriptorImpl(
                            gt,
                            geomDescriptor.getName(),
                            geomDescriptor.getMinOccurs(),
                            geomDescriptor.getMaxOccurs(),
                            geomDescriptor.isNillable(),
                            geomDescriptor.getDefaultValue()));
        } else {
            builder.add(desc);
        }
    }
    schema = builder.buildFeatureType();
    return schema;
}
 
Example #9
Source Project: sldeditor   Author: robward-scisys   File: SLDEditorBufferedImageLegendGraphicBuilder.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if the given AttributeDescriptor describes a generic Geometry.
 *
 * @param attDesc
 */
private boolean isMixedGeometry(AttributeDescriptor attDesc) {
    if (attDesc instanceof GeometryDescriptor
            && attDesc.getType().getBinding() == Geometry.class) {
        return true;
    }
    return false;
}
 
Example #10
Source Project: sldeditor   Author: robward-scisys   File: DatabaseClient.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks for the presence of a geometry field.
 *
 * @param dataStore the data store
 * @param name the name
 * @return true, if geometry field present
 */
private boolean hasGeometryField(DataStore dataStore, Name name) {
    try {
        SimpleFeatureSource featureSource = dataStore.getFeatureSource(name);
        GeometryDescriptor geometryDescriptor =
                featureSource.getSchema().getGeometryDescriptor();

        return (geometryDescriptor != null);

    } catch (IOException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    return false;
}
 
Example #11
Source Project: sldeditor   Author: robward-scisys   File: DataSourceInfo.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the property descriptor list.
 *
 * @return the property descriptor list
 */
public Collection<PropertyDescriptor> getPropertyDescriptorList() {
    if (schema != null) {
        return schema.getDescriptors();
    } else {
        if (geometryType == GeometryTypeEnum.RASTER) {
            if (rasterPropertyDescriptorList == null) {
                rasterPropertyDescriptorList = new ArrayList<>();

                CoordinateReferenceSystem crs = null;
                boolean isIdentifiable = false;
                boolean isAbstract = false;
                List<Filter> restrictions = null;
                AttributeType superType = null;
                InternationalString description = null;
                GeometryType type =
                        featureTypeFactory.createGeometryType(
                                new NameImpl(RASTER_GEOMETRY_FIELD),
                                GridCoverage2D.class,
                                crs,
                                isIdentifiable,
                                isAbstract,
                                restrictions,
                                superType,
                                description);
                GeometryDescriptor descriptor =
                        featureTypeFactory.createGeometryDescriptor(
                                type, new NameImpl(RASTER_GEOMETRY_FIELD), 0, 1, false, null);

                rasterPropertyDescriptorList.add(descriptor);
            }

            return rasterPropertyDescriptorList;
        }
    }
    return null;
}
 
Example #12
Source Project: sldeditor   Author: robward-scisys   File: InlineFeatureUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Determine geometry type.
 *
 * @param geometryDescriptor the geometry descriptor
 * @param simpleFeatureCollection the simple feature collection
 * @return the geometry type enum
 */
public static GeometryTypeEnum determineGeometryType(
        GeometryDescriptor geometryDescriptor,
        SimpleFeatureCollection simpleFeatureCollection) {

    if (geometryDescriptor == null) {
        return GeometryTypeEnum.UNKNOWN;
    }

    if (simpleFeatureCollection == null) {
        return GeometryTypeEnum.UNKNOWN;
    }

    Class<?> bindingType = geometryDescriptor.getType().getBinding();

    if (bindingType == Geometry.class) {
        Name geometryName = geometryDescriptor.getName();
        SimpleFeatureIterator iterator = simpleFeatureCollection.features();

        List<GeometryTypeEnum> geometryFeatures = new ArrayList<>();

        while (iterator.hasNext()) {
            SimpleFeature feature = iterator.next();

            Object value = feature.getAttribute(geometryName);

            if (value != null) {
                GeometryTypeEnum geometryType =
                        GeometryTypeMapping.getGeometryType(value.getClass());

                if (!geometryFeatures.contains(geometryType)) {
                    geometryFeatures.add(geometryType);
                }
            }
        }
        return (combineGeometryType(geometryFeatures));
    } else {
        return GeometryTypeMapping.getGeometryType(bindingType);
    }
}
 
Example #13
Source Project: sldeditor   Author: robward-scisys   File: InlineFeatureUtilsTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.ui.detail.config.inlinefeature.InlineFeatureUtils#determineGeometryType(org.opengis.feature.type.GeometryDescriptor,
 * org.geotools.data.simple.SimpleFeatureCollection)}.
 */
@Test
public void testDetermineGeometryType() {
    // Test 1
    SLDData sldData = new SLDData(null, testInline1a);
    StyledLayerDescriptor sld = SLDUtils.createSLDFromString(sldData);

    UserLayer userLayer1 = (UserLayer) sld.layers().get(0);

    GeometryDescriptor geometryDescriptor =
            userLayer1.getInlineFeatureType().getGeometryDescriptor();
    String typeName = userLayer1.getInlineFeatureType().getTypeName();
    SimpleFeatureCollection simpleFeatureCollection = null;
    try {
        simpleFeatureCollection =
                userLayer1.getInlineFeatureDatastore().getFeatureSource(typeName).getFeatures();
    } catch (IOException e) {
        e.printStackTrace();
    }

    assertEquals(
            GeometryTypeEnum.UNKNOWN, InlineFeatureUtils.determineGeometryType(null, null));
    assertEquals(
            GeometryTypeEnum.UNKNOWN,
            InlineFeatureUtils.determineGeometryType(geometryDescriptor, null));

    assertEquals(
            GeometryTypeEnum.POLYGON,
            InlineFeatureUtils.determineGeometryType(
                    geometryDescriptor, simpleFeatureCollection));
}
 
Example #14
Source Project: gama   Author: gama-platform   File: SLDs.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static final boolean isPolygon(final SimpleFeatureType featureType) {
	if (featureType == null) { return false; }
	final GeometryDescriptor geometryType = featureType.getGeometryDescriptor();
	if (geometryType == null) { return false; }
	final Class<?> type = geometryType.getType().getBinding();
	return Polygon.class.isAssignableFrom(type) || MultiPolygon.class.isAssignableFrom(type);
}
 
Example #15
Source Project: gama   Author: gama-platform   File: SLDs.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static final boolean isLine(final SimpleFeatureType featureType) {
	if (featureType == null) { return false; }
	final GeometryDescriptor geometryType = featureType.getGeometryDescriptor();
	if (geometryType == null) { return false; }
	final Class<?> type = geometryType.getType().getBinding();
	return LineString.class.isAssignableFrom(type) || MultiLineString.class.isAssignableFrom(type);
}
 
Example #16
Source Project: gama   Author: gama-platform   File: SLDs.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static final boolean isPoint(final SimpleFeatureType featureType) {
	if (featureType == null) { return false; }
	final GeometryDescriptor geometryType = featureType.getGeometryDescriptor();
	if (geometryType == null) { return false; }
	final Class<?> type = geometryType.getType().getBinding();
	return Point.class.isAssignableFrom(type) || MultiPoint.class.isAssignableFrom(type);
}
 
Example #17
Source Project: elasticgeo   Author: ngageoint   File: ElasticFeatureFilterIT.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testSchema() throws Exception {
    init();
    SimpleFeatureType schema = featureSource.getSchema();
    assertNotNull(schema);

    assertNotNull(schema.getGeometryDescriptor());
    assertTrue(schema.getDescriptor("geo") instanceof GeometryDescriptor);
    assertTrue(schema.getDescriptor("geo2") instanceof GeometryDescriptor);
    assertTrue(schema.getDescriptor("geo3") instanceof GeometryDescriptor);
    assertTrue(schema.getDescriptor("geo5") instanceof GeometryDescriptor);
}
 
Example #18
Source Project: hortonmachine   Author: TheHortonMachine   File: FeatureUtilities.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static String[] featureCollectionFieldNames( SimpleFeatureCollection feature ) {
    List<String> names = new ArrayList<>();
    List<AttributeDescriptor> attributeDescriptors = feature.getSchema().getAttributeDescriptors();
    for( AttributeDescriptor attributeDescriptor : attributeDescriptors ) {
        if (!(attributeDescriptor instanceof GeometryDescriptor)) {
            String fieldName = attributeDescriptor.getLocalName();
            names.add(fieldName);
        }
    }
    return names.toArray(new String[0]);
}
 
Example #19
Source Project: hortonmachine   Author: TheHortonMachine   File: NwwUtilities.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the geometry type from a featurecollection.
 * 
 * @param featureCollection
 *            the collection.
 * @return the {@link GEOMTYPE}.
 */
public static GEOMTYPE getGeometryType( SimpleFeatureCollection featureCollection ) {
    GeometryDescriptor geometryDescriptor = featureCollection.getSchema().getGeometryDescriptor();
    if (EGeometryType.isPolygon(geometryDescriptor)) {
        return GEOMTYPE.POLYGON;
    } else if (EGeometryType.isLine(geometryDescriptor)) {
        return GEOMTYPE.LINE;
    } else if (EGeometryType.isPoint(geometryDescriptor)) {
        return GEOMTYPE.POINT;
    } else {
        return GEOMTYPE.UNKNOWN;
    }
}
 
Example #20
private void setLayerType(VectorLayerInfo info, GeometryDescriptor geoType) {
	if (geoType.getType().getBinding() == Point.class) {
		info.setLayerType(LayerType.POINT);
	} else if (geoType.getType().getBinding() == MultiPoint.class) {
		info.setLayerType(LayerType.MULTIPOINT);
	} else if (geoType.getType().getBinding() == LineString.class) {
		info.setLayerType(LayerType.LINESTRING);
	} else if (geoType.getType().getBinding() == MultiLineString.class) {
		info.setLayerType(LayerType.MULTILINESTRING);
	} else if (geoType.getType().getBinding() == Polygon.class) {
		info.setLayerType(LayerType.POLYGON);
	} else if (geoType.getType().getBinding() == MultiPolygon.class) {
		info.setLayerType(LayerType.MULTIPOLYGON);
	}
}
 
Example #21
Source Project: hortonmachine   Author: TheHortonMachine   File: OmsScanLineRasterizer.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void process() throws Exception {
    checkNull(inVector);
    if (pValue == null && fCat == null) {
        throw new ModelsIllegalargumentException("One of pValue or the fCat have to be defined.", this, pm);
    }
    if (pNorth == null || pSouth == null || pWest == null || pEast == null || pRows == null || pCols == null) {
        if (inRaster == null) {
            throw new ModelsIllegalargumentException(
                    "It is necessary to supply all the information about the processing region. Did you set the boundaries and rows/cols?",
                    this, pm);
        }
    }

    if (inRaster != null) {
        RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster);
        pNorth = regionMap.getNorth();
        pSouth = regionMap.getSouth();
        pWest = regionMap.getWest();
        pEast = regionMap.getEast();
        pRows = regionMap.getRows();
        pCols = regionMap.getCols();

        inIter = CoverageUtilities.getRandomIterator(inRaster);
    }

    SimpleFeatureType schema = inVector.getSchema();
    CoordinateReferenceSystem crs = schema.getCoordinateReferenceSystem();
    GridGeometry2D pGrid;
    if (inRaster != null) {
        pGrid = inRaster.getGridGeometry();
    } else {
        pGrid = gridGeometryFromRegionValues(pNorth, pSouth, pEast, pWest, pCols, pRows, crs);
    }
    if (outWR == null) {
        paramsMap = gridGeometry2RegionParamsMap(pGrid);
        height = paramsMap.getRows();
        width = paramsMap.getCols();
        xRes = paramsMap.getXres();

        outWR = CoverageUtilities.createWritableRaster(width, height, null, null, doubleNovalue);
    }

    GeometryDescriptor geometryDescriptor = schema.getGeometryDescriptor();
    if (EGeometryType.isPoint(geometryDescriptor)) {
        throw new ModelsRuntimeException("Not implemented yet for points", this.getClass().getSimpleName());
    } else if (EGeometryType.isLine(geometryDescriptor)) {
        throw new ModelsRuntimeException("Not implemented yet for lines", this.getClass().getSimpleName());
    } else if (EGeometryType.isPolygon(geometryDescriptor)) {

        if (pUsePointInPolygon) {
            if (inRaster == null) {
                throw new ModelsIllegalargumentException("The point in polygon mode needs an input raster to work on.", this);
            }
            pm.beginTask("Prepare input data...", IHMProgressMonitor.UNKNOWN);
            List<Geometry> allGeoms = FeatureUtilities.featureCollectionToGeometriesList(inVector, false, null);
            Geometry allGeomsUnion = CascadedPolygonUnion.union(allGeoms);
            PreparedGeometry preparedGeometry = PreparedGeometryFactory.prepare(allGeomsUnion);
            pm.done();

            double value = pValue;
            pm.beginTask("Rasterizing...", height);
            WritableRandomIter wIter = CoverageUtilities.getWritableRandomIterator(outWR);
            for( int row = 0; row < height; row++ ) {
                for( int col = 0; col < width; col++ ) {
                    Coordinate coord = CoverageUtilities.coordinateFromColRow(col, row, pGrid);
                    if (preparedGeometry.intersects(gf.createPoint(coord))) {
                        wIter.setSample(col, col, 0, value);
                    }
                }
                pm.worked(1);
            }
            pm.done();
            wIter.done();
        } else {
            rasterizepolygon(pGrid);
        }
    } else {
        throw new ModelsIllegalargumentException("Couldn't recognize the geometry type of the file.",
                this.getClass().getSimpleName(), pm);
    }

    outRaster = CoverageUtilities.buildCoverage("rasterized", outWR, paramsMap,
            inVector.getSchema().getCoordinateReferenceSystem());

}
 
Example #22
Source Project: hortonmachine   Author: TheHortonMachine   File: OmsMapsViewer.java    License: GNU General Public License v3.0 4 votes vote down vote up
private void addFeatureCollections( MapContent map ) throws Exception {
    if (inVectors == null) {
        return;
    }
    for( String path : inVectors ) {
        SimpleFeatureCollection fc = OmsVectorReader.readVector(path);
        GeometryDescriptor geometryDescriptor = fc.getSchema().getGeometryDescriptor();
        EGeometryType type = EGeometryType.forGeometryDescriptor(geometryDescriptor);

        File file = new File(path);
        Style style = SldUtilities.getStyleFromFile(file);

        switch( type ) {
        case MULTIPOLYGON:
        case POLYGON:
            if (style == null) {
                Stroke polygonStroke = sf.createStroke(ff.literal(Color.BLUE), ff.literal(2));
                Fill polygonFill = sf.createFill(ff.literal(Color.BLUE), ff.literal(0.0));

                Rule polygonRule = sf.createRule();
                PolygonSymbolizer polygonSymbolizer = sf.createPolygonSymbolizer(polygonStroke, polygonFill, null);
                polygonRule.symbolizers().add(polygonSymbolizer);

                FeatureTypeStyle polygonFeatureTypeStyle = sf.createFeatureTypeStyle();
                polygonFeatureTypeStyle.rules().add(polygonRule);

                style = sf.createStyle();
                style.featureTypeStyles().add(polygonFeatureTypeStyle);
                style.setName("polygons");
            }
            break;
        case MULTIPOINT:
        case POINT:
            if (style == null) {
                Mark circleMark = sf.getCircleMark();
                Fill fill = sf.createFill(ff.literal(Color.RED));
                circleMark.setFill(fill);
                // circleMark.setStroke(null);

                Graphic gr = sf.createDefaultGraphic();
                gr.graphicalSymbols().clear();
                gr.graphicalSymbols().add(circleMark);
                Expression size = ff.literal(6);
                gr.setSize(size);

                Rule pointRule = sf.createRule();
                PointSymbolizer pointSymbolizer = sf.createPointSymbolizer(gr, null);
                pointRule.symbolizers().add(pointSymbolizer);

                FeatureTypeStyle pointsFeatureTypeStyle = sf.createFeatureTypeStyle();
                pointsFeatureTypeStyle.rules().add(pointRule);

                style = sf.createStyle();
                style.featureTypeStyles().add(pointsFeatureTypeStyle);
                style.setName("points");
            }
            break;
        case MULTILINESTRING:
        case LINESTRING:
            if (style == null) {
                Stroke lineStroke = sf.createStroke(ff.literal(Color.RED), ff.literal(2));

                Rule lineRule = sf.createRule();
                LineSymbolizer lineSymbolizer = sf.createLineSymbolizer(lineStroke, null);
                lineRule.symbolizers().add(lineSymbolizer);

                FeatureTypeStyle lineFeatureTypeStyle = sf.createFeatureTypeStyle();
                lineFeatureTypeStyle.rules().add(lineRule);

                style = sf.createStyle();
                style.featureTypeStyles().add(lineFeatureTypeStyle);
                style.setName("lines");
            }
            break;

        default:
            break;
        }

        FeatureLayer layer = new FeatureLayer(fc, style);
        map.addLayer(layer);

    }

}
 
Example #23
Source Project: snap-desktop   Author: senbox-org   File: VectorDataNodeImporter.java    License: GNU General Public License v3.0 4 votes vote down vote up
private void importGeometry(final SnapApp snapApp, final File file) {
    final Product product = snapApp.getSelectedProduct(AUTO);
    if (product == null) {
        return;
    }

    final GeoCoding geoCoding = product.getSceneGeoCoding();
    if (geoCoding == null || !geoCoding.canGetPixelPos()) {
        Dialogs.showError(dialogTitle, "Failed to import vector data.\n"
                                       +
                                       "Current geo-coding cannot convert from geographic to pixel coordinates."); /* I18N */
        return;
    }

    VectorDataNode vectorDataNode;
    try {
        vectorDataNode = readGeometry(snapApp, file, product);
        if (vectorDataNode == null) {
            return;
        }
    } catch (Exception e) {
        Dialogs.showError(dialogTitle, "Failed to import vector data.\n" + "An I/O Error occurred:\n"
                                       + e.getMessage()); /* I18N */
        Debug.trace(e);
        return;
    }

    if (vectorDataNode.getFeatureCollection().isEmpty()) {
        Dialogs.showError(dialogTitle, "The vector data was loaded successfully,\n"
                                       + "but no part is located within the scene boundaries."); /* I18N */
        return;
    }

    boolean individualShapes = false;
    String attributeName = null;
    GeometryDescriptor geometryDescriptor = vectorDataNode.getFeatureType().getGeometryDescriptor();
    int featureCount = vectorDataNode.getFeatureCollection().size();
    if (featureCount > 1
            && geometryDescriptor != null
            && Polygonal.class.isAssignableFrom(geometryDescriptor.getType().getBinding())) {

        String text = "<html>" +
                "The vector data set contains <b>" +
                featureCount + "</b> polygonal shapes.<br>" +
                "Shall they be imported separately?<br>" +
                "<br>" +
                "If you select <b>Yes</b>, the polygons can be used as individual masks<br>" +
                "and they will be displayed on individual layers.</i>";
        SeparateGeometriesDialog dialog = new SeparateGeometriesDialog(snapApp.getMainFrame(), vectorDataNode, helpId,
                text);

        int response = dialog.show();
        if (response == ModalDialog.ID_CANCEL) {
            return;
        }

        individualShapes = response == ModalDialog.ID_YES;
        attributeName = dialog.getSelectedAttributeName();
    }

    VectorDataNode[] vectorDataNodes = VectorDataNodeIO.getVectorDataNodes(vectorDataNode, individualShapes, attributeName);
    for (VectorDataNode vectorDataNode1 : vectorDataNodes) {
        product.getVectorDataGroup().add(vectorDataNode1);
    }

    setLayersVisible(vectorDataNodes);
}