Geotools中手工创建Feature的方法
package map;

import org.geotools.map.MapLayer;
import org.geotools.factory.FactoryRegistryException;
import org.geotools.feature.Feature;
import org.geotools.feature.type.GeometricAttributeType;
import org.geotools.feature.type.TextualAttributeType;
import org.geotools.filter.Filter;
import org.geotools.feature.FeatureTypeFactory;
import org.geotools.feature.FeatureType;
import org.geotools.feature.AttributeType;
import org.geotools.feature.IllegalAttributeException;
import org.geotools.feature.SchemaException;
import org.geotools.feature.Feature;
import org.geotools.feature.FeatureFactory;

import com.vividsolutions.jts.geom.Envelope;
import com.vividsolutions.jts.geom.Point;
import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;

import org.opengis.referencing.crs.CoordinateReferenceSystem;


public class MainClass …{

public static void main(String args[])…{
System.out.println(“begin“);
MainClass mainClass = new MainClass();
mainClass.test();
//new TestMap().sichuan();
System.out.println(“end“);
}

public void test()…{
CoordinateReferenceSystem crs = null;
GeometricAttributeType geoType = new GeometricAttributeType(“the_geom“,Point.class,true,1,1,null,crs,Filter.ALL);
TextualAttributeType txtType = new TextualAttributeType(“NAME“,true,1,1,null,Filter.ALL);

try …{
GeometryFactory geometryFactory = new GeometryFactory();
Coordinate c = new Coordinate(104.00,29.0);
Point pt = geometryFactory.createPoint(c);
String name = “beijing“;

FeatureType featureType = FeatureTypeFactory.newFeatureType(new AttributeType[]…{geoType,txtType}, “temp“);

Feature feature = featureType.create(new Object[]…{pt,name});
System.out.println(feature);

} catch (FactoryRegistryException e) …{
// TODO 自动生成 catch 块
e.printStackTrace();

} catch (SchemaException e) …{
// TODO 自动生成 catch 块
e.printStackTrace();

} catch (IllegalAttributeException e) …{
// TODO 自动生成 catch 块
e.printStackTrace();
}
System.out.println(geoType);
System.out.println(txtType);
}
}

转载自:https://blog.csdn.net/makui/article/details/1776247