Java Code Examples for org.opengis.feature.simple.SimpleFeature#setAttribute()
The following examples show how to use
org.opengis.feature.simple.SimpleFeature#setAttribute() .
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: BandFeatureIterator.java From geowave with Apache License 2.0 | 6 votes |
@Override public Iterator<SimpleFeature> apply(final SimpleFeature scene) { if (scene == null) { return Collections.emptyIterator(); } final String entityId = scene.getID(); final List<SimpleFeature> bands = new ArrayList<>(); for (final String bandId : scene.getAttribute( SceneFeatureIterator.BANDS_ATTRIBUTE_NAME).toString().split(";")) { final SimpleFeature band = featureBuilder.buildFeature(entityId + "_" + bandId); for (final Property property : scene.getProperties()) { band.setAttribute(property.getName(), property.getValue()); } band.setAttribute(BAND_ATTRIBUTE_NAME, bandId); bands.add(band); } return bands.iterator(); }
Example 2
Source File: FeatureNumericHistogramStaticticsTest.java From geowave with Apache License 2.0 | 6 votes |
private SimpleFeature create(final Double val) { final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors(); final Object[] defaults = new Object[descriptors.size()]; int p = 0; for (final AttributeDescriptor descriptor : descriptors) { defaults[p++] = descriptor.getDefaultValue(); } final SimpleFeature newFeature = SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString()); newFeature.setAttribute("pop", val); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", new Date()); newFeature.setAttribute("whennot", new Date()); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25))); return newFeature; }
Example 3
Source File: Network2ShapeFile.java From pt2matsim with GNU General Public License v2.0 | 6 votes |
public void convertNodes(String nodesOutputFile) { Collection<SimpleFeature> nodeFeatures = new ArrayList<>(); PointFeatureFactory pointFeatureFactory = new PointFeatureFactory.Builder() .setName("nodes") .setCrs(MGC.getCRS(crs)) .addAttribute("id", String.class) .addAttribute("inLinks", Double.class) .addAttribute("outLinks", Double.class) .create(); for(Node node : network.getNodes().values()) { SimpleFeature f = pointFeatureFactory.createPoint(MGC.coord2Coordinate(node.getCoord())); f.setAttribute("id", node.getId()); f.setAttribute("inLinks", node.getInLinks()); f.setAttribute("outLinks", node.getOutLinks()); nodeFeatures.add(f); } ShapeFileWriter.writeGeometries(nodeFeatures, nodesOutputFile); }
Example 4
Source File: InLineFeatureModel.java From sldeditor with GNU General Public License v3.0 | 6 votes |
/** * Sets the value at. * * @param aValue the a value * @param rowIndex the row index * @param columnIndex the column index */ @Override public void setValueAt(Object aValue, int rowIndex, int columnIndex) { if ((rowIndex < 0) || (rowIndex >= getRowCount())) { return; } if ((columnIndex < 0) || (columnIndex >= getColumnCount())) { return; } SimpleFeature feature = getFeature(rowIndex); if (feature != null) { feature.setAttribute(columnIndex, aValue); } if (parentObj != null) { parentObj.inlineFeatureUpdated(); } }
Example 5
Source File: FeatureHyperLogLogStaticticsTest.java From geowave with Apache License 2.0 | 6 votes |
private SimpleFeature create(final String pid, final Set<String> set) { final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors(); final Object[] defaults = new Object[descriptors.size()]; int p = 0; for (final AttributeDescriptor descriptor : descriptors) { defaults[p++] = descriptor.getDefaultValue(); } final SimpleFeature newFeature = SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString()); newFeature.setAttribute("pid", pid); set.add(pid); return newFeature; }
Example 6
Source File: WFSTemporalQueryTest.java From geowave with Apache License 2.0 | 5 votes |
public void populate() throws IOException, CQLException, ParseException { final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("start", DateUtilities.parseISO("2005-05-17T20:32:56Z")); newFeature.setAttribute("end", DateUtilities.parseISO("2005-05-19T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("start", DateUtilities.parseISO("2005-05-18T20:32:56Z")); newFeature.setAttribute("end", DateUtilities.parseISO("2005-05-20T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 27.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("start", DateUtilities.parseISO("2005-05-21T20:32:56Z")); newFeature.setAttribute("end", DateUtilities.parseISO("2005-05-22T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); }
Example 7
Source File: FeatureCountMinSketchStaticticsTest.java From geowave with Apache License 2.0 | 5 votes |
private SimpleFeature create(final String pid) { final List<AttributeDescriptor> descriptors = schema.getAttributeDescriptors(); final Object[] defaults = new Object[descriptors.size()]; int p = 0; for (final AttributeDescriptor descriptor : descriptors) { defaults[p++] = descriptor.getDefaultValue(); } final SimpleFeature newFeature = SimpleFeatureBuilder.build(schema, defaults, UUID.randomUUID().toString()); newFeature.setAttribute("pid", pid); return newFeature; }
Example 8
Source File: GeoToolsAttributesSubsetTest.java From geowave with Apache License 2.0 | 5 votes |
@Before public void setup() throws IOException, GeoWavePluginException, SchemaException { geotoolsDataStore = createDataStore(); type = DataUtilities.createType(typeName, typeSpec); geotoolsDataStore.createSchema(type); final Transaction transaction = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = geotoolsDataStore.getFeatureWriter(type.getTypeName(), transaction); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute( geometry_attribute, GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(41.25, 41.25))); newFeature.setAttribute(long_attribute, 1l); newFeature.setAttribute(string_attribute, "string1"); writer.write(); newFeature = writer.next(); newFeature.setAttribute( geometry_attribute, GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(41.5, 41.5))); newFeature.setAttribute(long_attribute, 2l); newFeature.setAttribute(string_attribute, "string2"); writer.write(); newFeature = writer.next(); newFeature.setAttribute( geometry_attribute, GeometryUtils.GEOMETRY_FACTORY.createPoint(new Coordinate(41.75, 41.75))); newFeature.setAttribute(long_attribute, 3l); newFeature.setAttribute(string_attribute, "string3"); writer.write(); writer.close(); transaction.commit(); transaction.close(); }
Example 9
Source File: GeoToolsLayerTest.java From geomajas-project-server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testUpdate() throws Exception { SimpleFeature f = (SimpleFeature) layer.read(LAYER_NAME + ".3"); // id always starts with layer id f.setAttribute("NAME", "Luxembourg2"); layer.update(f); Assert.assertEquals("Luxembourg2", f.getAttribute(ATTRIBUTE_NAME)); }
Example 10
Source File: GeoWaveFeatureSourceTest.java From geowave with Apache License 2.0 | 5 votes |
@Override public void populate(final SimpleFeatureType type, final DataStore dataStore) throws IOException, CQLException, ParseException { dataStore.createSchema(type); final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(77)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(66)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-18T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 27.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-17T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.242))); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); }
Example 11
Source File: WFSSpatialTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void test() throws IOException, CQLException, ParseException { final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T18:33:55Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25))); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T20:33:55Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25))); writer.write(); writer.close(); final FeatureReader<SimpleFeatureType, SimpleFeature> reader = dataStore.getFeatureReader(query, transaction1); assertTrue(reader.hasNext()); final SimpleFeature priorFeature = reader.next(); assertEquals(newFeature.getAttribute("pid"), priorFeature.getAttribute("pid")); assertFalse(reader.hasNext()); reader.close(); transaction1.commit(); transaction1.close(); }
Example 12
Source File: WFSBoundedSpatialQueryTest.java From geowave with Apache License 2.0 | 5 votes |
public void populate() throws IOException, CQLException, ParseException { final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-18T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 27.232))); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-17T20:32:56Z")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); }
Example 13
Source File: TemporalRangeTest.java From geowave with Apache License 2.0 | 5 votes |
@Test public void test() throws ParseException, IOException { final Calendar gmt = Calendar.getInstance(TimeZone.getTimeZone("GMT")); final Calendar local = Calendar.getInstance(TimeZone.getTimeZone("EDT")); local.setTimeInMillis(gmt.getTimeInMillis()); final TemporalRange rGmt = new TemporalRange(gmt.getTime(), gmt.getTime()); final TemporalRange rLocal = new TemporalRange(local.getTime(), local.getTime()); rGmt.fromBinary(rGmt.toBinary()); assertEquals(gmt.getTime(), rGmt.getEndTime()); assertEquals(rLocal.getEndTime(), rGmt.getEndTime()); assertEquals(rLocal.getEndTime().getTime(), rGmt.getEndTime().getTime()); final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); final SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(77)); newFeature.setAttribute("pid", UUID.randomUUID().toString()); newFeature.setAttribute("when", DateUtilities.parseISO("2005-05-19T19:32:56-04:00")); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(43.454, 28.232))); final FeatureTimeRangeStatistics stats = new FeatureTimeRangeStatistics(null, "when"); stats.entryIngested(newFeature); assertEquals( DateUtilities.parseISO("2005-05-19T23:32:56Z"), stats.asTemporalRange().getStartTime()); }
Example 14
Source File: CQLQueryFilterTest.java From geowave with Apache License 2.0 | 5 votes |
private SimpleFeature createFeature() { final SimpleFeature instance = SimpleFeatureBuilder.build(type, defaults, UUID.randomUUID().toString()); instance.setAttribute("pop", Long.valueOf(100)); instance.setAttribute("pid", "a89dhd-123-abc"); instance.setAttribute("geom", factory.createPoint(new Coordinate(27.25, 41.25))); return instance; }
Example 15
Source File: Schedule2ShapeFile.java From pt2matsim with GNU General Public License v2.0 | 5 votes |
/** * Converts reference links to polylines. */ public void stopRefLinks2Polylines(String outputFile) { Collection<SimpleFeature> lineFeatures = new ArrayList<>(); PolylineFeatureFactory polylineFeatureFactory = new PolylineFeatureFactory.Builder() .setName("StopFacilities") .setCrs(MGC.getCRS(crs)) .addAttribute("id", String.class) .addAttribute("name", String.class) .addAttribute("linkId", String.class) .addAttribute("postAreaId", String.class) .addAttribute("isBlocking", Boolean.class) .addAttribute("routes", String.class) .create(); for(TransitStopFacility stopFacility : schedule.getFacilities().values()) { if(stopFacility.getLinkId() != null) { Link refLink = network.getLinks().get(stopFacility.getLinkId()); Coordinate[] coordinates = new Coordinate[2]; try { coordinates[0] = MGC.coord2Coordinate(refLink.getFromNode().getCoord()); } catch (Exception e) { e.printStackTrace(); } coordinates[1] = MGC.coord2Coordinate(refLink.getToNode().getCoord()); SimpleFeature lf = polylineFeatureFactory.createPolyline(coordinates); lf.setAttribute("id", stopFacility.getId().toString()); lf.setAttribute("name", stopFacility.getName()); lf.setAttribute("linkId", stopFacility.getLinkId().toString()); lf.setAttribute("postAreaId", stopFacility.getStopAreaId()); lf.setAttribute("isBlocking", stopFacility.getIsBlockingLane()); lineFeatures.add(lf); } } ShapeFileWriter.writeGeometries(lineFeatures, outputFile); }
Example 16
Source File: ShapefileTool.java From geowave with Apache License 2.0 | 4 votes |
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings( value = "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE", justification = "Directories may alreadybe there") public static void writeShape(final String typeName, final File dir, final Geometry[] shapes) throws IOException { FileUtils.deleteDirectory(dir); dir.mkdirs(); final SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(createFeatureType(typeName, shapes[0] instanceof Point)); final ShapefileDataStoreFactory dataStoreFactory = new ShapefileDataStoreFactory(); final Map<String, Serializable> params = new HashMap<>(); params.put("url", new File(dir.getAbsolutePath() + "/" + typeName + ".shp").toURI().toURL()); params.put("create spatial index", Boolean.TRUE); final ShapefileDataStore newDataStore = (ShapefileDataStore) dataStoreFactory.createNewDataStore(params); newDataStore.createSchema(createFeatureType(typeName, shapes[0] instanceof Point)); final Transaction transaction = new DefaultTransaction("create"); try (final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriterAppend(typeName, transaction)) { final int i = 1; for (final Geometry shape : shapes) { featureBuilder.add(shape); featureBuilder.add(Integer.valueOf(i)); final SimpleFeature feature = featureBuilder.buildFeature(null); final SimpleFeature copy = writer.next(); for (final AttributeDescriptor attrD : feature.getFeatureType().getAttributeDescriptors()) { // the null case should only happen for geometry if (copy.getFeatureType().getDescriptor(attrD.getName()) != null) { copy.setAttribute(attrD.getName(), feature.getAttribute(attrD.getName())); } } // shape files force geometry name to be 'the_geom'. So isolate // this change copy.setDefaultGeometry(feature.getDefaultGeometry()); writer.write(); } } catch (final IOException e) { LOGGER.warn("Problem with the FeatureWritter", e); transaction.rollback(); } finally { transaction.commit(); transaction.close(); } }
Example 17
Source File: GeoWaveFeatureReaderTest.java From geowave with Apache License 2.0 | 4 votes |
@Before public void setup() throws SchemaException, CQLException, Exception { dataStore = createDataStore(); type = DataUtilities.createType( "GeoWaveFeatureReaderTest", "geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String"); ((GeoWaveGTDataStore) dataStore).getIndexStore().addIndex( new SpatialIndexBuilder().createIndex()); ((GeoWaveGTDataStore) dataStore).getIndexStore().addIndex( new SpatialTemporalIndexBuilder().createIndex()); dataStore.createSchema(type); stime = DateUtilities.parseISO("2005-05-15T20:32:56Z"); mtime = DateUtilities.parseISO("2005-05-20T20:32:56Z"); etime = DateUtilities.parseISO("2005-05-25T20:32:56Z"); final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter(type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(100)); newFeature.setAttribute("pid", "a" + UUID.randomUUID().toString()); newFeature.setAttribute("start", stime); newFeature.setAttribute("end", mtime); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(27.25, 41.25))); fids.add(newFeature.getID()); pids.add(newFeature.getAttribute("pid").toString()); writer.write(); newFeature = writer.next(); newFeature.setAttribute("pop", Long.valueOf(101)); newFeature.setAttribute("pid", "b" + UUID.randomUUID().toString()); newFeature.setAttribute("start", mtime); newFeature.setAttribute("end", etime); newFeature.setAttribute("geometry", factory.createPoint(new Coordinate(28.25, 41.25))); fids.add(newFeature.getID()); pids.add(newFeature.getAttribute("pid").toString()); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); query = new Query( "GeoWaveFeatureReaderTest", ECQL.toFilter("IN ('" + fids.get(0) + "')"), new String[] {"geometry", "pid"}); }
Example 18
Source File: GeoWaveFeatureReaderTest.java From rya with Apache License 2.0 | 4 votes |
@Before public void setup() throws SchemaException, CQLException, Exception { setupConf(); try (final GeoWaveGeoIndexer indexer = new GeoWaveGeoIndexer()) { indexer.setConf(conf); dataStore = indexer.getGeoToolsDataStore(); // Clear old data indexer.purge(conf); type = DataUtilities.createType( "GeoWaveFeatureReaderTest", "geometry:Geometry:srid=4326,start:Date,end:Date,pop:java.lang.Long,pid:String"); dataStore.createSchema(type); stime = DateUtilities.parseISO("2005-05-15T20:32:56Z"); etime = DateUtilities.parseISO("2005-05-20T20:32:56Z"); final Transaction transaction1 = new DefaultTransaction(); final FeatureWriter<SimpleFeatureType, SimpleFeature> writer = dataStore.getFeatureWriter( type.getTypeName(), transaction1); assertFalse(writer.hasNext()); SimpleFeature newFeature = writer.next(); newFeature.setAttribute( "pop", Long.valueOf(100)); newFeature.setAttribute( "pid", "a" + UUID.randomUUID().toString()); newFeature.setAttribute( "start", stime); newFeature.setAttribute( "end", etime); newFeature.setAttribute( "geometry", factory.createPoint(new Coordinate(27.25, 41.25))); fids.add(newFeature.getID()); pids.add(newFeature.getAttribute("pid").toString()); writer.write(); newFeature = writer.next(); newFeature.setAttribute( "pop", Long.valueOf(101)); newFeature.setAttribute( "pid", "b" + UUID.randomUUID().toString()); newFeature.setAttribute( "start", etime); newFeature.setAttribute( "geometry", factory.createPoint(new Coordinate(28.25, 41.25))); fids.add(newFeature.getID()); pids.add(newFeature.getAttribute("pid").toString()); writer.write(); writer.close(); transaction1.commit(); transaction1.close(); query = new Query( "GeoWaveFeatureReaderTest", ECQL.toFilter("IN ('" + fids.get(0) + "')"), new String[] { "geometry", "pid" }); } }
Example 19
Source File: AnalyticFeature.java From geowave with Apache License 2.0 | 4 votes |
public static SimpleFeature createGeometryFeature( final SimpleFeatureType featureType, final String batchId, final String dataId, final String name, final String groupID, final double weight, final Geometry geometry, final String[] extraDimensionNames, final double[] extraDimensions, final int zoomLevel, final int iteration, final long count) { if (extraDimensionNames.length != extraDimensions.length) { LOGGER.error( "The number of extraDimension names does not equal the number of extraDimensions"); throw new IllegalArgumentException( "The number of extraDimension names does not equal the number of extraDimensions"); } final List<AttributeDescriptor> descriptors = featureType.getAttributeDescriptors(); final Object[] defaults = new Object[descriptors.size()]; int p = 0; for (final AttributeDescriptor descriptor : descriptors) { defaults[p++] = descriptor.getDefaultValue(); } final SimpleFeature newFeature = SimpleFeatureBuilder.build(featureType, defaults, dataId); newFeature.setAttribute(ClusterFeatureAttribute.NAME.attrName(), name); newFeature.setAttribute(ClusterFeatureAttribute.GROUP_ID.attrName(), groupID); newFeature.setAttribute(ClusterFeatureAttribute.ITERATION.attrName(), iteration); newFeature.setAttribute(ClusterFeatureAttribute.WEIGHT.attrName(), weight); newFeature.setAttribute(ClusterFeatureAttribute.BATCH_ID.attrName(), batchId); newFeature.setAttribute(ClusterFeatureAttribute.COUNT.attrName(), count); newFeature.setAttribute(ClusterFeatureAttribute.GEOMETRY.attrName(), geometry); newFeature.setAttribute(ClusterFeatureAttribute.ZOOM_LEVEL.attrName(), zoomLevel); int i = 0; for (final String dimName : extraDimensionNames) { newFeature.setAttribute(dimName, new Double(extraDimensions[i++])); } return newFeature; }
Example 20
Source File: Schedule2ShapeFile.java From pt2matsim with GNU General Public License v2.0 | 4 votes |
/** * Converts the transit routes to polylines */ public void routes2Polylines(String outputFile, boolean useNetworkLinks) { Collection<SimpleFeature> features = new ArrayList<>(); PolylineFeatureFactory ff = new PolylineFeatureFactory.Builder() .setName("TransitRoutes") .setCrs(MGC.getCRS(crs)) .addAttribute("line", String.class) .addAttribute("route", String.class) .addAttribute("mode", String.class) .addAttribute("simLength", Double.class) .addAttribute("descr", String.class) .create(); for(TransitLine transitLine : schedule.getTransitLines().values()) { for(TransitRoute transitRoute : transitLine.getRoutes().values()) { for(TransitRouteStop stop : transitRoute.getStops()) { MapUtils.getSet(stop.getStopFacility(), routesOnStopFacility).add(transitRoute.getId()); } Coordinate[] coordinates; double simLength = 0.0; if(useNetworkLinks) { coordinates = getCoordinatesFromRoute(transitRoute); if(coordinates == null) { log.warn("No links found for route " + transitRoute.getId() + " on line " + transitLine.getId()); } simLength = getRouteLength(transitRoute); } else { coordinates = getCoordinatesFromStopFacilities(transitRoute); } SimpleFeature f = ff.createPolyline(coordinates); f.setAttribute("line", transitLine.getId().toString()); f.setAttribute("route", transitRoute.getId().toString()); f.setAttribute("mode", transitRoute.getTransportMode()); f.setAttribute("descr", transitRoute.getDescription()); f.setAttribute("simLength", simLength); features.add(f); } } ShapeFileWriter.writeGeometries(features, outputFile); }