geometry-api-java 学习笔记(三)多点 multipoint
multipoint 是一組有序點的集合。一個有效的multipoint,集合中的每一個點是不同的。
如果距離x坐標和y坐標之間的距離小于0.001米,multipoint不是一個有效的multipoint。
JSON 格式化
一個multipoint被表示成一個json字符串,格式化成一個points點的集合和一個空間坐標系,還具有布爾類型的hasM和hasZ字段,它倆默認值為false。
points數(shù)組的每個成員可能是一個具有2、3或者4個成員的數(shù)組,其中如果有2個元素表示2Dpoints,3個元素表示3Dpoints。
一個空multipoint表示成一個points的空數(shù)組。
Syntax語法
{"hasZ" : true | false,"hasM" : true | false,"points": [[<x1>,<y1>,<z1>,<m1>], ... ,[<xn>,<yn>,<zn>,<mn>]],"spatialReference" : {"wkid" : <wkid>}
}
2D multipoint
{"points": [[32462,-57839],[43892,-49160],[35637,-65035],[46009,-60379]],"spatialReference" : {"wkid" : 54004} }3D multipoint with Ms
Note that the third point does not have a z-value, and the fourth point does not have an m-value.
{"hasZ" : true,"hasM" : true,"points": [[32462,-57839,20,1],[43892,-49160,25,2],[35637,-65035,null,3],[46009,-60379,22]],"spatialReference" : {"wkid" : 54004} }Empty multipoint
{"points": []}創(chuàng)建一個multipoint
To create a multipoint, we can use the MultiPoint class methods or one of the import operators.
Each of the code samples below creates a multipoint with six points.
The multipoint looks like this:
MultiPoint class methods
We create a new MultiPoint and add points by calling the add method.
static MultiPoint createMultipoint1() {MultiPoint mPoint = new MultiPoint();// Add pointsmPoint.add(1, 1);mPoint.add(0.5, -0.5);mPoint.add(1, -1.5);mPoint.add(-1, -1);mPoint.add(-2, -0.5);mPoint.add(-1.5, 1.5);return mPoint; }Import from JSON
We first create the JSON string which represents the multipoint. We then call the execute method of OperatorImportFromJson.
static MultiPoint createMultipointFromJson() throws JsonParseException, IOException {String jsonString = "{\"points\":[[1,1],[0.5,-0.5],[1,-1.5],[-1,-1],[-2,-0.5],[-1.5,1.5]],"+ "\"spatialReference\":{\"wkid\":4326}}";MapGeometry mapGeom = OperatorImportFromJson.local().execute(Geometry.Type.MultiPoint, jsonString);return (MultiPoint)mapGeom.getGeometry(); }Import from GeoJSON
We first create the GeoJSON string which represents the multipoint. We then call the executemethod of OperatorImportFromGeoJson.
static MultiPoint createMultipointFromGeoJson() throws JsonParseException, IOException {String geoJsonString = "{\"type\":\"MultiPoint\","+ "\"coordinates\":[[1,1],[0.5,-0.5],[1,-1.5],[-1,-1],[-2,-0.5],[-1.5,1.5]],"+ "\"crs\":\"EPSG:4326\"}";MapGeometry mapGeom = OperatorImportFromGeoJson.local().execute(GeoJsonImportFlags.geoJsonImportDefaults, Geometry.Type.MultiPoint, geoJsonString, null);return (MultiPoint)mapGeom.getGeometry(); }Import from WKT
We first create the WKT string which represents the multipoint. We then call the executemethod of OperatorImportFromWkt.
static MultiPoint createMultipointFromWKT() throws JsonParseException, IOException {String wktString = "MULTIPOINT ((1 1),(0.5 -0.5),(1 -1.5),(-1 -1),(-2 -0.5),(-1.5 1.5))";Geometry geom = OperatorImportFromWkt.local().execute(WktImportFlags.wktImportDefaults, Geometry.Type.MultiPoint, wktString, null);return (MultiPoint)geom; }總結
以上是生活随笔為你收集整理的geometry-api-java 学习笔记(三)多点 multipoint的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Scala入门到精通——第二十五节 提取
- 下一篇: geometry-api-java 学习