Arcgis for Android 空间数据 WKT 与 JSON 描述
点线面数据标准格式
一 点WKT:
POINT(-118.4-45.2)
JSON:
{
"x":-118.4,
"y":-45.2,
"spatialReference":{
"wkid":4326
}
}
二 多点WKT:
MULTIPOINT(1.012.02,2.013.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.7068694858267.857562,668545.8715394858270.322537,668535.5042064858270.059492)
JSON:
{
"paths":[
[
[
668540.706869,
4858267.857562
],
[
668545.871539,
4858270.322537
],
[
668535.504206,
4858270.059492
]
]
],
"spatialReference":{
"wkid":102100
}
}
四 多义线WKT:
MULTILINESTRING((668540.7068694858267.857562,668545.8715394858270.322537),(668535.5042064858270.059492,668535.5042064858270.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.7070860323426616.2980572497,10181098.353058953439876.071546833,10188842.0607768653423858.265171416,10172081.7070860323426616.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.2502975028764.989051,753066.8719355028928.677375,753417.2495375028775.949135,753828.8264225027429.54477,752992.33085028072.927877,752912.2502975028764.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 对象Stringstr="{\"rings\":[[[1007664.4779535953,3710553.4649297176],[957962.4793888753,3190110.978805308],[1266114.9310351424,3430468.042044999],[1007664.4779535953,3710553.4649297176]]],\"spatialReference\":{\"wkid\":102100}}";
JsonFactoryjsonFactory=newJsonFactory();
try{
JsonParserjsonParser=jsonFactory.createJsonParser(str);
MapGeometrymapgeo=GeometryEngine.jsonToGeometry(jsonParser);
Geometrygeo=mapgeo.getGeometry();
}catch(JsonParseExceptione){
// TODO Auto-generated catch block
e.printStackTrace();
}catch(IOExceptione){
// 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))
来源: http://www.bubuko.com/infodetail-2525376.html