GeoTools Polygon smooth方法

本文介绍了一种使用GeoTools库中的Polygonsmooth方法处理带有菱角的polygon数据的方法,通过示例代码展示了如何将不规则的多边形平滑处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最近有个任务需要把 带有菱角的polygon数据处理光滑,网上搜索后发现GeoTools Polygon smooth方法 ,很好用。代码如下

import org.geotools.geometry.jts.JTS;
import org.geotools.geometry.jts.JTSFactoryFinder;


import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKTReader;




public class test {


public static void main(String[] args) {
// TODO Auto-generated method stub
String p="POLYGON((121.76762347504986 31.264281436214233,120.74589495942485 31.085685429106803,121.03153949067486 30.23515447986118,121.76762347504986 31.264281436214233))";
      
System.out.println(p);
System.out.println(getSmoothPolygonByGeoTools(p));


}
private static GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
public static String getSmoothPolygonByGeoTools(String polygonargs) {
// TODO Auto-generated method stub

WKTReader reader = new WKTReader( geometryFactory );
Polygon polygon = null;
try {
polygon = (Polygon) reader.read(polygonargs);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
   GeometryFactory  f= new GeometryFactory();
Polygon re= (Polygon) JTS.smooth(polygon, 1);
String rs="POLYGON((";
for(int i=0;i<re.getCoordinates().length;i++){
//System.out.println(re.getCoordinates()[i].x+","+re.getCoordinates()[i].y);
rs+=re.getCoordinates()[i].x+" "+re.getCoordinates()[i].y+",";
}
rs=rs.substring(0,rs.length()-1);
rs=rs+"))";
return rs;
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值