org.geotools.feature.FeatureCollection Java Examples
The following examples show how to use
org.geotools.feature.FeatureCollection.
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: GeoToolsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
/** * {@inheritDoc} * */ @Transactional(readOnly = true) public Iterator<?> getElements(Filter filter, int offset, int maxResultSize) throws LayerException { FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource(); try { if (source instanceof FeatureStore<?, ?>) { SimpleFeatureStore store = (SimpleFeatureStore) source; transactionSynchronization.synchTransaction(store); } Query query = new Query(); query.setFilter(filter); query.setMaxFeatures(maxResultSize > 0 ? maxResultSize : Integer.MAX_VALUE); query.setStartIndex(offset); FeatureCollection<SimpleFeatureType, SimpleFeature> fc = source.getFeatures(query); FeatureIterator<SimpleFeature> it = fc.features(); transactionSynchronization.addIterator(it); return new JavaIterator(it); } catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM); } }
Example #2
Source File: ImportTrackActionTest.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Test public void testReadTrack() throws Exception { CrsGeoCoding geoCoding = new CrsGeoCoding(DefaultGeographicCRS.WGS84, new Rectangle(360, 180), new AffineTransform()); InputStreamReader reader = new InputStreamReader(getClass().getResourceAsStream("TrackData.csv")); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = ImportTrackAction.readTrack(reader, geoCoding); assertNotNull(featureCollection); assertEquals(23, featureCollection.size()); // test ordering SimpleFeature[] simpleFeatures = featureCollection.toArray(new SimpleFeature[0]); assertEquals(23, simpleFeatures.length); assertEquals("ID00000000", simpleFeatures[0].getID()); assertEquals("ID00000011", simpleFeatures[11].getID()); assertEquals("ID00000022", simpleFeatures[22].getID()); }
Example #3
Source File: FeatureFigureEditorApp.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override protected void loadFigureCollection(File file, FigureCollection figureCollection) throws IOException { FeatureSource<SimpleFeatureType, SimpleFeature> featureFeatureSource; FeatureCollection<SimpleFeatureType, SimpleFeature> featureTypeSimpleFeatureFeatureCollection; featureFeatureSource = getFeatureSource(file); featureTypeSimpleFeatureFeatureCollection = featureFeatureSource.getFeatures(); try(FeatureIterator<SimpleFeature> featureIterator = featureTypeSimpleFeatureFeatureCollection.features();) { while (featureIterator.hasNext()) { SimpleFeature simpleFeature = featureIterator.next(); DefaultFigureStyle figureStyle = createDefaultFigureStyle(); Object o = simpleFeature.getDefaultGeometry(); if (o instanceof Point) { figureCollection.addFigure(new SimpleFeaturePointFigure(simpleFeature, sceneTransformProvider, figureStyle)); } else { figureCollection.addFigure(new SimpleFeatureShapeFigure(simpleFeature, sceneTransformProvider, figureStyle)); } } } }
Example #4
Source File: ShpConnector.java From TripleGeo with GNU General Public License v3.0 | 6 votes |
/** * Loads the shape file from the configuration path and returns the * feature collection associated according to the configuration. * * @param shapePath with the path to the shapefile. * @param featureString with the featureString to filter. * * @return FeatureCollection with the collection of features filtered. */ private FeatureCollection getShapeFileFeatureCollection(String shapePath, String featureString) throws IOException { File file = new File(shapePath); // Create the map with the file URL to be passed to DataStore. Map map = new HashMap(); try { map.put("url", file.toURL()); } catch (MalformedURLException ex) { Logger.getLogger(ShpConnector.class.getName()).log(Level.SEVERE, null, ex); } if (map.size() > 0) { DataStore dataStore = DataStoreFinder.getDataStore(map); FeatureSource featureSource = dataStore.getFeatureSource(featureString); return featureSource.getFeatures(); } return null; }
Example #5
Source File: GeoToolsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 6 votes |
@Override public Envelope getBounds(Filter filter) throws LayerException { FeatureSource<SimpleFeatureType, SimpleFeature> source = getFeatureSource(); if (source instanceof FeatureStore<?, ?>) { SimpleFeatureStore store = (SimpleFeatureStore) source; transactionSynchronization.synchTransaction(store); } try { FeatureCollection<SimpleFeatureType, SimpleFeature> fc; if (null == filter) { fc = source.getFeatures(); } else { fc = source.getFeatures(filter); } FeatureIterator<SimpleFeature> it = fc.features(); transactionSynchronization.addIterator(it); return fc.getBounds(); } catch (Throwable t) { // NOSONAR avoid errors (like NPE) as well throw new LayerException(t, ExceptionCode.UNEXPECTED_PROBLEM); } }
Example #6
Source File: geoUtils.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
public static String getFileLayerAction(String layerUrl) throws JSONException, IOException, EMFUserError { IFeaturesProviderFileDAO featuresProvider = DAOFactory.getFeaturesProviderFileDAO(); FeatureCollection outputFeatureCollection = featuresProvider.getAllFeatures(layerUrl); FeatureIterator it = outputFeatureCollection.features(); List<SimpleFeature> list = new ArrayList<SimpleFeature>(); while (it.hasNext()) { SimpleFeature f = (SimpleFeature) it.next(); list.add(f); } FeatureCollection<SimpleFeatureType, SimpleFeature> filteredOutputFeatureCollection = DataUtilities.collection(list); Monitor.start("GetTargetLayerAction.flushResponse"); FeatureJSON featureJSON = new FeatureJSON(); String responseFeature = featureJSON.toString(filteredOutputFeatureCollection); return responseFeature; }
Example #7
Source File: FeaturesProviderDAOWFSImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
@Override public FeatureCollection getAllFeatures(String wfsUrl) { FeatureCollection featureCollection = null; logger.debug("IN"); try { featureCollection = getFeatures(wfsUrl); } catch (Throwable t) { throw new SpagoBIRuntimeException("An unexpected error occured while executing service call [" + wfsUrl + "]", t); } finally { logger.debug("OUT"); } return featureCollection; }
Example #8
Source File: FeaturesProviderDAOWFSImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
@Override public FeatureCollection getAllFeaturesOLD(Object fetureProviderEndPoint, String layerName) { FeatureCollection featureCollection = null; String wfsUrl = null; logger.debug("IN"); try { wfsUrl = (String) fetureProviderEndPoint; wfsUrl += "?request=GetFeature" + "&typename=" + layerName + "&outputformat=json" + "&version=1.0.0"; featureCollection = getFeatures(wfsUrl); } catch (Throwable t) { throw new SpagoBIRuntimeException("An unexpected error occured while executing service call [" + wfsUrl + "]", t); } finally { logger.debug("OUT"); } return featureCollection; }
Example #9
Source File: FeatureLayerType.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
@Override public PropertySet createLayerConfig(LayerContext ctx) { final PropertyContainer configuration = new PropertyContainer(); // Mandatory Parameters configuration.addProperty(Property.create(PROPERTY_NAME_FEATURE_COLLECTION, FeatureCollection.class)); configuration.getDescriptor(PROPERTY_NAME_FEATURE_COLLECTION).setTransient(true); configuration.addProperty(Property.create(PROPERTY_NAME_SLD_STYLE, Style.class)); configuration.getDescriptor(PROPERTY_NAME_SLD_STYLE).setDomConverter(new StyleDomConverter()); configuration.getDescriptor(PROPERTY_NAME_SLD_STYLE).setNotNull(true); // Optional Parameters configuration.addProperty(Property.create(PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY, Geometry.class)); configuration.getDescriptor(PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY).setDomConverter( new GeometryDomConverter()); configuration.addProperty(Property.create(PROPERTY_NAME_FEATURE_COLLECTION_URL, URL.class)); configuration.addProperty(Property.create(PROPERTY_NAME_FEATURE_COLLECTION_CRS, CoordinateReferenceSystem.class)); configuration.getDescriptor(PROPERTY_NAME_FEATURE_COLLECTION_CRS).setDomConverter(new CRSDomConverter()); return configuration; }
Example #10
Source File: FeatureLayer.java From snap-desktop with GNU General Public License v3.0 | 6 votes |
public FeatureLayer(LayerType layerType, final FeatureCollection<SimpleFeatureType, SimpleFeature> fc, PropertySet configuration) { super(layerType, configuration); crs = fc.getSchema().getGeometryDescriptor().getCoordinateReferenceSystem(); if (crs == null) { // todo - check me! Why can this happen??? (nf) crs = DefaultGeographicCRS.WGS84; } final ReferencedEnvelope envelope = new ReferencedEnvelope(fc.getBounds(), crs); modelBounds = new Rectangle2D.Double(envelope.getMinX(), envelope.getMinY(), envelope.getWidth(), envelope.getHeight()); mapContext = new DefaultMapContext(crs); final Style style = (Style) configuration.getValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE); mapContext.addLayer(fc, style); renderer = new StreamingRenderer(); workaroundLabelCacheBug(); style.accept(new RetrievingStyleVisitor()); renderer.setContext(mapContext); }
Example #11
Source File: ImportTrackAction.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override public void actionPerformed(ActionEvent ae) { final File file = Dialogs.requestFileForOpen(Bundle.CTL_ImportSeadasTrackActionName(), false, null, "importTrack.lastDir"); if (file == null) { return; } final Product product = SnapApp.getDefault().getSelectedProduct(AUTO); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection; try { featureCollection = readTrack(file, product.getSceneGeoCoding()); } catch (IOException e) { Dialogs.showError(Bundle.CTL_ImportSeadasTrackActionName(), "Failed to load track file:\n" + e.getMessage()); return; } if (featureCollection.isEmpty()) { Dialogs.showError(Bundle.CTL_ImportSeadasTrackActionName(), "No records found."); return; } String name = FileUtils.getFilenameWithoutExtension(file); final PlacemarkDescriptor placemarkDescriptor = PlacemarkDescriptorRegistry.getInstance().getPlacemarkDescriptor(featureCollection.getSchema()); placemarkDescriptor.setUserDataOf(featureCollection.getSchema()); VectorDataNode vectorDataNode = new VectorDataNode(name, featureCollection, placemarkDescriptor); product.getVectorDataGroup().add(vectorDataNode); final ProductSceneView view = SnapApp.getDefault().getSelectedProductSceneView(); if (view != null) { view.setLayersVisible(vectorDataNode); } }
Example #12
Source File: ShapefileLoader.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private Style[] getStyles(File file, FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection) { Style[] styles = (Style[]) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_STYLES); if (styles == null || styles.length == 0) { styles = createStyle(file, featureCollection.getSchema()); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_STYLES, styles); } return styles; }
Example #13
Source File: ShapefileLoader.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection(File file) throws IOException { Object featureCollectionValue = context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection; if (featureCollectionValue == null) { featureCollection = FeatureUtils.getFeatureSource(file.toURI().toURL()).getFeatures(); } else { featureCollection = (FeatureCollection<SimpleFeatureType, SimpleFeature>) featureCollectionValue; } return featureCollection; }
Example #14
Source File: ShapefileLoader.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override protected Layer doInBackground(ProgressMonitor pm) throws Exception { try { pm.beginTask("Reading shapes", ProgressMonitor.UNKNOWN); final ProductSceneView sceneView = SnapApp.getDefault().getSelectedProductSceneView(); final Geometry clipGeometry = FeatureUtils.createGeoBoundaryPolygon(sceneView.getProduct()); File file = new File((String) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FILE_PATH)); FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = getFeatureCollection(file); CoordinateReferenceSystem featureCrs = (CoordinateReferenceSystem) context.getPropertyValue( ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS); Style[] styles = getStyles(file, featureCollection); Style selectedStyle = getSelectedStyle(styles); final LayerType type = LayerTypeRegistry.getLayerType(FeatureLayerType.class.getName()); final PropertySet configuration = type.createLayerConfig(sceneView); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_URL, file.toURI().toURL()); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION, featureCollection); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CRS, featureCrs); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY, clipGeometry); configuration.setValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE, selectedStyle); Layer featureLayer = type.createLayer(sceneView, configuration); featureLayer.setName(file.getName()); featureLayer.setVisible(true); return featureLayer; } finally { pm.done(); } }
Example #15
Source File: ShapefileAssistantPage1.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override public AbstractLayerSourceAssistantPage getNextPage() { final LayerSourcePageContext context = getContext(); fileHistoryModel.getHistory().copyInto(SnapApp.getDefault().getPreferences()); String path = (String) fileHistoryModel.getSelectedItem(); if (path != null && !path.trim().isEmpty()) { try { final String oldPath = (String) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FILE_PATH); if (!path.equals(oldPath)) { context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FILE_PATH, path); final URL fileUrl = new File(path).toURI().toURL(); final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = FeatureUtils.getFeatureSource(fileUrl); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION, featureSource.getFeatures()); // clear other properties they are not valid anymore context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_SELECTED_STYLE, null); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_STYLES, null); context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS, null); } FeatureCollection fc = (FeatureCollection) context.getPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION); final CoordinateReferenceSystem featureCrs = fc.getSchema().getCoordinateReferenceSystem(); if (featureCrs == null) { return new ShapefileAssistantPage2(); } else { context.setPropertyValue(ShapefileLayerSource.PROPERTY_NAME_FEATURE_COLLECTION_CRS, featureCrs); return new ShapefileAssistantPage3(); } } catch (Exception e) { e.printStackTrace(); context.showErrorDialog("Failed to load ESRI shapefile:\n" + e.getMessage()); } } return null; }
Example #16
Source File: ExportGeometryAction.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private static Map<Class<?>, List<SimpleFeature>> createGeometryToFeaturesListMap(VectorDataNode vectorNode) throws TransformException, SchemaException { FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = vectorNode.getFeatureCollection(); CoordinateReferenceSystem crs = vectorNode.getFeatureType().getCoordinateReferenceSystem(); if (crs == null) { // for pins and GCPs crs is null crs = vectorNode.getProduct().getSceneCRS(); } final CoordinateReferenceSystem modelCrs; if (vectorNode.getProduct().getSceneGeoCoding() instanceof CrsGeoCoding) { modelCrs = vectorNode.getProduct().getSceneCRS(); } else { modelCrs = DefaultGeographicCRS.WGS84; } // Not using ReprojectingFeatureCollection - it is reprojecting all geometries of a feature // but we want to reproject the default geometry only GeometryCoordinateSequenceTransformer transformer = createTransformer(crs, modelCrs); Map<Class<?>, List<SimpleFeature>> featureListMap = new HashMap<>(); final FeatureIterator<SimpleFeature> featureIterator = featureCollection.features(); // The schema needs to be reprojected. We need to build a new feature be cause we can't change the schema. // It is necessary to have this reprojected schema, because otherwise the shapefile is not correctly georeferenced. SimpleFeatureType schema = featureCollection.getSchema(); SimpleFeatureType transformedSchema = FeatureTypes.transform(schema, modelCrs); while (featureIterator.hasNext()) { SimpleFeature feature = featureIterator.next(); Object defaultGeometry = feature.getDefaultGeometry(); feature.setDefaultGeometry(transformer.transform((Geometry) defaultGeometry)); Class<?> geometryType = defaultGeometry.getClass(); List<SimpleFeature> featureList = featureListMap.computeIfAbsent(geometryType, k -> new ArrayList<>()); SimpleFeature exportFeature = SimpleFeatureBuilder.build(transformedSchema, feature.getAttributes(), feature.getID()); featureList.add(exportFeature); } return featureListMap; }
Example #17
Source File: FeatureLayerConfigurationPersistencyTest.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
@Override protected Layer createLayer(LayerType layerType) throws Exception { final PropertySet configuration = layerType.createLayerConfig(null); final URL shapefileUrl = getClass().getResource("bundeslaender.shp"); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_URL, shapefileUrl); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CRS, DefaultGeographicCRS.WGS84); final Coordinate[] coordinates = { new Coordinate(-10, 50), new Coordinate(+10, 50), new Coordinate(+10, 30), new Coordinate(-10, 30), new Coordinate(-10, 50) }; final GeometryFactory geometryFactory = new GeometryFactory(); final LinearRing ring = geometryFactory.createLinearRing(coordinates); final Polygon clipGeometry = geometryFactory.createPolygon(ring, new LinearRing[0]); configuration.setValue(FeatureLayerType.PROPERTY_NAME_FEATURE_COLLECTION_CLIP_GEOMETRY, clipGeometry); configuration.setValue(FeatureLayerType.PROPERTY_NAME_SLD_STYLE, createStyle()); FeatureCollection<SimpleFeatureType, SimpleFeature> fc; try { fc = FeatureUtils.createFeatureCollection( shapefileUrl, DefaultGeographicCRS.WGS84, clipGeometry); } catch (IOException e) { throw new IllegalArgumentException(e); } return new FeatureLayer(layerType, fc, configuration); }
Example #18
Source File: ImportTrackAction.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private static void transformFeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection, CoordinateReferenceSystem targetCRS) throws TransformException { final GeometryCoordinateSequenceTransformer transform = FeatureUtils.getTransform(DefaultGeographicCRS.WGS84, targetCRS); final FeatureIterator<SimpleFeature> features = featureCollection.features(); final GeometryFactory geometryFactory = new GeometryFactory(); while (features.hasNext()) { final SimpleFeature simpleFeature = features.next(); final Point sourcePoint = (Point) simpleFeature.getDefaultGeometry(); final Point targetPoint = transform.transformPoint(sourcePoint, geometryFactory); simpleFeature.setDefaultGeometry(targetPoint); } }
Example #19
Source File: ImportTrackAction.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
static FeatureCollection<SimpleFeatureType, SimpleFeature> readTrack(Reader reader, GeoCoding geoCoding) throws IOException { CsvReader csvReader = new CsvReader(reader, new char[]{'\t', ' '}, true, "#"); SimpleFeatureType trackFeatureType = createTrackFeatureType(geoCoding); ListFeatureCollection featureCollection = new ListFeatureCollection(trackFeatureType); double[] record; int pointIndex = 0; while ((record = csvReader.readDoubleRecord()) != null) { if (record.length < 3) { throw new IOException("Illegal track file format.\n" + "Expecting tab-separated lines containing 3 values: lat, lon, data."); } float lat = (float) record[0]; float lon = (float) record[1]; double data = record[2]; final SimpleFeature feature = createFeature(trackFeatureType, geoCoding, pointIndex, lat, lon, data); if (feature != null) { featureCollection.add(feature); } pointIndex++; } if (featureCollection.isEmpty()) { throw new IOException("No track point found or all of them are located outside the scene boundaries."); } final CoordinateReferenceSystem mapCRS = geoCoding.getMapCRS(); if (!mapCRS.equals(DefaultGeographicCRS.WGS84)) { try { transformFeatureCollection(featureCollection, mapCRS); } catch (TransformException e) { throw new IOException("Cannot transform the ship track onto CRS '" + mapCRS.toWKT() + "'.", e); } } return featureCollection; }
Example #20
Source File: VectorDataLayer.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private void updateFigureCollection() { FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollection = vectorDataNode.getFeatureCollection(); Figure[] figures = figureCollection.getFigures(); Map<SimpleFeature, SimpleFeatureFigure> figureMap = new HashMap<>(); for (Figure figure : figures) { if (figure instanceof SimpleFeatureFigure) { SimpleFeatureFigure simpleFeatureFigure = (SimpleFeatureFigure) figure; figureMap.put(simpleFeatureFigure.getSimpleFeature(), simpleFeatureFigure); } } FeatureIterator<SimpleFeature> featureIterator = featureCollection.features(); while (featureIterator.hasNext()) { SimpleFeature simpleFeature = featureIterator.next(); SimpleFeatureFigure featureFigure = figureMap.get(simpleFeature); if (featureFigure != null) { figureMap.remove(simpleFeature); Placemark placemark = vectorDataNode.getPlacemarkGroup().getPlacemark(simpleFeature); if(placemark != null) { String css = placemark.getStyleCss(); final FigureStyle normalStyle = DefaultFigureStyle.createFromCss(css); final FigureStyle selectedStyle = getFigureFactory().deriveSelectedStyle(normalStyle); featureFigure.setNormalStyle(normalStyle); featureFigure.setSelectedStyle(selectedStyle); } } else { featureFigure = getFigureFactory().createSimpleFeatureFigure(simpleFeature, vectorDataNode.getDefaultStyleCss()); figureCollection.addFigure(featureFigure); } featureFigure.forceRegeneration(); } Collection<SimpleFeatureFigure> remainingFigures = figureMap.values(); figureCollection.removeFigures(remainingFigures.toArray(new Figure[remainingFigures.size()])); }
Example #21
Source File: FeatureCollectionValues.java From sldeditor with GNU General Public License v3.0 | 5 votes |
@Override public void setValue(Object aValue) { this.value = null; this.expression = null; if (aValue instanceof FeatureCollection) { this.value = (FeatureCollection) aValue; } else if ((aValue instanceof AttributeExpressionImpl) || (aValue instanceof LiteralExpressionImpl) || (aValue instanceof FunctionExpressionImpl) || (aValue instanceof MathExpressionImpl)) { this.expression = (Expression) aValue; } }
Example #22
Source File: FeaturesProviderDAOWFSImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
@Override public SimpleFeature getFeatureById(Object fetureProviderEndPoint, String layerName, Map parameters) { FeatureCollection featureCollection; String wfsUrl = null; String geoIdPName = null; String geoIdPValue = null; logger.debug("IN"); try { wfsUrl = (String) fetureProviderEndPoint; geoIdPName = (String) parameters.get(GEOID_PNAME); logger.debug("Parameter [" + GEOID_PNAME + "] is equal to [" + geoIdPName + "]"); geoIdPValue = (String) parameters.get(GEOID_PVALUE); logger.debug("Parameter [" + GEOID_PVALUE + "] is equal to [" + geoIdPValue + "]"); wfsUrl += "?request=GetFeature" + "&typename=" + layerName + "&Filter=<Filter><PropertyIsEqualTo><PropertyName>" + geoIdPName + "</PropertyName><Literal>" + geoIdPValue + "</Literal></PropertyIsEqualTo></Filter>" + "&outputformat=json" + "&version=1.0.0"; featureCollection = getFeatures(wfsUrl); } catch (Throwable t) { throw new SpagoBIRuntimeException("An unexpected error occured while executing service call [" + wfsUrl + "]", t); } finally { logger.debug("OUT"); } return (SimpleFeature) featureCollection.features().next(); }
Example #23
Source File: ShapeInMemLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Retrieve the bounds of the specified features. * * @param filter filter * @return the bounds of the specified features * @throws LayerException cannot read features */ public Envelope getBounds(Filter filter) throws LayerException { try { FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureSource().getFeatures(filter); return fc.getBounds(); } catch (IOException ioe) { throw new LayerException(ioe, ExceptionCode.FEATURE_MODEL_PROBLEM); } }
Example #24
Source File: ShapeInMemLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
/** * Finish initializing the layer. * * @throws LayerException oops */ @PostConstruct protected void initFeatures() throws LayerException { crs = geoService.getCrs2(layerInfo.getCrs()); try { setFeatureSourceName(layerInfo.getFeatureInfo().getDataSourceName()); featureModel = new ShapeInMemFeatureModel(getDataStore(), layerInfo.getFeatureInfo().getDataSourceName(), geoService.getSridFromCrs(layerInfo.getCrs()), converterService); featureModel.setLayerInfo(layerInfo); FeatureCollection<SimpleFeatureType, SimpleFeature> col = getFeatureSource().getFeatures(); FeatureIterator<SimpleFeature> iterator = col.features(); int lastIndex = 0; while (iterator.hasNext()) { SimpleFeature feature = iterator.next(); String id = featureModel.getId(feature); features.put(id, feature); int intId = Integer.parseInt(id.substring(id.lastIndexOf('.') + 1)); if (intId > lastIndex) { lastIndex = intId; } } iterator.close(); ((ShapeInMemFeatureModel) featureModel).setNextId(++lastIndex); } catch (NumberFormatException nfe) { throw new LayerException(nfe, ExceptionCode.FEATURE_MODEL_PROBLEM, url); } catch (MalformedURLException e) { throw new LayerException(e, ExceptionCode.INVALID_SHAPE_FILE_URL, url); } catch (IOException ioe) { throw new LayerException(ioe, ExceptionCode.CANNOT_CREATE_LAYER_MODEL, url); } catch (GeomajasException ge) { throw new LayerException(ge, ExceptionCode.CANNOT_CREATE_LAYER_MODEL, url); } }
Example #25
Source File: WmsLayer.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
private List<Feature> getGmlFeatures(InputStream stream, Version version) throws IOException, SAXException, ParserConfigurationException { List<Feature> features = new ArrayList<Feature>(); GML gml = new GML(version); FeatureCollection<?, SimpleFeature> collection = gml.decodeFeatureCollection(stream); FeatureIterator<SimpleFeature> it = collection.features(); while (it.hasNext()) { features.add(toDto(it.next())); } return features; }
Example #26
Source File: InsertWktGeometryAction.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
@Override public void actionPerformed(ActionEvent event) { JTextArea textArea = new JTextArea(16, 32); textArea.setEditable(true); JPanel contentPanel = new JPanel(new BorderLayout(4, 4)); contentPanel.add(new JLabel("Geometry Well-Known-Text (WKT):"), BorderLayout.NORTH); contentPanel.add(new JScrollPane(textArea), BorderLayout.CENTER); SnapApp snapApp = SnapApp.getDefault(); ModalDialog modalDialog = new ModalDialog(snapApp.getMainFrame(), Bundle.CTL_InsertWktGeometryAction_DialogTitle(), ModalDialog.ID_OK_CANCEL, null); modalDialog.setContent(contentPanel); modalDialog.center(); if (modalDialog.show() == ModalDialog.ID_OK) { String wellKnownText = textArea.getText(); if (wellKnownText == null || wellKnownText.isEmpty()) { return; } ProductSceneView sceneView = snapApp.getSelectedProductSceneView(); VectorDataLayer vectorDataLayer = InsertFigureInteractorInterceptor.getActiveVectorDataLayer(sceneView); if (vectorDataLayer == null) { return; } SimpleFeatureType wktFeatureType = PlainFeatureFactory.createDefaultFeatureType(DefaultGeographicCRS.WGS84); ListFeatureCollection newCollection = new ListFeatureCollection(wktFeatureType); SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(wktFeatureType); SimpleFeature wktFeature = featureBuilder.buildFeature("ID" + Long.toHexString(currentFeatureId++)); Geometry geometry; try { geometry = new WKTReader().read(wellKnownText); } catch (ParseException e) { snapApp.handleError("Failed to convert WKT into geometry", e); return; } wktFeature.setDefaultGeometry(geometry); newCollection.add(wktFeature); FeatureCollection<SimpleFeatureType, SimpleFeature> productFeatures = FeatureUtils.clipFeatureCollectionToProductBounds( newCollection, sceneView.getProduct(), null, ProgressMonitor.NULL); if (productFeatures.isEmpty()) { Dialogs.showError(Bundle.CTL_InsertWktGeometryAction_MenuText(), "The geometry is not contained in the product."); } else { vectorDataLayer.getVectorDataNode().getFeatureCollection().addAll(productFeatures); } } }
Example #27
Source File: PutStatisticsIntoVectorDataAction.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection(SimpleFeatureType featureType) { return featureType2VDN.get(featureType).getFeatureCollection(); }
Example #28
Source File: ImportTrackAction.java From snap-desktop with GNU General Public License v3.0 | 4 votes |
private static FeatureCollection<SimpleFeatureType, SimpleFeature> readTrack(File file, GeoCoding geoCoding) throws IOException { try (Reader reader = new FileReader(file)) { return readTrack(reader, geoCoding); } }
Example #29
Source File: FeatureCollectionValuesTest.java From sldeditor with GNU General Public License v3.0 | 4 votes |
/** * Test method for {@link * com.sldeditor.rendertransformation.types.FeatureCollectionValues#FeatureCollectionValues()}. */ @Test void testFeatureCollectionValues() { FeatureCollectionValues testObj = new FeatureCollectionValues(); testObj.createInstance(); assertEquals( Arrays.asList(FeatureCollection.class, SimpleFeatureCollection.class), testObj.getType()); @SuppressWarnings("rawtypes") FeatureCollection fc = new DefaultFeatureCollection(); testObj.setDefaultValue(fc); assertNull(testObj.getExpression()); // FeatureCollection value testObj.setValue(fc); assertNull(testObj.getExpression()); // Literal expression Expression expectedExpression = ff.literal(fc); testObj.setValue(expectedExpression); assertEquals(testObj.getExpression(), expectedExpression); // Attribute expression expectedExpression = ff.property("test"); testObj.setValue(expectedExpression); assertEquals(expectedExpression, testObj.getExpression()); // Not set testObj.setValue(null); assertNull(testObj.getExpression()); FieldConfigBase field = testObj.getField( new FieldConfigCommonData( FeatureCollectionValues.class, FieldIdEnum.INITIAL_GAP, "label", true, false, false)); assertEquals(FieldConfigGeometry.class, field.getClass()); // Increase code coverage TestFeatureCollectionValues testObj2 = new TestFeatureCollectionValues(); testObj2.populateSymbolType(null); }
Example #30
Source File: FeatureCollectionValues.java From sldeditor with GNU General Public License v3.0 | 4 votes |
@Override public List<Class<?>> getType() { return Arrays.asList(FeatureCollection.class, SimpleFeatureCollection.class); }