Arcgis for Android 空间数据WKT与JSON描述

点线面数据标准格式

一、 

WKT:

POINT(-118.4 -45.2)

JSON:

{

"x": -118.4,

"y": -45.2,

"spatialReference": {

"wkid": 4326

}

}

二、 多点

WKT:

MULTIPOINT(1.01 2.02, 2.01 3.01)

注意:这个结构与OGC标准不同,这是sqlite的几何体的结构。

OGC标准: MULTIPOINT( (1.01 2.02), (2.01 3.01))

JSON:

{

"points": [

[

1.01,

2.02

],

[

2.01,

3.01

]

],

"spatialReference": {

"wkid": 4326

}

}

三、 线

WKT:

LINESTRING(668540.706869 4858267.857562, 668545.871539 4858270.322537, 668535.504206 4858270.059492)

JSON:

{

"paths": [

[

[

668540.706869,

4858267.857562

],

[

668545.871539,

4858270.322537

],

[

668535.504206,

4858270.059492

]

]

],

"spatialReference": {

"wkid": 102100

}

}

四、 多义线

WKT:

MULTILINESTRING((668540.706869 4858267.857562,668545.871539 4858270.322537),(668535.504206 4858270.059492, 668535.504206 4858270.059492))

JSON:

{

"rings": [

[

[

668540.706869,

4858267.857562

],

[

668545.871539,

4858270.322537

]

],

[

[

668535.504206,

4858270.059492

],

[

668535.504206,

4858270.059492

]

]

],

"spatialReference": {

"wkid": 102100

}

}

五、 多边形

注意: 多边形首尾两点坐标是相同的。

WKT:

POLYGON((10172081.707086032 3426616.2980572497,10181098.35305895 3439876.071546833,10188842.060776865 3423858.265171416,10172081.707086032 3426616.2980572497))

JSON:

{

"rings": [

[

[

10172081.707086032,

3426616.2980572497

],

[

10181098.35305895,

3439876.071546833

],

[

1266114.9310351424,

3430468.042044999

],

[

10188842.060776865,

3423858.265171416

] ,

[

10172081.707086032,

3426616.2980572497

]

]

],

"spatialReference": {

"wkid": 102100

}

}

六、 多多边形

WKT:

MULTIPOLYGON(((752912.250297 5028764.989051, 753066.871935 5028928.677375, 753417.249537 5028775.949135, 753828.826422 5027429.54477, 752992.3308 5028072.927877, 752912.250297 5028764.989051)))

JSON:

{

"rings": [

[

[

752912.250297,

5028764.989051

],

[

753066.871935,

5028928.677375

],

[

753417.249537,

5028775.949135

],

[

753828.826422,

5027429.54477

],

[

752992.3308,

5028072.927877

],

[

752912.250297,

5028764.989051

]

]

],

"spatialReference": {

"wkid": 102100

}

}

 

实际应用开发

1) WKT与JSON格式的相互转换。

WKT转成JSON方法: String WKT.read(String wktsr)

JSON转成WKT方法: String WKT.write(String jsonstr)

2) 基于第一点可将WKT生成Arcgis for Android 的几何体Geometry

从Spatialite数据库读取几何体的WKT字符串:

SELECT ASTEXT(geometry) FROM test

将WKT字符串转成JSON,通过GeometryEngine的jsonToGeometry方法将JSON转成Geometry对象。

String str= "{"rings":[[[1007664.4779535953,3710553.4649297176],[957962.4793888753,3190110.978805308],[1266114.9310351424,3430468.042044999],[1007664.4779535953,3710553.4649297176]]],"spatialReference":{"wkid":102100}} ";

JsonFactory jsonFactory = new JsonFactory();

try {

JsonParser jsonParser = jsonFactory.createJsonParser(str);

MapGeometry mapgeo = GeometryEngine.jsonToGeometry(jsonParser);

Geometry geo = mapgeo.getGeometry();

} catch (JsonParseException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

3) 将Arcgis for android Geomtery 存入空间数据库Spatialite中,我是指存入空间数据而不是WKT字符串。

JSON字符串是通过GeometryEngine的geometryToJson方法生成,转成WKT后再插入空间数据库。

将多点数据插入Spatialite数据库:

INSERT INTO test ( geometry) VALUES(GeomFromText('MULTIPOINT(1.01 2.02, 2.01 3.01)', 4326))

原文地址:https://www.cnblogs.com/telwanggs/p/8550520.html