标签:
空间数据模型
(1)、JTS Geometry model
(2)、ISO Geometry model (Geometry Plugin and JTS Wrapper Plugin)
GeoTools has two implementations of these interfaces:
Geometry Plugin a port of JTS 1.7 to the ISO Geometry interfaces
JTS Wrapper Plugin an implementation that delegates all the work to JTS
JTS包结构
系(linearref包)、计算交点(noding包)、几何图形操作(operation包)、平面图(planargraph包)、多边形化(polygnize包)、精度(precision)、工具(util包)
重点理解JTS Geometry model
(1) JTS提供了如下的空间数据类型
Point
MultiPoint
LineString
LinearRing 封闭的线条
MultiLineString 多条线
Polygon
MultiPolygon
GeometryCollection 包括点,线,面
(2) 支持接口
Coordinate
Coordinate(坐标)是用来存储坐标的轻便的类。它不同于点,点是Geometry的子类。不像模范Point的对象(包含额外的信息,例如一个信包,一个精确度模型和空间参考系统信息),Coordinate只包含纵座标值和存取方法。
Envelope(矩形)
一个具体的类,包含一个最大和最小的x 值和y 值。
GeometryFactory
GeometryFactory提供一系列的有效方法用来构造来自Coordinate类的Geometry对象。支持接口
1 package com.mapbar.geo.jts; 2 3 import org.geotools.geometry.jts.JTSFactoryFinder; 4 5 import com.vividsolutions.jts.geom.Coordinate; 6 import com.vividsolutions.jts.geom.Geometry; 7 import com.vividsolutions.jts.geom.GeometryCollection; 8 import com.vividsolutions.jts.geom.GeometryFactory; 9 import com.vividsolutions.jts.geom.LineString; 10 import com.vividsolutions.jts.geom.LinearRing; 11 import com.vividsolutions.jts.geom.Point; 12 import com.vividsolutions.jts.geom.Polygon; 13 import com.vividsolutions.jts.geom.MultiPolygon; 14 import com.vividsolutions.jts.geom.MultiLineString; 15 import com.vividsolutions.jts.geom.MultiPoint; 16 import com.vividsolutions.jts.io.ParseException; 17 import com.vividsolutions.jts.io.WKTReader; 18 19 /** 20 21 * Class GeometryDemo.java 22 23 * Description Geometry 几何实体的创建,读取操作 24 25 * Company mapbar 26 27 * author Chenll E-mail: Chenll@mapbar.com 28 29 * Version 1.0 30 31 * Date 2012-2-17 上午11:08:50 32 33 */ 34 public class GeometryDemo { 35 36 private GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null ); 37 38 /** 39 * create a point 40 * @return 41 */ 42 public Point createPoint(){ 43 Coordinate coord = new Coordinate(109.013388, 32.715519); 44 Point point = geometryFactory.createPoint( coord ); 45 return point; 46 } 47 48 /** 49 * create a point by WKT 50 * @return 51 * @throws ParseException 52 */ 53 public Point createPointByWKT() throws ParseException{ 54 WKTReader reader = new WKTReader( geometryFactory ); 55 Point point = (Point) reader.read("POINT (109.013388 32.715519)"); 56 return point; 57 } 58 59 /** 60 * create multiPoint by wkt 61 * @return 62 */ 63 public MultiPoint createMulPointByWKT()throws ParseException{ 64 WKTReader reader = new WKTReader( geometryFactory ); 65 MultiPoint mpoint = (MultiPoint) reader.read("MULTIPOINT(109.013388 32.715519,119.32488 31.435678)"); 66 return mpoint; 67 } 68 /** 69 * 70 * create a line 71 * @return 72 */ 73 public LineString createLine(){ 74 Coordinate[] coords = new Coordinate[] {new Coordinate(2, 2), new Coordinate(2, 2)}; 75 LineString line = geometryFactory.createLineString(coords); 76 return line; 77 } 78 79 /** 80 * create a line by WKT 81 * @return 82 * @throws ParseException 83 */ 84 public LineString createLineByWKT() throws ParseException{ 85 WKTReader reader = new WKTReader( geometryFactory ); 86 LineString line = (LineString) reader.read("LINESTRING(0 0, 2 0)"); 87 return line; 88 } 89 90 /** 91 * create multiLine 92 * @return 93 */ 94 public MultiLineString createMLine(){ 95 Coordinate[] coords1 = new Coordinate[] {new Coordinate(2, 2), new Coordinate(2, 2)}; 96 LineString line1 = geometryFactory.createLineString(coords1); 97 Coordinate[] coords2 = new Coordinate[] {new Coordinate(2, 2), new Coordinate(2, 2)}; 98 LineString line2 = geometryFactory.createLineString(coords2); 99 LineString[] lineStrings = new LineString[2]; 100 lineStrings[0]= line1; 101 lineStrings[1] = line2; 102 MultiLineString ms = geometryFactory.createMultiLineString(lineStrings); 103 return ms; 104 } 105 106 /** 107 * create multiLine by WKT 108 * @return 109 * @throws ParseException 110 */ 111 public MultiLineString createMLineByWKT()throws ParseException{ 112 WKTReader reader = new WKTReader( geometryFactory ); 113 MultiLineString line = (MultiLineString) reader.read("MULTILINESTRING((0 0, 2 0),(1 1,2 2))"); 114 return line; 115 } 116 117 /** 118 * create a polygon(多边形) by WKT 119 * @return 120 * @throws ParseException 121 */ 122 public Polygon createPolygonByWKT() throws ParseException{ 123 WKTReader reader = new WKTReader( geometryFactory ); 124 Polygon polygon = (Polygon) reader.read("POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))"); 125 return polygon; 126 } 127 128 /** 129 * create multi polygon by wkt 130 * @return 131 * @throws ParseException 132 */ 133 public MultiPolygon createMulPolygonByWKT() throws ParseException{ 134 WKTReader reader = new WKTReader( geometryFactory ); 135 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)))"); 136 return mpolygon; 137 } 138 139 /** 140 * create GeometryCollection contain point or multiPoint or line or multiLine or polygon or multiPolygon 141 * @return 142 * @throws ParseException 143 */ 144 public GeometryCollection createGeoCollect() throws ParseException{ 145 LineString line = createLine(); 146 Polygon poly = createPolygonByWKT(); 147 Geometry g1 = geometryFactory.createGeometry(line); 148 Geometry g2 = geometryFactory.createGeometry(poly); 149 Geometry[] garray = new Geometry[]{g1,g2}; 150 GeometryCollection gc = geometryFactory.createGeometryCollection(garray); 151 return gc; 152 } 153 154 /** 155 * create a Circle 创建一个圆,圆心(x,y) 半径RADIUS 156 * @param x 157 * @param y 158 * @param RADIUS 159 * @return 160 */ 161 public Polygon createCircle(double x, double y, final double RADIUS){ 162 final int SIDES = 32;//圆上面的点个数 163 Coordinate coords[] = new Coordinate[SIDES+1]; 164 for( int i = 0; i < SIDES; i++){ 165 double angle = ((double) i / (double) SIDES) * Math.PI * 2.0; 166 double dx = Math.cos( angle ) * RADIUS; 167 double dy = Math.sin( angle ) * RADIUS; 168 coords[i] = new Coordinate( (double) x + dx, (double) y + dy ); 169 } 170 coords[SIDES] = coords[0]; 171 LinearRing ring = geometryFactory.createLinearRing( coords ); 172 Polygon polygon = geometryFactory.createPolygon( ring, null ); 173 return polygon; 174 } 175 176 /** 177 * @param args 178 * @throws ParseException 179 */ 180 public static void main(String[] args) throws ParseException { 181 GeometryDemo gt = new GeometryDemo(); 182 Polygon p = gt.createCircle(0, 1, 2); 183 //圆上所有的坐标(32个) 184 Coordinate coords[] = p.getCoordinates(); 185 for(Coordinate coord:coords){ 186 System.out.println(coord.x+","+coord.y); 187 } 188 } 189 }
WKT(Well-known text)是一种文本标记语言,用于表示矢量几何对象、空间参照系统及空间参照系统之间的转换。它的二进制表示方式,亦即WKB(well-known binary)则胜于在传输和在数据库中存储相同的信息。该格式由开放地理空间联盟(OGC)制定。
WKT可以表示的几何对象包括:点,线,多边形,TIN(不规则三角网)及多面体。可以通过几何集合的方式来表示不同维度的几何对象。
几何物体的坐标可以是2D(x,y),3D(x,y,z),4D(x,y,z,m),加上一个属于线性参照系统的m值。
以下为几何WKT字串样例:
基础知识:坐标参照系有三种最常见的子类:地心坐标系(geocentric cs、GEOCCS),地理坐标系(geographic cs、GEOGCS),和投影坐标系(projected cs、PROJCS)以及相互之间的关系,可以参考《坐标参照系》。投影参数内容:Ellipsoid 、 Datum ;Projection,可以参考《地图投影为什么》。
坐标系的文字描述的扩展BN范式(EBNF)定义如下:
<coordinate system> = <projected cs> | <geographic cs> | <geocentric cs>
<projection> = PROJECTION["<name>"]
<parameter> = PARAMETER["<name>", <value>]
<value> = <number>
<datum> = DATUM["<name>", <spheroid>]
<spheroid> = SPHEROID["<name>", <semi-major axis>, <inverse flattening>]
<semi-major axis> = <number> NOTE: semi-major axis is measured in meters and must be > 0.
<inverse flattening> = <number>
<prime meridian> = PRIMEM["<name>", <longitude>]
<longitude> = <number>
<angular unit> = <unit>
<linear unit> = <unit>
<unit> = UNIT["<name>", <conversion factor>]
<conversion factor> = <number>
以下示例说明,参照上述参数,然后比瓢画葫芦即可自行用WKT创建坐标系。
地理坐标系的格式:<geographic cs> = GEOGCS["<name>", <datum>, <prime meridian>, <angular unit>]
WGS1984的地理坐标系WKT形式:
GEOGCS["WGS 84",
DATUM["WGS_1984",
SPHEROID["WGS 84", 6378137, 298.257223563, AUTHORITY["EPSG", "7030"]],
AUTHORITY["EPSG", "6326"]],
PRIMEM["Greenwich", 0, AUTHORITY["EPSG", "8901"]],
UNIT["degree", 0.0174532925199433, AUTHORITY["EPSG", "9122"]],
AUTHORITY["EPSG", "4326"]]
投影坐标系的格式:<projected cs> = PROJCS["<name>", <geographic cs>, <projection>, {<parameter>,}* <linear unit>]
WGS1984地理坐标,统一横轴墨卡托(UTM)投影,中央经线117E的投影坐标系WKT形式:
PROJCS["WGS 84 / UTM zone 50N",
GEOGCS["WGS 84", DATUM["WGS_1984", SPHEROID["WGS 84", 6378137, 298.257223563, AUTHORITY["EPSG", "7030"]], AUTHORITY["EPSG", "6326"]], PRIMEM["Greenwich", 0, AUTHORITY["EPSG", "8901"]], UNIT["degree", 0.0174532925199433, AUTHORITY["EPSG", "9122"]], AUTHORITY["EPSG", "4326"]],
PROJECTION["Transverse_Mercator"],
PARAMETER["latitude_of_origin", 0],
PARAMETER["central_meridian", 117],
PARAMETER["scale_factor", 0.9996],
PARAMETER["false_easting", 500000],
PARAMETER["false_northing", 0],
UNIT["metre", 1, AUTHORITY["EPSG", "9001"]],
AUTHORITY["EPSG", "32650"]]
地心坐标系格式相似于地理坐标系:<geocentric cs> = GEOCCS["<name>", <datum>, <prime meridian>, <linear unit>]
参数中出现AUTHORITY是EPSG的玩意,在自定义坐标系时可以忽略,我会在后面详细介绍EPSG相关内容。WKT更具体的可参考OGC相关文档:如SFA、《SF for OLE/COM》等。
练习:给出下属投影坐标系参数,请用WKT方式表述。
投影参数:椭球体,Krasovsky_1940;基准面,北京1954;投影:兰勃特双标准纬线,25N,47N;中央经线,117E。
参考答案:
PROJCS["liongg",有个偷懒的方法就是用商业软件譬如ArcGIS按照参数新建投影,然后在.prj文件中提取投影内容并修改。
标签:
原文地址:http://www.cnblogs.com/gaopeng527/p/5067321.html