Java Code Examples for org.opengis.feature.simple.SimpleFeature#getDefaultGeometry()
The following examples show how to use
org.opengis.feature.simple.SimpleFeature#getDefaultGeometry() .
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: BasicMapReduceIT.java From geowave with Apache License 2.0 | 6 votes |
@Override protected void mapNativeValue( final GeoWaveInputKey key, final Object value, final Mapper<GeoWaveInputKey, ObjectWritable, NullWritable, NullWritable>.Context context) throws IOException, InterruptedException { ResultCounterType resultType = ResultCounterType.ERROR; if (value instanceof SimpleFeature) { final SimpleFeature result = (SimpleFeature) value; final Geometry geometry = (Geometry) result.getDefaultGeometry(); if (!geometry.isEmpty()) { resultType = expectedHashedCentroids.contains(TestUtils.hashCentroid(geometry)) ? ResultCounterType.EXPECTED : ResultCounterType.UNEXPECTED; } } context.getCounter(resultType).increment(1); }
Example 2
Source File: LasOnDtmBuildingsExtractor.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private DefaultFeatureCollection removeNonBuildings( ALasDataManager lasHandler, SimpleFeatureCollection buildingsFC, GridCoverage2D dem, double buildingsBuffer ) throws Exception { final List<SimpleFeature> buildingsList = FeatureUtilities.featureCollectionToList(buildingsFC); final List<SimpleFeature> checkedBuildings = new ArrayList<SimpleFeature>(); pm.beginTask("Removing buildings...", buildingsList.size()); for( int i = 0; i < buildingsList.size(); i++ ) { SimpleFeature building = buildingsList.get(i); Geometry buildingGeom = (Geometry) building.getDefaultGeometry(); Geometry bufferedGeom = buildingGeom.buffer(buildingsBuffer); List<LasRecord> points = lasHandler.getPointsInGeometry(bufferedGeom, false); int percOfOnes = checkReturnNum(points, bufferedGeom); if (percOfOnes >= 96) { checkedBuildings.add(building); } pm.worked(1); } pm.done(); DefaultFeatureCollection fc = new DefaultFeatureCollection(); fc.addAll(checkedBuildings); return fc; }
Example 3
Source File: TestDxfConverter.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("nls") public void testVectorFilter() throws Exception { URL testUrl = this.getClass().getClassLoader().getResource("test.dxf"); String dxfFile = new File(testUrl.toURI()).getAbsolutePath(); OmsDxfConverter reader = new OmsDxfConverter(); reader.file = dxfFile; reader.process(); SimpleFeatureCollection pointsFC = reader.pointsVector; SimpleFeatureCollection linesFC = reader.lineVector; assertTrue(pointsFC.size() == 0); assertTrue(linesFC.size() == 1); SimpleFeature feature = linesFC.features().next(); Geometry geometry = (Geometry) feature.getDefaultGeometry(); Coordinate[] coordinates = geometry.getCoordinates(); double delta = 0.000001; assertEquals(coordinates[0].x, 0.0, delta); assertEquals(coordinates[0].y, 0.0, delta); assertEquals(coordinates[1].x, 10.0, delta); assertEquals(coordinates[1].y, 10.0, delta); }
Example 4
Source File: TestVectorReshaper.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testConvexHull() throws Exception { String cql = "the_geom=convexHull(the_geom)"; GeometryFactory gf = GeometryUtilities.gf(); MultiPoint multiPoint = gf.createMultiPoint(new Coordinate[]{// HMTestMaps.getWestNorth(), HMTestMaps.getEastSouth(), HMTestMaps.getEastNorth()}); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(HMTestMaps.getCrs()); b.add("the_geom", MultiPoint.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Object[] values = new Object[]{multiPoint}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); newCollection.add(feature); OmsVectorReshaper reshaper = new OmsVectorReshaper(); reshaper.inVector = newCollection; reshaper.pCql = cql; reshaper.process(); SimpleFeatureCollection outFC = reshaper.outVector; FeatureIterator<SimpleFeature> featureIterator = outFC.features(); SimpleFeature newFeature = featureIterator.next(); Geometry geometry = (Geometry) newFeature.getDefaultGeometry(); String geometryType = geometry.getGeometryType(); assertTrue(geometryType.toUpperCase().equals("POLYGON")); featureIterator.close(); }
Example 5
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 6
Source File: OmsEpanetInpGenerator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private String handleVertices( List<SimpleFeature> pipesList ) throws IOException { StringBuilder sbPipesVertices = new StringBuilder(); sbPipesVertices.append("\n\n[VERTICES]\n"); sbPipesVertices.append(";NODE").append(SPACER); sbPipesVertices.append("XCOORD").append(SPACER); sbPipesVertices.append("YCOORD").append(NL); for( SimpleFeature pipe : pipesList ) { Geometry geometry = (Geometry) pipe.getDefaultGeometry(); Coordinate[] coordinates = geometry.getCoordinates(); // [PIPES] Object id = getAttribute(pipe, Pipes.ID.getAttributeName()); String idString = id.toString(); if (idString.toUpperCase().startsWith(EpanetConstants.DUMMYPIPE.toString())) { continue; } // [VERTICES] for( Coordinate coordinate : coordinates ) { sbPipesVertices.append(idString); sbPipesVertices.append(SPACER); sbPipesVertices.append(coordinate.x); sbPipesVertices.append(SPACER); sbPipesVertices.append(coordinate.y); sbPipesVertices.append(NL); } } sbPipesVertices.append("\n\n"); return sbPipesVertices.toString(); }
Example 7
Source File: OmsEpanetInpGenerator.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
private String handleCoordinates( List<SimpleFeature> junctionsList, List<SimpleFeature> reservoirsList, List<SimpleFeature> tanksList ) throws IOException { ArrayList<SimpleFeature> nodesList = new ArrayList<SimpleFeature>(); nodesList.addAll(junctionsList); nodesList.addAll(reservoirsList); nodesList.addAll(tanksList); StringBuilder sbJunctionsCoords = new StringBuilder(); sbJunctionsCoords.append("\n\n[COORDINATES]\n"); sbJunctionsCoords.append(";NODE").append(SPACER); sbJunctionsCoords.append("XCOORD").append(SPACER); sbJunctionsCoords.append("YCOORD").append(NL); for( SimpleFeature node : nodesList ) { Geometry geometry = (Geometry) node.getDefaultGeometry(); Coordinate coordinate = geometry.getCoordinate(); // [COORDINATES] Object attribute = getAttribute(node, Junctions.ID.getAttributeName()); sbJunctionsCoords.append(attribute.toString()); sbJunctionsCoords.append(SPACER); sbJunctionsCoords.append(coordinate.x); sbJunctionsCoords.append(SPACER); sbJunctionsCoords.append(coordinate.y); sbJunctionsCoords.append(NL); } sbJunctionsCoords.append("\n\n"); return sbJunctionsCoords.toString(); }
Example 8
Source File: ShapeInMemFilterTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void withinFilter() throws LayerException { SimpleFeature feature = (SimpleFeature) layer.read(LAYER_NAME+".7"); Geometry geom = (Geometry) feature.getDefaultGeometry(); Filter filter = filterService.createWithinFilter(geom, PARAM_GEOMETRY_ATTR); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { it.next(); t++; } Assert.assertEquals(4, t); }
Example 9
Source File: TrackLayerType.java From snap-desktop with GNU General Public License v3.0 | 5 votes |
private void drawTrackPointConnections0(Rendering rendering) { // todo - get these styles from vector data node. (nf) rendering.getGraphics().setPaint(strokePaint); float scalingFactor = (float) rendering.getViewport().getViewToModelTransform().getScaleX(); float effectiveStrokeWidth = (float) (scalingFactor * STROKE_WIDTH); float effectiveDash = Math.max(1.0F, scalingFactor * 5.0F); float effectiveMeterLimit = Math.max(1.0F, scalingFactor * 10.0F); BasicStroke basicStroke = new BasicStroke(effectiveStrokeWidth, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_MITER, effectiveMeterLimit, new float[]{ effectiveDash, effectiveDash}, 0.0f); rendering.getGraphics().setStroke(basicStroke); // FeatureCollection.toArray() returns the feature in original order // todo - must actually sort using some (timestamp) attribute (nf) SimpleFeature[] features = getVectorDataNode().getFeatureCollection().toArray(new SimpleFeature[0]); double lastX = 0; double lastY = 0; for (int i = 0; i < features.length; i++) { SimpleFeature feature = features[i]; Geometry geometry = (Geometry) feature.getDefaultGeometry(); org.locationtech.jts.geom.Point centroid = geometry.getCentroid(); try { final Point2D.Double sceneCoords = new Point2D.Double(centroid.getX(), centroid.getY()); final Point2D.Double modelCoords = new Point2D.Double(); sceneTransformProvider.getSceneToModelTransform().transform(sceneCoords, modelCoords); if (i > 0) { rendering.getGraphics().draw(new Line2D.Double(lastX, lastY, centroid.getX(), centroid.getY())); } lastX = modelCoords.getX(); lastY = modelCoords.getY(); } catch (TransformException e) { //continue loop } } }
Example 10
Source File: ShapeInMemFilterTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void containsFilter() throws LayerException { SimpleFeature feature = (SimpleFeature) layer.read(LAYER_NAME+".1"); Geometry geom = (Geometry) feature.getDefaultGeometry(); Filter filter = filterService.createContainsFilter(geom, PARAM_GEOMETRY_ATTR); Iterator<?> it = layer.getElements(filter, 0, 0); int t = 0; while (it.hasNext()) { it.next(); t++; } Assert.assertEquals(3, t); }
Example 11
Source File: FeatureCentroidDistanceFn.java From geowave with Apache License 2.0 | 5 votes |
private Geometry getGeometry(final SimpleFeature x) { for (final Object attr : x.getAttributes()) { if (attr instanceof Geometry) { return (Geometry) attr; } } return (Geometry) x.getDefaultGeometry(); }
Example 12
Source File: TestVectorizer.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorizer2() throws Exception { double[][] inData = HMTestMaps.extractNet0Data; HashMap<String, Double> envelopeParams = HMTestMaps.getEnvelopeparams(); CoordinateReferenceSystem crs = HMTestMaps.getCrs(); GridCoverage2D inCoverage = CoverageUtilities.buildCoverage("data", inData, envelopeParams, crs, true); OmsVectorizer vectorizer = new OmsVectorizer(); vectorizer.pm = pm; vectorizer.inRaster = inCoverage; vectorizer.pValue = null; vectorizer.pThres = 1; vectorizer.fDefault = "rast"; vectorizer.process(); SimpleFeatureCollection outGeodata = vectorizer.outVector; assertEquals(2, outGeodata.size()); List<SimpleFeature> features = FeatureUtilities.featureCollectionToList(outGeodata); SimpleFeature f1 = features.get(0); SimpleFeature f2 = features.get(1); Geometry g1 = (Geometry) f1.getDefaultGeometry(); Geometry g2 = (Geometry) f2.getDefaultGeometry(); // SimpleFeature nvFeature = f1; SimpleFeature valuesFeature = f2; if (g1.getArea() < g2.getArea()) { // nvFeature = f2; valuesFeature = f1; } double value = ((Number) valuesFeature.getAttribute("rast")).doubleValue(); assertEquals(2.0, value, 0.0000001); Geometry geometry = (Geometry) valuesFeature.getDefaultGeometry(); double area = geometry.getArea(); assertEquals(6300.0, area, 0.0000001); }
Example 13
Source File: OmsRiverSectionsExtractor.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inElev, inRiver); gf = GeometryUtilities.gf(); List<SimpleFeature> riverFeatures = FeatureUtilities.featureCollectionToList(inRiver); SimpleFeature riverFeature = riverFeatures.get(0); Geometry geometry = (Geometry) riverFeature.getDefaultGeometry(); Coordinate[] riverCoordinates = geometry.getCoordinates(); RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inElev); Envelope envelope = regionMap.toEnvelope(); pm.beginTask("Building 3D reach geometry...", riverCoordinates.length); Point2D.Double point = new Point2D.Double(); double[] extracted = new double[1]; for( int i = 0; i < riverCoordinates.length; i++ ) { Coordinate coordinate = riverCoordinates[i]; if (!envelope.intersects(coordinate.x, coordinate.y)) { pm.worked(1); continue; } point.setLocation(coordinate.x, coordinate.y); inElev.evaluate(point, extracted); riverCoordinates[i] = new Coordinate(coordinate.x, coordinate.y, extracted[0]); pm.worked(1); } pm.done(); LineString riverGeometry3d = gf.createLineString(riverCoordinates); ARiverSectionsExtractor sectionsExtractor; if (inSections == null) { List<FeatureMate> bridgePoints = new ArrayList<>(); if (inBridges != null) { bridgePoints = FeatureUtilities.featureCollectionToMatesList(inBridges); } if (inRiverPoints != null) { List<SimpleFeature> riverPointsList = FeatureUtilities.featureCollectionToList(inRiverPoints); Coordinate[] riverPointCoordinates = new Coordinate[riverPointsList.size()]; int[] riverPointIds = new int[riverPointsList.size()]; double[] riverPointKs = new double[riverPointsList.size()]; for( int i = 0; i < riverPointIds.length; i++ ) { SimpleFeature riverPointFeature = riverPointsList.get(i); Coordinate riverPointCoordinate = ((Geometry) riverPointFeature.getDefaultGeometry()).getCoordinate(); int id = ((Number) riverPointFeature.getAttribute(LWFields.LINKID)).intValue(); riverPointCoordinates[i] = riverPointCoordinate; riverPointIds[i] = id; Object attribute = riverPointFeature.getAttribute(LWFields.GAUKLER); if (attribute != null) { double ks = ((Number) attribute).doubleValue(); riverPointKs[i] = ks; } else { riverPointKs[i] = 30.0; } } sectionsExtractor = new RiverSectionsFromDtmExtractor(riverGeometry3d, // riverPointCoordinates, riverPointIds, riverPointKs, // inElev, pSectionsIntervalDistance, pSectionsWidth, bridgePoints, fBridgeWidth, pBridgeBuffer, pm); } else { sectionsExtractor = new RiverSectionsFromDtmExtractor(riverGeometry3d, // inElev, pSectionsIntervalDistance, pSectionsWidth, bridgePoints, fBridgeWidth, pBridgeBuffer, pm); } } else { List<SimpleFeature> sectionsList = FeatureUtilities.featureCollectionToList(inSections); sectionsExtractor = new RiverSectionsFromFeaturesExtractor(riverGeometry3d, inElev, sectionsList, pm); } outSections = sectionsExtractor.getSectionsCollection(); outSectionPoints = sectionsExtractor.getSectionPointsCollection(); outRiverPoints = sectionsExtractor.getRiverPointsCollection(); }
Example 14
Source File: TestVectorReader.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public void testShapefileReader() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", Point.class); b.add("id", Integer.class); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); SimpleFeatureType type = b.buildFeatureType(); for( int i = 0; i < 2; i++ ) { SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Point point = GeometryUtilities.gf().createPoint(new Coordinate(i, i)); Object[] values = new Object[]{point, i}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + i); newCollection.add(feature); } File tmpShape = File.createTempFile("testshp", ".shp"); if (tmpShape.exists()) { if (!tmpShape.delete()) throw new IOException(); } OmsVectorWriter writer = new OmsVectorWriter(); writer.file = tmpShape.getAbsolutePath(); writer.inVector = newCollection; writer.process(); // now read it again OmsVectorReader reader = new OmsVectorReader(); reader.file = tmpShape.getAbsolutePath(); reader.process(); SimpleFeatureCollection readFC = reader.outVector; FeatureIterator<SimpleFeature> featureIterator = readFC.features(); while( featureIterator.hasNext() ) { SimpleFeature f = featureIterator.next(); int id = ((Number) f.getAttribute("id")).intValue(); Geometry geometry = (Geometry) f.getDefaultGeometry(); Coordinate coordinate = geometry.getCoordinate(); if (id == 0) { assertEquals(coordinate.x, 0.0); assertEquals(coordinate.y, 0.0); } if (id == 1) { assertEquals(coordinate.x, 1.0); assertEquals(coordinate.y, 1.0); } if (id == 2) { assertEquals(coordinate.x, 2.0); assertEquals(coordinate.y, 2.0); } } if (tmpShape.exists()) { tmpShape.deleteOnExit(); } }
Example 15
Source File: OmsBuffer.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inMap); int joinStyle; if (pJoinstyle.equals(JOIN_MITRE)) { joinStyle = BufferParameters.JOIN_MITRE; } else if (pJoinstyle.equals(JOIN_BEVEL)) { joinStyle = BufferParameters.JOIN_BEVEL; } else { joinStyle = BufferParameters.JOIN_ROUND; } int endCapStyle; if (pCapstyle.equals(CAP_FLAT)) { endCapStyle = BufferParameters.CAP_FLAT; } else if (pCapstyle.equals(CAP_SQUARE)) { endCapStyle = BufferParameters.CAP_SQUARE; } else { endCapStyle = BufferParameters.CAP_ROUND; } FeatureGeometrySubstitutor fgs = new FeatureGeometrySubstitutor(inMap.getSchema(), MultiPolygon.class); DefaultFeatureCollection outMaptmp = new DefaultFeatureCollection("new", fgs.getNewFeatureType()); GeometryFactory gf = GeometryUtilities.gf(); List<SimpleFeature> featuresList = FeatureUtilities.featureCollectionToList(inMap); pm.beginTask("Buffering geometries...", featuresList.size()); for( SimpleFeature feature : featuresList ) { Geometry geometry = (Geometry) feature.getDefaultGeometry(); double buf = pBuffer; if (pBufferField != null) { Object bFieldObj = feature.getAttribute(pBufferField); if (bFieldObj instanceof Number) { buf = ((Number) bFieldObj).doubleValue(); } } BufferParameters bP = new BufferParameters(quadrantSegments, endCapStyle, joinStyle, mitreLimit); Geometry bufferedGeom = BufferOp.bufferOp(geometry, buf, bP); List<Polygon> polygons = new ArrayList<Polygon>(bufferedGeom.getNumGeometries()); for( int i = 0; i < bufferedGeom.getNumGeometries(); i++ ) { Geometry geometryN = bufferedGeom.getGeometryN(i); if (geometryN instanceof Polygon) { polygons.add((Polygon) geometryN); } else { pm.errorMessage("Ignored non polygonal geometry in: " + geometryN.toText()); } } MultiPolygon multiPolygon = gf.createMultiPolygon(polygons.toArray(GeometryUtilities.TYPE_POLYGON)); SimpleFeature newFeature = fgs.substituteGeometry(feature, multiPolygon); outMaptmp.add(newFeature); pm.worked(1); } pm.done(); outMap = outMaptmp; }
Example 16
Source File: OmsVoronoiDiagram.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inMap); if (!EGeometryType.isPoint(inMap.getSchema().getGeometryDescriptor())) { throw new ModelsIllegalargumentException("The input geometry needs to be points.", this, pm); } if (fElev != null) { fElev = FeatureUtilities.findAttributeName(inMap.getSchema(), fElev); if (fElev == null) { throw new ModelsIllegalargumentException("Couldn't find field: " + fElev, this); } } CoordinateReferenceSystem crs = inMap.getBounds().getCoordinateReferenceSystem(); List<SimpleFeature> fList = FeatureUtilities.featureCollectionToList(inMap); pm.beginTask("Processing...", fList.size()); VoronoiDiagramBuilder b = new VoronoiDiagramBuilder(); List<Coordinate> cList = new ArrayList<Coordinate>(); for( SimpleFeature f : fList ) { Geometry geometry = (Geometry) f.getDefaultGeometry(); double elev = 0.0; if (fElev != null) elev = (Double) f.getAttribute(fElev); Coordinate c = geometry.getCoordinate(); c.z = elev; cList.add(c); pm.worked(1); } pm.done(); b.setSites(cList); List<Geometry> geosList = new ArrayList<Geometry>(); Geometry diagram = b.getDiagram(gf); for( int i = 0; i < diagram.getNumGeometries(); i++ ) { Geometry geometryN = diagram.getGeometryN(i); Coordinate[] coordinates = geometryN.getCoordinates(); double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; for( Coordinate coordinate : coordinates ) { min = Math.min(min, coordinate.z); max = Math.max(max, coordinate.z); } geometryN.setUserData(new String[]{"" + min, "" + max}); geosList.add(geometryN); } outMap = FeatureUtilities.featureCollectionFromGeometry(crs, geosList.toArray(new Geometry[0])); }
Example 17
Source File: SimpleFeatureProjection.java From geowave with Apache License 2.0 | 4 votes |
@Override public Geometry getProjection(final SimpleFeature anItem) { return (Geometry) anItem.getDefaultGeometry(); }
Example 18
Source File: OmsVectorIntersector.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inMap1, inMap2); outMap = new DefaultFeatureCollection(); if (!doKeepFirstAttributes) { SimpleFeatureCollection inMapTmp = inMap1; inMap1 = inMap2; inMap2 = inMapTmp; } List<Geometry> geometries = FeatureUtilities.featureCollectionToGeometriesList(inMap2, false, null); GeometryCollection geometryCollection = new GeometryCollection(geometries.toArray(new Geometry[geometries.size()]), gf); Geometry intersectionGeometry = geometryCollection.buffer(0); PreparedGeometry preparedIntersectionGeometry = PreparedGeometryFactory.prepare(intersectionGeometry); List<SimpleFeature> mainFeatures = FeatureUtilities.featureCollectionToList(inMap1); if (mainFeatures.size() == 0) { throw new ModelsIllegalargumentException("No features found in the layer.", this); } EGeometryType geometryType = EGeometryType.forGeometry((Geometry) mainFeatures.get(0).getDefaultGeometry()); Class< ? > multiClazz = geometryType.getMultiClazz(); EGeometryType newGeometryType = EGeometryType.forClass(multiClazz); FeatureGeometrySubstitutor sub = new FeatureGeometrySubstitutor(inMap1.getSchema(), multiClazz); pm.beginTask("Performing intersection...", mainFeatures.size()); for( SimpleFeature feature : mainFeatures ) { Geometry geometry = (Geometry) feature.getDefaultGeometry(); if (preparedIntersectionGeometry.intersects(geometry)) { Geometry intersection = geometry.intersection(intersectionGeometry); EGeometryType intersectionGeometryType = EGeometryType.forGeometry(intersection); if (intersectionGeometryType.isCompatibleWith(newGeometryType)) { SimpleFeature newFeature = sub.substituteGeometry(feature, intersection); ((DefaultFeatureCollection) outMap).add(newFeature); } else { pm.errorMessage("Could not add intersection result geometry to layer due to incompatibility: " + intersection); } } pm.worked(1); } pm.done(); }
Example 19
Source File: GeometryDataSetGenerator.java From geowave with Apache License 2.0 | 4 votes |
public List<SimpleFeature> generatePointSet( final double minCenterDistanceFactor, final double outlierFactor, final int numberOfCenters, final int minSetSize, final double[] minAxis, final double[] maxAxis) { final List<SimpleFeature> pointSet = new ArrayList<>(); final List<double[]> minForCenter = new ArrayList<>(); final List<double[]> maxForCenter = new ArrayList<>(); final double[] range = createRange(minCenterDistanceFactor, minAxis, maxAxis); if (numberOfCenters >= minSetSize) { LOGGER.error("The number of centers passed much be less than the minimum set size"); throw new IllegalArgumentException( "The number of centers passed much be less than the minimum set size"); } final double minDistance = computeMinDistance(minCenterDistanceFactor, minAxis, maxAxis); /** Pick the initial centers which have minimum distance from each other. */ while (pointSet.size() < numberOfCenters) { final Pair<double[], double[]> axis = gridCellBounds(minCenterDistanceFactor, minAxis, maxAxis); final SimpleFeature nextFeature = createNewFeature(axis.getLeft(), axis.getRight()); if (isFarEnough(nextFeature, pointSet, minDistance)) { pointSet.add(nextFeature); } } /** * Calculate the boundaries around each center point to place additional points, thus creating * clusters */ for (final SimpleFeature center : pointSet) { final double[] centerMinAxis = new double[coordSystem.getDimension()]; final double[] centerMaxAxis = new double[coordSystem.getDimension()]; final Geometry geo = (Geometry) center.getDefaultGeometry(); final Coordinate centerCoord = geo.getCentroid().getCoordinate(); for (int i = 0; i < centerMinAxis.length; i++) { centerMinAxis[i] = centerCoord.getOrdinate(i) - (range[i] / 2.0); centerMaxAxis[i] = centerCoord.getOrdinate(i) + (range[i] / 2.0); } minForCenter.add(centerMinAxis); maxForCenter.add(centerMaxAxis); } /* * Pick a random center point and add a new geometry with the bounding range around that point. */ final int clusterdItemsCount = (int) Math.ceil((minSetSize) * (1.0 - outlierFactor)); while (pointSet.size() < clusterdItemsCount) { // HP Fortify "Insecure Randomness" false positive // This random number is not used for any purpose // related to security or cryptography final int centerPos = rand.nextInt(Integer.MAX_VALUE) % minForCenter.size(); pointSet.add(createNewFeature(minForCenter.get(centerPos), maxForCenter.get(centerPos))); } /** Add random points as potential outliers (no guarantees) */ while (pointSet.size() < minSetSize) { pointSet.add(createNewFeature(minAxis, maxAxis)); } return pointSet; }
Example 20
Source File: OmsMeltonNumber.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inElev, inFans); RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inElev); int cols = regionMap.getCols(); int rows = regionMap.getRows(); double west = regionMap.getWest(); double east = regionMap.getEast(); double south = regionMap.getSouth(); double north = regionMap.getNorth(); AttributeType type = inFans.getSchema().getType(fId); if (type == null) { throw new ModelsIllegalargumentException(MessageFormat.format("The attribute {0} does not exist in the vector map.", fId), this, pm); } List<SimpleFeature> fansList = FeatureUtilities.featureCollectionToList(inFans); outMelton = new String[fansList.size()][2]; int index = 0; pm.beginTask("Calculating Melton number for fans...", fansList.size()); for( SimpleFeature fan : fansList ) { Object attribute = fan.getAttribute(fId); // rasterize the fan DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); newCollection.add(fan); OmsScanLineRasterizer rasterizer = new OmsScanLineRasterizer(); rasterizer.inVector = newCollection; rasterizer.pCols = cols; rasterizer.pRows = rows; rasterizer.pNorth = north; rasterizer.pSouth = south; rasterizer.pEast = east; rasterizer.pWest = west; rasterizer.pValue = 1.0; rasterizer.pm = new DummyProgressMonitor(); rasterizer.process(); GridCoverage2D rasterizedFan = rasterizer.outRaster; GridCoverage2D fanElev = CoverageUtilities.coverageValuesMapper(inElev, rasterizedFan); // extract min and max OmsRasterSummary summary = new OmsRasterSummary(); summary.pm = new DummyProgressMonitor(); summary.inRaster = fanElev; summary.process(); double min = summary.outMin; double max = summary.outMax; // get the suface of the fan Geometry geometry = (Geometry) fan.getDefaultGeometry(); double area = geometry.getArea(); // calculate Melton double melton = (max - min) / sqrt(area); outMelton[index][0] = attribute.toString(); outMelton[index][1] = String.valueOf(melton); index++; pm.message(MessageFormat.format("id: {0} gave Melton number: {1}", attribute.toString(), melton)); pm.message("Based on max: " + max + " min: " + min + " and area: " + area); pm.worked(1); } pm.done(); }