本文整理汇总了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;
}
示例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);
}
}
}
示例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();
}
}
示例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);
}
}
示例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);
}
示例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();
}
}
示例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();
}
}