JTS(Geometry)
空间数据模型
(1)、JTSGeometrymodel
(2)、ISOGeometrymodel(GeometryPluginandJTSWrapperPlugin)
GeoToolshastwoimplementationsoftheseinterfaces:
GeometryPluginaportofJTS1.7totheISOGeometryinterfaces
JTSWrapperPluginanimplementationthatdelegatesalltheworktoJTS
JTS包结构
系(linearref包)、计算交点(noding包)、几何图形操作(operation包)、平面图(planargraph包)、多边形化(polygnize包)、精度(precision)、工具(util包)
重点理解JTSGeometrymodel
(1)JTS提供了如下的空间数据类型
Point
MultiPoint
LineString
LinearRing封闭的线条
MultiLineString多条线
Polygon
MultiPolygon
GeometryCollection包括点,线,面
(2)支持接口
Coordinate
Coordinate(坐标)是用来存储坐标的轻便的类。它不同于点,点是Geometry的子类。不像模范Point的对象(包含额外的信息,例如一个信包,一个精确度模型和空间参考系统信息),Coordinate只包含纵座标值和存取方法。
Envelope(矩形)
一个具体的类,包含一个最大和最小的x值和y值。
GeometryFactory
GeometryFactory提供一系列的有效方法用来构造来自Coordinate类的Geometry对象。支持接口
[java]viewplaincopy
packagecom.mapbar.geo.jts;
importorg.geotools.geometry.jts.JTSFactoryFinder;
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;
/
ClassGeometryDemo.java
DescriptionGeometry几何实体的创建,读取操作
Companymapbar
authorChenllE-mail:Chenll@mapbar.com
Version1.0
Date2012-2-17上午11:08:50
/
publicclassGeometryDemo{
privateGeometryFactorygeometryFactory=JTSFactoryFinder.getGeometryFactory(null);
/
createapoint
@return
/
publicPointcreatePoint(){
Coordinatecoord=newCoordinate(109.013388,32.715519);
Pointpoint=geometryFactory.createPoint(coord);
returnpoint;
}
/
createapointbyWKT
@return
@throwsParseException
/
publicPointcreatePointByWKT()throwsParseException{
WKTReaderreader=newWKTReader(geometryFactory);
Pointpoint=(Point)reader.read("POINT(109.01338832.715519)");
returnpoint;
}
/
createmultiPointbywkt
@return
/
publicMultiPointcreateMulPointByWKT()throwsParseException{
WKTReaderreader=newWKTReader(geometryFactory);MultiPointmpoint=(MultiPoint)www.wang027.comreader.read
("MULTIPOINT(109.01338832.715519,119.3248831.435678)");
returnmpoint;
}
/
createaline
@return
/
publicLineStringcreateLine(){
Coordinate[]coords=newCoordinate[]{newCoordinate(2,2),newCoordinate(2,2)};
LineStringline=geometryFactory.createLineString(coords);
returnline;
}
/
createalinebyWKT
@return
@throwsParseException
/
publicLineStringcreateLineByWKT()throwsParseException{
WKTReaderreader=newWKTReader(geometryFactory);
LineStringline=(LineString)reader.read("LINESTRING(00,20)");
returnline;
}
/
createmultiLine
@return
/
publicMultiLineStringcreateMLine(){
Coordinate[]coords1=newCoordinate[]{newCoordinate(2,2),newCoordinate(2,2)};
LineStringline1=geometryFactory.createLineString(coords1);
Coordinate[]coords2=newCoordinate[]{newCoordinate(2,2),newCoordinate(2,2)};
LineStringline2=geometryFactory.createLineString(coords2);
LineString[]lineStrings=newLineString[2];
lineStrings[0]=line1;
lineStrings[1]=line2;
MultiLineStringms=geometryFactory.createMultiLineString(lineStrings);
returnms;
}
/
createmultiLinebyWKT
@return
@throwsParseException
/
publicMultiLineStringcreateMLineByWKT()throwsParseException{
WKTReaderreader=newWKTReader(geometryFactory);
MultiLineStringline=(MultiLineString)reader.read("MULTILINESTRING((00,20),(11,22))");
returnline;
}
/
createapolygon(多边形)byWKT
@return
@throwsParseException
/
publicPolygoncreatePolygonByWKT()throwsParseException{
WKTReaderreader=newWKTReader(geometryFactory);
Polygonpolygon=(Polygon)reader.read("POLYGON((2010,300,4010,3020,2010))");
returnpolygon;
}
/
createmultipolygonbywkt
@return
@throwsParseException
/
publicMultiPolygoncreateMulPolygonByWKT()throwsParseException{
WKTReaderreader=newWKTReader(geometryFactory);
MultiPolygonmpolygon=(MultiPolygon)reader.read("MULTIPOLYGON(((4010,300,4010,3020,4010),(3010,300,4010,3020,3010)))");
returnmpolygon;
}
/
createGeometryCollectioncontainpointormultiPointorlineormultiLineorpolygonormultiPolygon
@return
@throwsParseException
/
publicGeometryCollectioncreateGeoCollect()throwsParseException{
LineStringline=createLine();
Polygonpoly=createPolygonByWKT();
Geometryg1=geometryFactory.createGeometry(line);
Geometryg2=geometryFactory.createGeometry(poly);
Geometry[]garray=newwww.baiyuewang.netGeometry[]{g1,g2};
GeometryCollectiongc=geometryFactory.createGeometryCollection(garray);
returngc;
}
/
createaCircle创建一个圆,圆心(x,y)半径RADIUS
@paramx
@paramy
@paramRADIUS
@return
/
publicPolygoncreateCircle(doublex,doubley,finaldoubleRADIUS){
finalintSIDES=32;//圆上面的点个数
Coordinatecoords[]=newCoordinate[SIDES+1];
for(inti=0;i doubleangle=((double)i/(double)SIDES)Math.PI2.0;
doubledx=Math.cos(angle)RADIUS;
doubledy=Math.sin(angle)RADIUS;
coords[i]=newCoordinate((double)x+dx,(double)y+dy);
}
coords[SIDES]=coords[0];
LinearRingring=geometryFactory.createLinearRing(coords);
Polygonpolygon=geometryFactory.createPolygon(ring,null);
returnpolygon;
}
/
@paramargs
@throwsParseException
/
publicstaticvoidmain(String[]args)throwsParseException{
GeometryDemogt=newGeometryDemo();
Polygonp=gt.createCircle(0,1,2);
//圆上所有的坐标(32个)
Coordinatecoords[]=p.getCoordinates();
for(Coordinatecoord:coords){
System.out.println(coord.x+","+coord.y);
}
}
}
|
|