Java Code Examples for org.geotools.feature.DefaultFeatureCollection#add()
The following examples show how to use
org.geotools.feature.DefaultFeatureCollection#add() .
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: IFeatureShape.java From hortonmachine with GNU General Public License v3.0 | 7 votes |
/** * Add a feature to the store. * * @param feature the feature to add. */ default public void addFeature( SimpleFeature feature) { FeatureStoreInfo featureStoreInfo = getFeatureStoreInfo(); SimpleFeatureStore featureStore = featureStoreInfo.getFeatureStore(); if (featureStore != null) { Transaction transaction = new DefaultTransaction("add"); featureStore.setTransaction(transaction); try { DefaultFeatureCollection fc = new DefaultFeatureCollection(); fc.add(feature); featureStore.addFeatures(fc); transaction.commit(); } catch (Exception eek) { try { transaction.rollback(); } catch (IOException e) { e.printStackTrace(); } } } }
Example 2
Source File: TinHandler.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
public SimpleFeatureCollection toFeatureCollectionTinPoints() { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("points"); b.setCRS(crs); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); b.add("the_geom", Point.class); b.add("elev", Double.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); for( Coordinate c : tinCoordinateList ) { Object[] values = new Object[]{gf.createPoint(c), c.z}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); newCollection.add(feature); } return newCollection; }
Example 3
Source File: GeoMesaGeoIndexer.java From rya with Apache License 2.0 | 6 votes |
@Override public void storeStatements(final Collection<RyaStatement> ryaStatements) throws IOException { // create a feature collection final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); for (final RyaStatement ryaStatement : ryaStatements) { final Statement statement = RyaToRdfConversions.convertStatement(ryaStatement); // if the predicate list is empty, accept all predicates. // Otherwise, make sure the predicate is on the "valid" list final boolean isValidPredicate = validPredicates.isEmpty() || validPredicates.contains(statement.getPredicate()); if (isValidPredicate && (statement.getObject() instanceof Literal)) { try { final SimpleFeature feature = createFeature(featureType, statement); featureCollection.add(feature); } catch (final ParseException e) { logger.warn("Error getting geo from statement: " + statement.toString(), e); } } } // write this feature collection to the store if (!featureCollection.isEmpty()) { featureStore.addFeatures(featureCollection); } }
Example 4
Source File: OmsLW04_BankfullWidthAnalyzer.java From hortonmachine with GNU General Public License v3.0 | 6 votes |
private DefaultFeatureCollection getNetworkPoints( CoordinateReferenceSystem crs, LinkedHashMap<SimpleFeature, double[]> validPointsMap ) throws Exception { FeatureExtender ext = null; DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); Set<Entry<SimpleFeature, double[]>> entrySet = validPointsMap.entrySet(); for( Entry<SimpleFeature, double[]> entry : entrySet ) { SimpleFeature pointFeature = entry.getKey(); if (ext == null) { ext = new FeatureExtender(pointFeature.getFeatureType(), new String[]{WIDTH, WIDTH_FROM}, new Class[]{Double.class, Double.class}); } double[] attributes = entry.getValue(); Object[] attrObj = new Object[attributes.length]; for( int i = 0; i < attrObj.length; i++ ) { attrObj[i] = attributes[i]; } SimpleFeature extendedFeature = ext.extendFeature(pointFeature, attrObj); newCollection.add(extendedFeature); } return newCollection; }
Example 5
Source File: FeatureUtilities.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Create a featurecollection from a vector of features * * @param features - the vectore of features * @return the created featurecollection */ public static SimpleFeatureCollection createFeatureCollection( SimpleFeature... features ) { DefaultFeatureCollection fcollection = new DefaultFeatureCollection(); for( SimpleFeature feature : features ) { fcollection.add(feature); } return fcollection; }
Example 6
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 7
Source File: TestLineSmootherJaitools.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorReader() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", LineString.class); b.add("id", Integer.class); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); SimpleFeatureType type = b.buildFeatureType(); Geometry line = new WKTReader().read("LINESTRING (0 0, 1 1, 2 0)");//2 2, 3 3, 4 4, 5 3, 6 2, 7 1, 8 0)"); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Object[] values = new Object[]{line, 0}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0"); newCollection.add(feature); OmsLineSmootherJaitools smoother = new OmsLineSmootherJaitools(); smoother.inVector = newCollection; smoother.pAlpha = 1; smoother.process(); SimpleFeatureCollection outFeatures = smoother.outVector; List<Geometry> geomList = FeatureUtilities.featureCollectionToGeometriesList(outFeatures, false, null); Geometry geometry = geomList.get(0); int newLength = geometry.getCoordinates().length; Geometry densifiedline = new WKTReader() .read("LINESTRING (0 0, 0.0342935528120713 0.0342935528120713, 0.1262002743484225 0.1262002743484225, 0.2592592592592592 0.2592592592592592, 0.4170096021947873 0.4170096021947873, 0.5829903978052127 0.5829903978052127, 0.7407407407407407 0.7407407407407407, 0.8737997256515775 0.8737997256515775, 0.9657064471879286 0.9657064471879286, 1 1, 1.0342935528120714 0.9657064471879288, 1.1262002743484225 0.8737997256515775, 1.2592592592592593 0.7407407407407408, 1.4170096021947873 0.5829903978052127, 1.5829903978052127 0.4170096021947874, 1.7407407407407407 0.2592592592592593, 1.8737997256515775 0.1262002743484225, 1.9657064471879289 0.0342935528120714, 2 0)"); int expectedLength = densifiedline.getCoordinates().length; assertEquals(expectedLength, newLength); }
Example 8
Source File: LasUtils.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Dump an overview shapefile for a las folder. * * @param folder the folder. * @param crs the crs to use. * @throws Exception */ public static void dumpLasFolderOverview( String folder, CoordinateReferenceSystem crs ) throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("overview"); b.setCRS(crs); b.add("the_geom", Polygon.class); b.add("name", String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); OmsFileIterator iter = new OmsFileIterator(); iter.inFolder = folder; iter.fileFilter = new FileFilter(){ public boolean accept( File pathname ) { return pathname.getName().endsWith(".las"); } }; iter.process(); List<File> filesList = iter.filesList; for( File file : filesList ) { try (ALasReader r = new LasReaderBuffered(file, crs)) { r.open(); ReferencedEnvelope3D envelope = r.getHeader().getDataEnvelope(); Polygon polygon = GeometryUtilities.createPolygonFromEnvelope(envelope); Object[] objs = new Object[]{polygon, r.getLasFile().getName()}; builder.addAll(objs); SimpleFeature feature = builder.buildFeature(null); newCollection.add(feature); } } File folderFile = new File(folder); File outFile = new File(folder, "overview_" + folderFile.getName() + ".shp"); OmsVectorWriter.writeVector(outFile.getAbsolutePath(), newCollection); }
Example 9
Source File: TestLineSmootherMcMaster.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorReader() throws Exception { SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("test"); b.setCRS(DefaultGeographicCRS.WGS84); b.add("the_geom", LineString.class); b.add("id", Integer.class); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); SimpleFeatureType type = b.buildFeatureType(); Geometry line = new WKTReader().read("LINESTRING (0 0, 1 1, 2 2, 3 3, 4 4, 5 3, 6 2, 7 1, 8 0)"); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Object[] values = new Object[]{line, 0}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0"); newCollection.add(feature); OmsLineSmootherMcMaster smoother = new OmsLineSmootherMcMaster(); smoother.inVector = newCollection; smoother.pLookahead = 3; smoother.pSlide = 0.9; smoother.pDensify = 0.9; smoother.process(); SimpleFeatureCollection outFeatures = smoother.outVector; List<Geometry> geomList = FeatureUtilities.featureCollectionToGeometriesList(outFeatures, false, null); Geometry geometry = geomList.get(0); int newLength = geometry.getCoordinates().length; Geometry densifiedline = new WKTReader() .read("LINESTRING (0 0, 0.5 0.5, 1 1, 1.5 1.5, 2 2, 2.5 2.5, 3 3, 3.5 3.5, 4 4, 4.5 3.5, 5 3, 5.5 2.5, 6 2, 6.5 1.5, 7 1, 7.5 0.5, 8 0)"); int expectedLength = densifiedline.getCoordinates().length; assertEquals(expectedLength, newLength); }
Example 10
Source File: TestVectorTableJoiner.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
public void testVectorTableJoiner() 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(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); Point point = GeometryUtilities.gf().createPoint(new Coordinate(0, 0)); Object[] values = new Object[]{point, 1}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(type.getTypeName() + ".0"); newCollection.add(feature); HashMap<String, List<Object>> tabledata = new HashMap<String, List<Object>>(); List<Object> id = Arrays.asList(new Object[]{1}); tabledata.put("id", id); List<Object> area = Arrays.asList(new Object[]{123.45}); tabledata.put("area", area); List<Object> area2 = Arrays.asList(new Object[]{67.89}); tabledata.put("area2", area2); OmsVectorTableJoiner joiner = new OmsVectorTableJoiner(); joiner.inVector = newCollection; joiner.tabledata = tabledata; joiner.fCommon = "id"; joiner.pFields = "area"; joiner.process(); SimpleFeatureCollection outFeatures = joiner.outVector; SimpleFeature f = FeatureUtilities.featureCollectionToList(outFeatures).get(0); String areaStr = f.getAttribute("area").toString(); assertTrue(areaStr.equals("123.45")); }
Example 11
Source File: OmsGeopaparazzi4Converter.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Convert the logs to a featurecollection. * * @param pm the monitor. * @param logsList the list of logs as gathered from {@link #getGpsLogsList(IHMConnection)}. * @return the extracted collection. * @throws Exception */ public static DefaultFeatureCollection getLogLinesFeatureCollection( IHMProgressMonitor pm, List<GpsLog> logsList ) { GeometryFactory gf = GeometryUtilities.gf(); SimpleFeatureType featureType = GeopaparazziUtilities.getGpsLogLinesFeatureType(); pm.beginTask("Import gps to lines...", logsList.size()); DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); for( GpsLog log : logsList ) { List<GpsPoint> points = log.points; List<Coordinate> coordList = new ArrayList<>(); String startDate = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(log.startTime)); String endDate = ETimeUtilities.INSTANCE.TIME_FORMATTER_LOCAL.format(new Date(log.endTime)); for( GpsPoint gpsPoint : points ) { Coordinate c = new Coordinate(gpsPoint.lon, gpsPoint.lat); coordList.add(c); } Coordinate[] coordArray = coordList.toArray(new Coordinate[coordList.size()]); if (coordArray.length < 2) { continue; } LineString lineString = gf.createLineString(coordArray); MultiLineString multiLineString = gf.createMultiLineString(new LineString[]{lineString}); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(featureType); Object[] values = new Object[]{multiLineString, startDate, endDate, log.text}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); newCollection.add(feature); pm.worked(1); } pm.done(); return newCollection; }
Example 12
Source File: MonitoringPoint.java From hortonmachine with GNU General Public License v3.0 | 5 votes |
/** * Create a featurecollection from a list of monitoringpoints. Based on the position of the * points and some of their attributes. * * @param monitoringPointsList * @return the featurecollection */ public SimpleFeatureCollection toFeatureCollection( List<MonitoringPoint> monitoringPointsList ) { // create the feature type SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); // set the name b.setName("monitoringpoints"); // add a geometry property b.add("the_geom", Point.class); // add some properties b.add("id", Integer.class); b.add("relatedid", Integer.class); b.add("pfaf", String.class); // build the type SimpleFeatureType type = b.buildFeatureType(); // create the feature SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); GeometryFactory gF = new GeometryFactory(); /* * insert them in inverse order to get them out of the collection in the same order as the * list */ DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); for( int i = 0; i < monitoringPointsList.size(); i++ ) { MonitoringPoint mp = monitoringPointsList.get(monitoringPointsList.size() - i - 1); Object[] values = new Object[]{gF.createPoint(mp.getPosition()), mp.getID(), mp.getRelatedID(), mp.getPfatstetterNumber().toString()}; // add the values builder.addAll(values); // build the feature with provided ID SimpleFeature feature = builder.buildFeature(type.getTypeName() + "." + i); newCollection.add(feature); } return newCollection; }
Example 13
Source File: Shape.java From constellation with Apache License 2.0 | 4 votes |
/** * Construct geojson to represent a single shape given a list of * coordinates, a desired shape type and a unique identifier. * * @param uuid a unique identifier for the shape * @param type a type of shape * @param coordinates a list of coordinate tuples of the form (longitude, * latitude) from which to build the shape * @return a geojson string representing a single shape * @throws IOException there was a problem writing the generated shape */ public static String generateShape(final String uuid, final GeometryType type, final List<Tuple<Double, Double>> coordinates) throws IOException { // build precision formatter final StringBuilder precisionPattern = new StringBuilder("#."); for (int decimalPlace = 0; decimalPlace < GEOMETRY_PRECISION; decimalPlace++) { precisionPattern.append("#"); } final DecimalFormat precisionFormat = new DecimalFormat(precisionPattern.toString()); precisionFormat.setRoundingMode(RoundingMode.CEILING); // calculate geometry final double centroidLongitude = coordinates.stream().mapToDouble(coordinate -> coordinate.getFirst()).reduce((lon1, lon2) -> lon1 + lon2).getAsDouble() / coordinates.size(); final double centroidLatitude = coordinates.stream().mapToDouble(coordinate -> coordinate.getSecond()).reduce((lat1, lat2) -> lat1 + lat2).getAsDouble() / coordinates.size(); final double errorLongitude = coordinates.stream().mapToDouble(coordinate -> Math.abs(centroidLongitude - coordinate.getFirst())).max().getAsDouble(); final double errorLatitude = coordinates.stream().mapToDouble(coordinate -> Math.abs(centroidLatitude - coordinate.getSecond())).max().getAsDouble(); final double minLongitude = centroidLongitude - errorLongitude; final double minLatitude = centroidLatitude - errorLatitude; final double maxLongitude = centroidLongitude + errorLongitude; final double maxLatitude = centroidLatitude + errorLatitude; final double radius = Math.max(errorLatitude, errorLongitude); // build geometry final GeometryBuilder geometryBuilder = new GeometryBuilder(); final Geometry geometry; switch (type) { case POINT: geometry = geometryBuilder.point(centroidLongitude, centroidLatitude); break; case LINE: geometry = geometryBuilder.lineString(coordinates.stream() .flatMap(Tuple::stream) .mapToDouble(coordinate -> (Double) coordinate) .toArray()); break; case POLYGON: geometry = geometryBuilder.polygon(coordinates.stream() .flatMap(Tuple::stream) .mapToDouble(coordinate -> (Double) coordinate) .toArray()); break; case BOX: final List<Tuple<Double, Double>> boxCoordinates = new ArrayList<>(); boxCoordinates.add(Tuple.create(minLongitude, minLatitude)); boxCoordinates.add(Tuple.create(minLongitude, maxLatitude)); boxCoordinates.add(Tuple.create(maxLongitude, maxLatitude)); boxCoordinates.add(Tuple.create(maxLongitude, minLatitude)); geometry = geometryBuilder.polygon(boxCoordinates.stream() .flatMap(Tuple::stream) .mapToDouble(coordinate -> (Double) coordinate) .toArray()); break; default: throw new IllegalArgumentException(String.format("The specified shape type, %s, is not currently supported.", type)); } // initialise json final String wgs84; try { wgs84 = SpatialReference.WGS84.getSrs(); } catch (final FactoryException ex) { throw new IOException(ex); } final SimpleFeatureType featureType = generateFeatureType(uuid, wgs84, DEFAULT_GEOMETRY_ATTRIBUTE, type.getGeomertyClass(), null); final FeatureJSON featureJson = generateFeatureJson(featureType, false); // build feature final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(featureType); featureBuilder.add(geometry); featureBuilder.set(NAME_ATTRIBUTE, uuid); featureBuilder.set(CENTROID_LATITUDE_ATTRIBUTE, precisionFormat.format(centroidLatitude)); featureBuilder.set(CENTROID_LONGITUDE_ATTRIBUTE, precisionFormat.format(centroidLongitude)); featureBuilder.set(RADIUS_ATTRIBUTE, precisionFormat.format(radius)); final SimpleFeature feature = featureBuilder.buildFeature(uuid); final DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(uuid, featureType); featureCollection.add(feature); // build json final ByteArrayOutputStream output = new ByteArrayOutputStream(); featureJson.writeFeatureCollection(featureCollection, output); return output.toString(StandardCharsets.UTF_8.name()); }
Example 14
Source File: OmsLW03_NetworkHierarchyToPointsSplitter.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inNet); if (pGauklerStrickler < 10) { throw new ModelsIllegalargumentException("KS can't be negative.", this); } // Creates the list of contained features List<SimpleFeature> netList = FeatureUtilities.featureCollectionToList(inNet); // Creates the output feature collection DefaultFeatureCollection outNetPointsFC = new DefaultFeatureCollection(); // Creates the structure of the output point layer SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("net"); b.setCRS(inNet.getBounds().getCoordinateReferenceSystem()); b.add("the_geom", Point.class); b.add(PFAF, String.class); b.add(LINKID, Integer.class); b.add(GAUKLER, Double.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); /*for each line generates the points geometries of the contained * vertexes with attributes -> it is assumed that the input network is * the output of the tool NetworkAttributesBuilder */ for( SimpleFeature netLineFeature : netList ) { int count = 1; Object pfaf = netLineFeature.getAttribute(PFAF); Geometry netLine = (Geometry) netLineFeature.getDefaultGeometry(); for( int i = 0; i < netLine.getNumGeometries(); i++ ) { LineString net = (LineString) netLine.getGeometryN(i); Coordinate[] coordinates = net.getCoordinates(); for( int j = 0; j < coordinates.length - 1; j++ ) { Point point = gf.createPoint(coordinates[j]); Object[] values = new Object[]{point, pfaf, count, pGauklerStrickler}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); outNetPointsFC.add(feature); count++; } } } outNetPoints = outNetPointsFC; }
Example 15
Source File: TmsShpGenerator.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public static void main( String[] args ) throws Exception { String EPSG_MERCATOR = "EPSG:3857"; CoordinateReferenceSystem mercatorCrs = CrsUtilities.getCrsFromEpsg(EPSG_MERCATOR, null); double w = -180; double e = 180; double s = -90; double n = 90; int pMinzoom = 1; int pMaxzoom = 7; String folder = "/home/moovida/TMP/AAAAAAAAA_BM/mappe_x_android/outtiles/shps/"; GlobalMercator mercator = new GlobalMercator(); for( int z = pMinzoom; z <= pMaxzoom; z++ ) { DefaultFeatureCollection newCollection = new DefaultFeatureCollection(); // List<Geometry> g = new ArrayList<Geometry>(); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("typename"); b.setCRS(mercatorCrs); b.add("the_geom", Polygon.class); b.add("tms", String.class); b.add("google", String.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); // get ul and lr tile number in GOOGLE tiles int[] llTileXY = mercator.GoogleTile(s, w, z); int[] urTileXY = mercator.GoogleTile(n, e, z); int startXTile = Math.min(llTileXY[0], urTileXY[0]); int endXTile = Math.max(llTileXY[0], urTileXY[0]); int startYTile = Math.min(llTileXY[1], urTileXY[1]); int endYTile = Math.max(llTileXY[1], urTileXY[1]); for( int i = startXTile; i <= endXTile; i++ ) { for( int j = startYTile; j <= endYTile; j++ ) { double[] bounds = mercator.TileBounds(i, j, z); double west = bounds[0]; double south = bounds[1]; double east = bounds[2]; double north = bounds[3]; Coordinate c1 = new Coordinate(west, south); Coordinate c2 = new Coordinate(west, north); Coordinate c3 = new Coordinate(east, north); Coordinate c4 = new Coordinate(east, south); Coordinate c5 = new Coordinate(west, south); Coordinate[] c = {c1, c2, c3, c4, c5}; Polygon p = gf.createPolygon(gf.createLinearRing(c), null); String google = z + "/" + i + "/" + j; int[] tmsTile = mercator.TMSTileFromGoogleTile(i, j, z); String tms = z + "/" + tmsTile[0] + "/" + tmsTile[1]; Object[] values = new Object[]{p, google, tms}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); newCollection.add(feature); } } String name = "tiles_" + z + ".shp"; OmsVectorWriter.writeVector(folder + name, newCollection); } }
Example 16
Source File: OmsHoughCirclesRaster.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
@Execute public void process() throws Exception { checkNull(inRaster, pMinRadius, pMaxRadius, pRadiusIncrement); if (pColorNv != null) { colorNv = pColorNv; useColorNv = true; } RegionMap regionMap = CoverageUtilities.getRegionParamsFromGridCoverage(inRaster); offx = 0; offy = 0; width = regionMap.getCols(); height = regionMap.getRows(); offset = width; xRes = regionMap.getXres(); radiusMinPixel = (int) round(width * pMinRadius / (regionMap.getEast() - regionMap.getWest())); radiusMaxPixel = (int) round(width * pMaxRadius / (regionMap.getEast() - regionMap.getWest()));; radiusIncPixel = (int) round(width * pRadiusIncrement / (regionMap.getEast() - regionMap.getWest())); if (radiusIncPixel < 1) { radiusIncPixel = 1; } maxCircles = pMaxCircleCount; depth = ((radiusMaxPixel - radiusMinPixel) / radiusIncPixel) + 1; Geometry[] circles = getCircles(); SimpleFeatureTypeBuilder b = new SimpleFeatureTypeBuilder(); b.setName("houghcircles"); b.setCRS(inRaster.getCoordinateReferenceSystem()); b.add("the_geom", Polygon.class); b.add("value", Double.class); SimpleFeatureType type = b.buildFeatureType(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(type); DefaultFeatureCollection outFC = new DefaultFeatureCollection(); for( Geometry geometry : circles ) { Object[] values = new Object[]{geometry, referenceImageValue}; builder.addAll(values); SimpleFeature feature = builder.buildFeature(null); outFC.add(feature); } outCircles = outFC; }
Example 17
Source File: OmsTrentoPProjectFilesGenerator.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
private SimpleFeatureCollection createNewCollection( SimpleFeatureType simpleFeatureType ) { DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); SimpleFeatureIterator stationsIter = pOldVector.features(); SimpleFeatureBuilder builder = new SimpleFeatureBuilder(simpleFeatureType); // create the features. try { while( stationsIter.hasNext() ) { SimpleFeature networkFeature = stationsIter.next(); try { // add the geometry. builder.add(networkFeature.getDefaultGeometry()); // add the ID. Integer field = ((Integer) networkFeature.getAttribute(TrentoPFeatureType.ID_STR)); if (field == null) { throw new IllegalArgumentException(); } builder.add(field); // add the area. Double value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.DRAIN_AREA_STR)); if (value == null) { throw new IllegalArgumentException(); } builder.add(value); // add the percentage of the area which is dry. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.PERCENTAGE_OF_DRY_AREA)); builder.add(value); // the pipes elevation is the elevation of the // terrain minus the depth. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.DEPTH_INITIAL_PIPE_STR)); builder.add(value); // the pipes elevation is the elevation of the // terrain minus the depth. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.DEPTH_FINAL_PIPE_STR)); builder.add(value); // add the runoff coefficent. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.RUNOFF_COEFFICIENT_STR)); builder.add(value); // add the average residence time. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.AVERAGE_RESIDENCE_TIME_STR)); builder.add(value); // add the ks. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.KS_STR)); builder.add(value); // add the average slope. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.AVERAGE_SLOPE_STR)); builder.add(value); // add the diameters. value = ((Double) networkFeature.getAttribute(TrentoPFeatureType.DIAMETER_STR)); builder.add(value); // build the feature SimpleFeature feature = builder.buildFeature(null); featureCollection.add(feature); } catch (NullPointerException e) { throw new IllegalArgumentException(); } } } finally { stationsIter.close(); } return featureCollection; }
Example 18
Source File: DxfLINE.java From hortonmachine with GNU General Public License v3.0 | 4 votes |
public static DxfGroup readEntity( RandomAccessFile raf, DefaultFeatureCollection entities ) throws IOException { double x1 = Double.NaN, y1 = Double.NaN, z1 = Double.NaN; double x2 = Double.NaN, y2 = Double.NaN, z2 = Double.NaN; DxfGroup group; SimpleFeatureBuilder builder = new SimpleFeatureBuilder(DxfFile.DXF_LINESCHEMA); String layer = ""; String ltype = ""; Double elevation = new Double(0.0); Double thickness = new Double(0.0); Integer color = new Integer(256); String text = ""; Double text_height = new Double(0.0); String text_style = ""; while( null != (group = DxfGroup.readGroup(raf)) && group.getCode() != 0 ) { if (group.getCode() == 8) layer = group.getValue(); else if (group.getCode() == 6) ltype = group.getValue(); else if (group.getCode() == 39) thickness = new Double(group.getDoubleValue()); else if (group.getCode() == 62) color = new Integer(group.getIntValue()); else if (group.getCode() == 10) x1 = group.getDoubleValue(); else if (group.getCode() == 20) y1 = group.getDoubleValue(); else if (group.getCode() == 30) z1 = group.getDoubleValue(); else if (group.getCode() == 11) x2 = group.getDoubleValue(); else if (group.getCode() == 21) y2 = group.getDoubleValue(); else if (group.getCode() == 31) z2 = group.getDoubleValue(); else { } } if (!Double.isNaN(x1) && !Double.isNaN(y1) && !Double.isNaN(x2) && !Double.isNaN(y2)) { Object[] values = new Object[]{ gF.createLineString(new Coordinate[]{new Coordinate(x1, y1, z1), new Coordinate(x2, y2, z2)}), layer, ltype, elevation, thickness, color, text, text_height, text_style}; builder.addAll(values); StringBuilder featureId = new StringBuilder(); featureId.append(DxfFile.DXF_LINESCHEMA.getTypeName()); featureId.append("."); featureId.append(DxfFile.getNextFid()); SimpleFeature feature = builder.buildFeature(featureId.toString()); entities.add(feature); } return group; }
Example 19
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(); }
Example 20
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(); } }