java jts_JTS基本概念和使用

java jts_JTS基本概念和使用packagecom alibaba autonavi importcom vividsolutio jts geom Coordinate importcom vividsolutio jts geom Geometry importcom vividsolutio jts geom GeometryColl importcom vividsolutio jts ge

packagecom.alibaba.autonavi;importcom.vividsolutions.jts.geom.Coordinate;importcom.vividsolutions.jts.geom.Geometry;importcom.vividsolutions.jts.geom.GeometryCollection;importcom.vividsolutions.jts.geom.GeometryFactory;importcom.vividsolutions.jts.geom.LineString;importcom.vividsolutions.jts.geom.LinearRing;importcom.vividsolutions.jts.geom.Point;importcom.vividsolutions.jts.geom.Polygon;importcom.vividsolutions.jts.geom.MultiPolygon;importcom.vividsolutions.jts.geom.MultiLineString;importcom.vividsolutions.jts.geom.MultiPoint;importcom.vividsolutions.jts.io.ParseException;importcom.vividsolutions.jts.io.WKTReader;public classGeometryDemo {private GeometryFactory geometryFactory = newGeometryFactory();/* create a point

*@return

*/

publicPoint createPoint(){

Coordinate coord= new Coordinate(109.013388, 32.);

Point point=geometryFactory.createPoint( coord );returnpoint;

}/* create a point by WKT

*@return*@throwsParseException*/

public Point createPointByWKT() throwsParseException{

WKTReader reader= newWKTReader( geometryFactory );

Point point= (Point) reader.read(“POINT (109.013388 32.)”);returnpoint;

}/* create multiPoint by wkt

*@return

*/

public MultiPoint createMulPointByWKT()throwsParseException{

WKTReader reader= newWKTReader( geometryFactory );

MultiPoint mpoint= (MultiPoint) reader.read(“MULTIPOINT(109.013388 32.,119.32488 31.)”);returnmpoint;

}/*

* create a line

*@return

*/

publicLineString createLine(){

Coordinate[] coords= new Coordinate[] {new Coordinate(2, 2), new Coordinate(2, 2)};

LineString line=geometryFactory.createLineString(coords);returnline;

}/* create a line by WKT

*@return*@throwsParseException*/

public LineString createLineByWKT() throwsParseException{

WKTReader reader= newWKTReader( geometryFactory );

LineString line= (LineString) reader.read(“LINESTRING(0 0, 2 0)”);returnline;

}/* create multiLine

*@return

*/

publicMultiLineString createMLine(){

Coordinate[] coords1= new Coordinate[] {new Coordinate(2, 2), new Coordinate(2, 2)};

LineString line1=geometryFactory.createLineString(coords1);

Coordinate[] coords2= new Coordinate[] {new Coordinate(2, 2), new Coordinate(2, 2)};

LineString line2=geometryFactory.createLineString(coords2);

LineString[] lineStrings= new LineString[2];

lineStrings[0]=line1;

lineStrings[1] =line2;

MultiLineString ms=geometryFactory.createMultiLineString(lineStrings);returnms;

}/* create multiLine by WKT

*@return*@throwsParseException*/

public MultiLineString createMLineByWKT()throwsParseException{

WKTReader reader= newWKTReader( geometryFactory );

MultiLineString line= (MultiLineString) reader.read(“MULTILINESTRING((0 0, 2 0),(1 1,2 2))”);returnline;

}/* create a polygon(多边形) by WKT

*@return*@throwsParseException*/

public Polygon createPolygonByWKT() throwsParseException{

WKTReader reader= newWKTReader( geometryFactory );

Polygon polygon= (Polygon) reader.read(“POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))”);returnpolygon;

}/* create multi polygon by wkt

*@return*@throwsParseException*/

public MultiPolygon createMulPolygonByWKT() throwsParseException{

WKTReader reader= newWKTReader( geometryFactory );

MultiPolygon mpolygon= (MultiPolygon) reader.read(“MULTIPOLYGON(((40 10, 30 0, 40 10, 30 20, 40 10),(30 10, 30 0, 40 10, 30 20, 30 10)))”);returnmpolygon;

}/* create GeometryCollection contain point or multiPoint or line or multiLine or polygon or multiPolygon

*@return*@throwsParseException*/

public GeometryCollection createGeoCollect() throwsParseException{

LineString line=createLine();

Polygon poly=createPolygonByWKT();

Geometry g1=geometryFactory.createGeometry(line);

Geometry g2=geometryFactory.createGeometry(poly);

Geometry[] garray= newGeometry[]{g1,g2};

GeometryCollection gc=geometryFactory.createGeometryCollection(garray);returngc;

}/* create a Circle 创建一个圆,圆心(x,y) 半径RADIUS

*@paramx

*@paramy

*@paramRADIUS

*@return

*/

public Polygon createCircle(double x, double y, final doubleRADIUS){final int SIDES = 32;//圆上面的点个数

Coordinate coords[] = new Coordinate[SIDES+1];for( int i = 0; i < SIDES; i++){double angle = ((double) i / (double) SIDES) * Math.PI * 2.0;double dx = Math.cos( angle ) *RADIUS;double dy = Math.sin( angle ) *RADIUS;

coords[i]= new Coordinate( (double) x + dx, (double) y +dy );

}

coords[SIDES]= coords[0];

LinearRing ring=geometryFactory.createLinearRing( coords );

Polygon polygon= geometryFactory.createPolygon( ring, null);returnpolygon;

}/*@paramargs

*@throwsParseException*/

public static void main(String[] args) throwsParseException {

GeometryDemo gt= newGeometryDemo();

Polygon p= gt.createCircle(0, 1, 2);//圆上所有的坐标(32个)

Coordinate coords[] =p.getCoordinates();for(Coordinate coord:coords){

System.out.println(coord.x+”,”+coord.y);

}

}

}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/224954.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月17日 上午10:45
下一篇 2026年3月17日 上午10:46


相关推荐

  • 什么是AI智能体(agent)?一文读懂AI智能体:定义、分类与应用,程序员必备收藏指南!

    什么是AI智能体(agent)?一文读懂AI智能体:定义、分类与应用,程序员必备收藏指南!

    2026年3月12日
    1
  • 史上最全 Java 多线程面试题及答案「建议收藏」

    史上最全 Java 多线程面试题及答案「建议收藏」这篇文章主要是对多线程的问题进行总结的,因此罗列了40个多线程的问题。这些多线程的问题,有些来源于各大网站、有些来源于自己的思考。可能有些问题网上有、可能有些问题对应的答案也有、也可能有些各位网友也都看过,但是本文写作的重心就是所有的问题都会按照自己的理解回答一遍,不会去看网上的答案,因此可能有些问题讲的不对,能指正的希望大家不吝指教。1、多线程有什么用? 一个可能在很多人…

    2022年8月27日
    7
  • Glance详解_glance of

    Glance详解_glance ofGlance简介Glance是OpenStack平台中负责镜像服务的组件,其功能包括系统镜像的查找、注册和获取等,简单来说glance的功能就是用户可以通过其提供的RESTAPI查询和获取镜像元数据。glance负责OpenStack中的ImageService,那么Image是什么,简单来说Image就是一个模板,里面包含各种常用的操作系统和软件,这样用户在租用OpenStack服务后就…

    2025年7月26日
    6
  • Delphi XE5中的新增内容

    Delphi XE5中的新增内容DelphiXE5中的新增内容DelphiXE5是所有Delphi开发人员的必须备升级,并且是来自Embarcadero的获奖的、多设备应用开发解决方案的最新版本。使用DelphiXE5的新特性,以交付应用Android、iOS、Windows和OSX。以PC机、平板电脑和智能手机为目标,更轻松地与更多数据连接-等等!DelphiXE5中的新特性针对设

    2022年7月18日
    23
  • struts2漏洞监测_struts2 漏洞 测试方案 与 解决方案

    struts2漏洞监测_struts2 漏洞 测试方案 与 解决方案Struts2的核心是使用的webwork框架,处理action时通过调用底层的getter/setter方法来处理http的参数,它将每个http参数声明为一个ONGL(这里是ONGL的介绍)语句。当我们提交一个http参数:Java代码?user.address.city=Bishkek&user[‘favoriteDrink’]=kumys?user.address.city=Bi…

    2022年7月19日
    19
  • Spring boot zuul 网关「建议收藏」

    Spring boot zuul 网关「建议收藏」Zuul作为微服务系统的网关组件,用于构建边界服务,致力于动态的路由、过滤、监控、弹性伸缩和安全。其中Zuul、Ribbon以及Eureka的结合使用可以实现智能路由和负载均衡的功能,网关将所有的服务的API接口统一聚合,统一对外暴露,外界调用API的接口的时候,不需要知道微服务系统中各服务相关调用的复杂性,保护了内部微服务单元的API接口,网关可以做用户身份认证和权限认证,防止非法请求操作a…

    2022年8月15日
    8

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号