geometry-api-java 学习笔记(三)多点 multipoint

来源:互联网 发布:sql优化 面试题 编辑:程序博客网 时间:2024/06/06 16:25

multipoint 是一组有序点的集合。一个有效的multipoint,集合中的每一个点是不同的。

如果距离x坐标和y坐标之间的距离小于0.001米,multipoint不是一个有效的multipoint。

JSON 格式化

一个multipoint被表示成一个json字符串,格式化成一个points点的集合和一个空间坐标系,还具有布尔类型的hasM和hasZ字段,它俩默认值为false。

points数组的每个成员可能是一个具有2、3或者4个成员的数组,其中如果有2个元素表示2Dpoints,3个元素表示3Dpoints。


一个空multipoint表示成一个points的空数组。

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": []}

创建一个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:

Create this multipoint

MultiPoint class methods

We create a new MultiPoint and add points by calling the add method.

static MultiPoint createMultipoint1() {    MultiPoint mPoint = new MultiPoint();    // Add points    mPoint.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 theexecute 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 theexecutemethod 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 theexecutemethod 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;}

原创粉丝点击