當前位置: 首頁>>代碼示例>>Java>>正文


Java SimpleFeature.setAttribute方法代碼示例

本文整理匯總了Java中org.opengis.feature.simple.SimpleFeature.setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java SimpleFeature.setAttribute方法的具體用法?Java SimpleFeature.setAttribute怎麽用?Java SimpleFeature.setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.opengis.feature.simple.SimpleFeature的用法示例。


在下文中一共展示了SimpleFeature.setAttribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
public void execute(Tuple tuple) {

        final String[] attributes = tuple.getValue(0).toString().split(",");

        // Only ingest attributes that have a latitude and longitude
        if (attributes.length == 2 && attributes[LATITUDE_COL_IDX] != null && attributes[LONGITUDE_COL_IDX] != null) {

            featureBuilder.reset();
            final SimpleFeature simpleFeature = featureBuilder.buildFeature(String.valueOf(UUID.randomUUID().getMostSignificantBits()));
            simpleFeature.setDefaultGeometry(getGeometry(attributes));

            try {
                final SimpleFeature next = featureWriter.next();
                for (int i = 0; i < simpleFeature.getAttributeCount(); i++) {
                    next.setAttribute(i, simpleFeature.getAttribute(i));
                }
                ((FeatureIdImpl)next.getIdentifier()).setID(simpleFeature.getID());
                featureWriter.write();
            } catch (IOException e) {
                log.error("Exception writing feature", e);
            }
        }
    }
 
開發者ID:geomesa,項目名稱:geomesa-tutorials,代碼行數:24,代碼來源:OSMKafkaBolt.java

示例2: convertNodes

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
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);
}
 
開發者ID:matsim-org,項目名稱:pt2matsim,代碼行數:21,代碼來源:Network2ShapeFile.java

示例3: setValueAt

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
/**
 * 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) {
        if (columnIndex == getGeometryFieldIndex()) {
            feature.setAttribute(columnIndex, aValue);
        } else {
            feature.setAttribute(columnIndex, aValue);
        }
    }

    if (parentObj != null) {
        parentObj.inlineFeatureUpdated();
    }
}
 
開發者ID:robward-scisys,項目名稱:sldeditor,代碼行數:32,代碼來源:InLineFeatureModel.java

示例4: writeESRIShapeFile

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
/**
 * Writes the given shapes to a shape file
 */
public static void writeESRIShapeFile(Collection<? extends RouteShape> shapes, String outputCoordinateSystem, String filename) {
	Collection<SimpleFeature> features = new ArrayList<>();

	PolylineFeatureFactory ff = new PolylineFeatureFactory.Builder()
			.setName("shape")
			.setCrs(MGC.getCRS(outputCoordinateSystem))
			.addAttribute("shape_id", String.class)
			.create();

	for(RouteShape shape : shapes) {
		if(shape != null) {
			Collection<Coord> points = shape.getCoordsSorted().values();
			int i = 0;
			Coordinate[] coordinates = new Coordinate[points.size()];
			for(Coord coord : points) {
				coordinates[i++] = MGC.coord2Coordinate(coord);
			}

			SimpleFeature f = ff.createPolyline(coordinates);
			f.setAttribute("shape_id", shape.getId());
			features.add(f);
		}
	}
	ShapeFileWriter.writeGeometries(features, filename);

}
 
開發者ID:matsim-org,項目名稱:pt2matsim,代碼行數:30,代碼來源:ShapeTools.java

示例5: stopRefLinks2Polylines

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
/**
 * 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.getStopPostAreaId());
			lf.setAttribute("isBlocking", stopFacility.getIsBlockingLane());
			lineFeatures.add(lf);
		}
	}

	ShapeFileWriter.writeGeometries(lineFeatures, outputFile);
}
 
開發者ID:matsim-org,項目名稱:pt2matsim,代碼行數:42,代碼來源:Schedule2ShapeFile.java

示例6: stopFacilities2Points

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
/**
 * Converts the stop facilities to points.
 */
public void stopFacilities2Points(String pointOutputFile) {
	Collection<SimpleFeature> pointFeatures = new ArrayList<>();

	PointFeatureFactory pointFeatureFactory = new PointFeatureFactory.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()) {

		SimpleFeature pf = pointFeatureFactory.createPoint(MGC.coord2Coordinate(stopFacility.getCoord()));
		pf.setAttribute("id", stopFacility.getId().toString());
		pf.setAttribute("name", stopFacility.getName());
		pf.setAttribute("postAreaId", stopFacility.getStopPostAreaId());
		pf.setAttribute("isBlocking", stopFacility.getIsBlockingLane());

		if(stopFacility.getLinkId() != null) pf.setAttribute("linkId", stopFacility.getLinkId().toString());

		if(routesOnStopFacility.get(stopFacility) != null) {
			pf.setAttribute("routes", CollectionUtils.idSetToString(routesOnStopFacility.get(stopFacility)));
		}
		pointFeatures.add(pf);
	}

	ShapeFileWriter.writeGeometries(pointFeatures, pointOutputFile);
}
 
開發者ID:matsim-org,項目名稱:pt2matsim,代碼行數:36,代碼來源:Schedule2ShapeFile.java

示例7: convertLinks

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
public void convertLinks(String linksOutputFile) {
	Collection<SimpleFeature> linkFeatures = new ArrayList<>();
	PolylineFeatureFactory linkFactory = new PolylineFeatureFactory.Builder()
			.setName("links")
			.setCrs(MGC.getCRS(crs))
			.addAttribute("id", String.class)
			.addAttribute("length", Double.class)
			.addAttribute("freespeed", Double.class)
			.addAttribute("capacity", Double.class)
			.addAttribute("lanes", Double.class)
			.addAttribute("modes", String.class)
			.addAttribute("fromNode", String.class)
			.addAttribute("toNode", String.class)
			.create();

	for(Link link : network.getLinks().values()) {
		SimpleFeature f = linkFactory.createPolyline(getCoordinates(link));
		f.setAttribute("id", link.getId());
		f.setAttribute("length", link.getLength());
		f.setAttribute("freespeed", link.getFreespeed());
		f.setAttribute("capacity", link.getCapacity());
		f.setAttribute("lanes", link.getNumberOfLanes());
		f.setAttribute("fromNode", link.getFromNode());
		f.setAttribute("toNode", link.getToNode());
		f.setAttribute("modes", CollectionUtils.setToString(link.getAllowedModes()));
		linkFeatures.add(f);
	}

	ShapeFileWriter.writeGeometries(linkFeatures, linksOutputFile);
}
 
開發者ID:matsim-org,項目名稱:pt2matsim,代碼行數:31,代碼來源:Network2ShapeFile.java

示例8: map

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
@Override
public void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, SimpleFeature>.Context context)
        throws IOException, InterruptedException {
    String[] attributes = value.toString().split("\\t", -1);
    if (attributes.length >= MINIMUM_NUM_FIELDS && !attributes[LATITUDE_COL_IDX].equals("") &&
        !attributes[LONGITUDE_COL_IDX].equals("")) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        try {
            featureBuilder.reset();

            Double lat = Double.parseDouble(attributes[LATITUDE_COL_IDX]);
            Double lon = Double.parseDouble(attributes[LONGITUDE_COL_IDX]);
            if (Math.abs(lat) > 90.0 || Math.abs(lon) > 180.0) {
                context.getCounter("com.example.geomesa", "invalid-geoms").increment(1);
            } else {
                Geometry geom = geometryFactory.createPoint(new Coordinate(lon, lat));
                SimpleFeature simpleFeature = featureBuilder.buildFeature(attributes[ID_COL_IDX]);
                int i = 0;
                while (i < attributes.length) {
                    simpleFeature.setAttribute(i, attributes[i]);
                    i++;
                }
                simpleFeature.setAttribute("SQLDATE", formatter.parse(attributes[DATE_COL_IDX]));
                simpleFeature.setDefaultGeometry(geom);

                context.write(new Text(), simpleFeature);
            }
        } catch (ParseException e) {
            context.getCounter("com.example.geomesa", "parse-errors").increment(1);
            e.printStackTrace();
        }
    } else {
        context.getCounter("com.example.geomesa", "invalid-lines").increment(1);
    }
}
 
開發者ID:geomesa,項目名稱:geomesa-tutorials,代碼行數:36,代碼來源:GDELTIngestMapper.java

示例9: updateFeature

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
public static void updateFeature(SimpleFeature feature) {
    Point point = (Point) feature.getDefaultGeometry();
    Double step = (Double) feature.getAttribute("step");

    Double newLong = nudgeLong(point.getX() + step);

    Geometry newPoint = WKTUtils$.MODULE$.read("POINT(" + newLong + " " + point.getY() + ")");

    feature.setAttribute("dtg", new Date());
    feature.setDefaultGeometry(newPoint);
}
 
開發者ID:geomesa,項目名稱:geomesa-tutorials,代碼行數:12,代碼來源:KafkaLoadTester.java

示例10: prepareOperations

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
/**
 * Filters operations and triggers the analysis
 */
private void prepareOperations(List<IVgiFeature> batch) {
	for (IVgiFeature feature : batch) {
		
		/** Filter by tag */
		if (!feature.filterByTag(settings.getFilterTag())) continue;
		
		if (settings.getCurrentPolygon() != null || settings.isWriteGeometryFiles()) {
			if (settings.getCurrentPolygon() != null) {
				if (!settings.getCurrentPolygon().getPolygon().getEnvelopeInternal().intersects(feature.getBBox())) continue;
			}
			
			SimpleFeature f = geometryAssemblerConsumer.assembleGeometry(feature, null);
			if (f == null) continue;
			
			if (((Geometry)f.getDefaultGeometry()).getGeometryType().equals("LineString")) {
				double length = GeomUtils.calculateLengthMeterFromWGS84LineStringAndoyer((LineString)f.getDefaultGeometry());
				f.setAttribute("length", length);
			}
			
			if (settings.getCurrentPolygon() != null) {
				Geometry geometry = (Geometry)f.getDefaultGeometry();
				if (geometry == null || geometry.disjoint(settings.getCurrentPolygon().getPolygon())) continue;					
			}
			
			if (settings.isWriteGeometryFiles()) {
				if (!mapFeatures.containsKey(f.getFeatureType())) mapFeatures.put(f.getFeatureType(), new DefaultFeatureCollection(f.getFeatureType().getTypeName(), f.getFeatureType()));
				if (!(boolean)f.getAttribute("deleted")) {
					mapFeatures.get(f.getFeatureType()).add(f);
				}
			}
		}
		
		featureList.add(feature);
	}
	
	analyzeFeatures();
}
 
開發者ID:SGroe,項目名稱:vgi-analytics-framework,代碼行數:41,代碼來源:VgiAnalysisConsumer.java

示例11: exportGeometriesToShapeFile

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
/**
 *
 * @param geoms
 * @param fileOutput
 * @param geomType
 * @param transform
 * @throws IOException
 * @throws SchemaException
 */
public static void exportGeometriesToShapeFile(final List<Geometry> geoms,
	 File fileOutput,String geomType,GeoTransform transform,
	 SimpleFeatureType featureType) throws IOException, SchemaException{

 FileDataStoreFactorySpi factory = new ShapefileDataStoreFactory();
 //Map map = Collections.singletonMap( "url", fileOutput.toURI().toURL() );
 DataStore data = factory.createDataStore( fileOutput.toURI().toURL() );
 boolean addAttr=true;
 if(featureType==null){
	 featureType=DataUtilities.createType( "the_geom", "geom:"+geomType+",name:String,age:Integer,description:String" );
	 addAttr=false;
 }
 data.createSchema( featureType );

 Transaction transaction = new DefaultTransaction();
    FeatureWriter<SimpleFeatureType, SimpleFeature> writer = data.getFeatureWriterAppend(data.getTypeNames()[0], transaction);

    SimpleFeatureBuilder featureBuilder=new SimpleFeatureBuilder(featureType);
    GeometryFactory gb=new GeometryFactory();
    try {
     int fid=0;
     for(final Geometry g:geoms){
    	 Geometry clone=gb.createGeometry(g);
    	 if(transform!=null)
    		 clone=transform.transformGeometryGeoFromPixel(clone);

    	 featureBuilder.add("the_geom");
    	 featureBuilder.add(clone);
    	 SimpleFeature sf=featureBuilder.buildFeature(""+fid++);
    	 SimpleFeature sfout=writer.next();
    	 sfout.setAttributes( sf.getAttributes() );
         //setting attributes geometry
       	 AttributesGeometry att=(AttributesGeometry) g.getUserData();
       	 try{
        	 if(att!=null&&addAttr){
         	 String sch[]=att.getSchema();
         	 for(int i=0;i<sch.length;i++){
         		 Object val=att.get(sch[i]);
         		 if(val.getClass().isArray()){
         			 Object o=ArrayUtils.toString(val);
         			 sfout.setAttribute(sch[i], o);
         		 }else{
         			 sfout.setAttribute(sch[i], val);
         		 }
         	 }
        	 }
       	 }catch(Exception e ){
       		 logger.warn("Error adding attributes to geometry:"+e.getMessage());
       	 }

         sfout.setDefaultGeometry( clone);
    	 writer.write();
	 }
     transaction.commit();
     logger.info("Export to shapefile complete:"+ fileOutput.getAbsolutePath());
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
        logger.error("Export to shapefile failed",problem );
    } finally {
        writer.close();
        transaction.close();
        data.dispose();
    }

}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:76,代碼來源:SimpleShapefile.java

示例12: writeGtfsTripsToFile

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
/**
 * Allows converting GTFS data to an ESRI shapefiles.
 */
@Deprecated
public static void writeGtfsTripsToFile(GtfsFeed gtfsFeed, Set<String> serviceIds, String outputCoordinateSystem, String outFile) {
	Collection<SimpleFeature> features = new ArrayList<>();

	PolylineFeatureFactory ff = new PolylineFeatureFactory.Builder()
			.setName("gtfs_shapes")
			.setCrs(MGC.getCRS(outputCoordinateSystem))
			.addAttribute("shape_id", String.class)
			.addAttribute("trip_id", String.class)
			.addAttribute("route_id", String.class)
			.addAttribute("route_name", String.class)
			.create();


	GtfsFeedImpl gtfs = (GtfsFeedImpl) gtfsFeed;

	for(Route gtfsRoute : gtfs.getRoutes().values()) {
		for(Trip trip : gtfsRoute.getTrips().values()) {
			boolean useTrip = false;
			if(serviceIds != null) {
				for(String serviceId : serviceIds) {
					if(trip.getService().getId().equals(serviceId)) {
						useTrip = true;
						break;
					}
				}
			} else {
				useTrip = true;
			}

			if(useTrip) {
				RouteShape shape = trip.getShape();
				if(shape != null) {

					Collection<Coord> points = shape.getCoordsSorted().values();
					int i = 0;
					Coordinate[] coordinates = new Coordinate[points.size()];
					for(Coord coord : points) {
						coordinates[i++] = MGC.coord2Coordinate(coord);
					}

					SimpleFeature f = ff.createPolyline(coordinates);
					f.setAttribute("shape_id", shape.getId());
					f.setAttribute("trip_id", trip.getId());
					f.setAttribute("route_id", gtfsRoute.getId());
					f.setAttribute("route_name", gtfsRoute.getShortName());
					features.add(f);
				}
			}
		}
	}
	ShapeFileWriter.writeGeometries(features, outFile);
}
 
開發者ID:matsim-org,項目名稱:pt2matsim,代碼行數:57,代碼來源:ShapeTools.java

示例13: routes2Polylines

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
/**
 * 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);
}
 
開發者ID:matsim-org,項目名稱:pt2matsim,代碼行數:48,代碼來源:Schedule2ShapeFile.java

示例14: createNewFeatures

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
static SimpleFeatureCollection createNewFeatures(SimpleFeatureType simpleFeatureType, int numNewFeatures) {
    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();

    String id;
    Object[] NO_VALUES = {};
    String[] PEOPLE_NAMES = {"Addams", "Bierce", "Clemens"};
    Long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L;
    Random random = new Random(5771);
    DateTime MIN_DATE = new DateTime(2014, 1, 1, 0, 0, 0, DateTimeZone.forID("UTC"));
    Double MIN_X = -78.0;
    Double MIN_Y = -39.0;
    Double DX = 2.0;
    Double DY = 2.0;

    for (int i = 0; i < numNewFeatures; i ++) {
        // create the new (unique) identifier and empty feature shell
        id = "Observation." + Integer.toString(i);
        SimpleFeature simpleFeature = SimpleFeatureBuilder.build(simpleFeatureType, NO_VALUES, id);

        // be sure to tell GeoTools explicitly that you want to use the ID you provided
        simpleFeature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);

        // populate the new feature's attributes

        // string value
        simpleFeature.setAttribute("Who", PEOPLE_NAMES[i % PEOPLE_NAMES.length]);

        // long value
        simpleFeature.setAttribute("What", i);

        // location:  construct a random point within a 2-degree-per-side square
        double x = MIN_X + random.nextDouble() * DX;
        double y = MIN_Y + random.nextDouble() * DY;
        Geometry geometry = WKTUtils.read("POINT(" + x + " " + y + ")");

        // date-time:  construct a random instant within a year
        simpleFeature.setAttribute("Where", geometry);
        DateTime dateTime = MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR));
        simpleFeature.setAttribute("When", dateTime.toDate());

        // another string value
        // "Why"; left empty, showing that not all attributes need values

        // accumulate this new feature in the collection
        featureCollection.add(simpleFeature);
    }

    return featureCollection;
}
 
開發者ID:geomesa,項目名稱:geomesa-tutorials,代碼行數:50,代碼來源:AvroExample.java

示例15: createNewFeatures

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
static FeatureCollection createNewFeatures(SimpleFeatureType simpleFeatureType, int numNewFeatures) {
    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();

    String id;
    Object[] NO_VALUES = {};
    String[] PEOPLE_NAMES = {"Addams", "Bierce", "Clemens"};
    Long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L;
    Random random = new Random(5771);
    DateTime MIN_DATE = new DateTime(2014, 1, 1, 0, 0, 0, DateTimeZone.forID("UTC"));
    Double MIN_X = -78.0;
    Double MIN_Y = -39.0;
    Double DX = 2.0;
    Double DY = 2.0;

    for (int i = 0; i < numNewFeatures; i ++) {
        // create the new (unique) identifier and empty feature shell
        id = "Observation." + Integer.toString(i);
        SimpleFeature simpleFeature = SimpleFeatureBuilder.build(simpleFeatureType, NO_VALUES, id);

        // be sure to tell GeoTools explicitly that you want to use the ID you provided
        simpleFeature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE);

        // populate the new feature's attributes

        // string value
        simpleFeature.setAttribute("Who", PEOPLE_NAMES[i % PEOPLE_NAMES.length]);

        // long value
        simpleFeature.setAttribute("What", i);

        // location:  construct a random point within a 2-degree-per-side square
        double x = MIN_X + random.nextDouble() * DX;
        double y = MIN_Y + random.nextDouble() * DY;
        Geometry geometry = WKTUtils.read("POINT(" + x + " " + y + ")");

        // date-time:  construct a random instant within a year
        simpleFeature.setAttribute("Where", geometry);
        DateTime dateTime = MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR));
        simpleFeature.setAttribute("When", dateTime.toDate());

        // another string value
        // "Why"; left empty, showing that not all attributes need values

        // set visibility on each feature, and attribute for display
        if (i % 2 == 0) {
            simpleFeature.setAttribute("Visibility", "admin");
            SecurityUtils.setFeatureVisibility(simpleFeature, "admin");
        } else {
            simpleFeature.setAttribute("Visibility", "user|admin");
            SecurityUtils.setFeatureVisibility(simpleFeature, "user|admin");
        }
        // accumulate this new feature in the collection
        featureCollection.add(simpleFeature);
    }

    return featureCollection;
}
 
開發者ID:geomesa,項目名稱:geomesa-tutorials,代碼行數:58,代碼來源:FeatureLevelVisibility.java


注:本文中的org.opengis.feature.simple.SimpleFeature.setAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。