點線面資料標準格式
一、 點
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))