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


Java SimpleFeature.setDefaultGeometry方法代碼示例

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


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

示例1: correctFeatures

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
public static SimpleFeatureCollection correctFeatures(SimpleFeatureCollection fc){
 	SimpleFeatureIterator iterator=fc.features();
 	DefaultFeatureCollection outVector = new DefaultFeatureCollection();

 	while(iterator.hasNext()){
 		SimpleFeature sf=iterator.next();
 		Geometry gm=(Geometry)sf.getDefaultGeometry();
 		if(!gm.isValid()){
 			gm=JTSUtil.repair(gm);
 			System.out.println(gm.isValid());
 		}
sf.setDefaultGeometry(gm);
   outVector.add(sf);

 	}

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

示例2: 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

示例3: exportToShapefile

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
/**
 * Export features to a new shapefile using the map projection in which
 * they are currently displayed
 */
 public static void exportToShapefile(DataStore newDataStore, FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)/*,SimpleFeatureType ftype)*/ throws Exception {
 // carefully open an iterator and writer to process the results
    Transaction transaction = new DefaultTransaction();
    FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriter(newDataStore.getTypeNames()[0],  transaction);

    FeatureIterator<SimpleFeature> iterator = featureCollection.features();
    try {

        while( iterator.hasNext() ){
            SimpleFeature feature = iterator.next();
            SimpleFeature copy = writer.next();


            //copy.setAttributes( feature.getAttributes() );
            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            if(geometry!=null){
            	copy.setDefaultGeometry( geometry.buffer(0));
            	writer.write();
            }else{
            	logger.warn("Warning:geometry null");
            }
        }
        transaction.commit();
        logger.info("Export to shapefile complete" );
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
        logger.error("Export to shapefile failed",problem );
    } finally {
        writer.close();
        iterator.close();
        transaction.close();
    }
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:39,代碼來源:SimpleShapefile.java

示例4: 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

示例5: 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

示例6: 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

示例7: exportToShapefileForceWGS84

import org.opengis.feature.simple.SimpleFeature; //導入方法依賴的package包/類
public static void exportToShapefileForceWGS84(DataStore newDataStore, FeatureCollection<SimpleFeatureType,SimpleFeature> featureCollection)/*,SimpleFeatureType ftype)*/ throws Exception {
 // carefully open an iterator and writer to process the results
    Transaction transaction = new DefaultTransaction();

    //CoordinateReferenceSystem crsOrig=featureCollection.getSchema().getCoordinateReferenceSystem();

    //set wgs84 coordinates ref sys
    SimpleFeatureType featureType = SimpleFeatureTypeBuilder.retype(featureCollection.getSchema(), DefaultGeographicCRS.WGS84);
    newDataStore.createSchema(featureType);

    FeatureWriter<SimpleFeatureType, SimpleFeature> writer = newDataStore.getFeatureWriter(newDataStore.getTypeNames()[0],  transaction);
    //create the transformation
    MathTransform trans=CRS.findMathTransform(CRS.parseWKT(WKTString.WKT3995_ESRI),DefaultGeographicCRS.WGS84);


    FeatureIterator<SimpleFeature> iterator = featureCollection.features();
    try {

        while( iterator.hasNext() ){
            SimpleFeature feature = iterator.next();
            SimpleFeature copy = writer.next();


            Geometry geometry = (Geometry) feature.getDefaultGeometry();
            geometry=JTS.transform(geometry,trans);


            if(geometry!=null){
            	copy.setDefaultGeometry( geometry.buffer(0));
            	writer.write();
            }else{
            	logger.warn("Warning:geometry null");
            }
        }
        transaction.commit();
        logger.info("Export to shapefile complete" );
    } catch (Exception problem) {
        problem.printStackTrace();
        transaction.rollback();
        logger.error("Export to shapefile failed",problem );
    } finally {
        writer.close();
        iterator.close();
        transaction.close();
    }
}
 
開發者ID:ec-europa,項目名稱:sumo,代碼行數:47,代碼來源:SimpleShapefile.java


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