geotools中泰森多边形的生成( 二 )

coords = new ArrayList();Envelope clipEnvelpoe = new Envelope();int xmin = 0, xmax=180;int ymin = 0, ymax=90;Random random = new Random();List geomsPoints = new ArrayList();for(int i=0;i<100;i++){int x = random.nextInt(xmax)%(xmax-xmin+1) + xmin,y = random.nextInt(ymax)%(ymax-ymin+1) + ymin;Coordinate coord = new Coordinate(x,y,i);coords.add(coord);clipEnvelpoe.expandToInclude(coord);geomsPoints.add(new GeometryFactory().createPoint(coord));}String pointpath = "d:/data/tsdbxpt.shp";tsdbx.writeShape(pointpath,"Point", geomsPoints);voronoiDiagramBuilder.setSites(coords);voronoiDiagramBuilder.setClipEnvelope(clipEnvelpoe);Geometry geom = voronoiDiagramBuilder.getDiagram(JTSFactoryFinder.getGeometryFactory());List geoms = new ArrayList();for(int i=0;i geoms) {try {//创建shape文件对象File file = new File(filepath);Map params = new HashMap();params.put( ShapefileDataStoreFactory.URLP.key, file.toURI().toURL() );ShapefileDataStore ds = (ShapefileDataStore) new ShapefileDataStoreFactory().createNewDataStore(params);//定义图形信息和属性信息SimpleFeatureTypeBuilder tb = new SimpleFeatureTypeBuilder();tb.setCRS(DefaultGeographicCRS.WGS84);tb.setName("shapefile");if(geoType=="Point"){tb.add("the_geom", Point.class);}else{tb.add("the_geom", Polygon.class);}ds.createSchema(tb.buildFeatureType());//设置编码Charset charset = Charset.forName("GBK");ds.setCharset(charset);//设置WriterFeatureWriter writer = ds.getFeatureWriter(ds.getTypeNames()[0], Transaction.AUTO_COMMIT);for(int i=0,len=geoms.size();i
参考文献:
1、百度百科
2、 user guide
---------------------------------------------------------------------------------------------------------------
技术博客
CSDN:
博客园:
在线教程