地図を扱う時にGeoJSONが使えると便利だそうなので調べる。
GeoJSON
{}がオブジェクト。[]が配列。JSONっていう形式があって、その派生みたい。FeatureCollection > Feature > Point > coordinatesみたいなのを作りたい。
JSONObject・JSONArray
この2つを使うとJSON形式が作れるようで、GeoJSONは特定のname, valueを含めてけばいいようだ。
public class GeoJASONMainActivity extends AppCompatActivity {
TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_geo_jasonmain);
tv = findViewById(R.id.editText);
makeJSON();
}
void makeJSON() {
String[] list = {"138.7306,35.3625", "141.936667,45.5225", "123.805056,24.049806", "145.816278,43.385056", "123.004722,24.468333"};
JSONObject json = new JSONObject();
JSONObject nullobj = new JSONObject();
String[] listr = new String[5000];
for (int i = 0; i <= 4999; i++) {
Random r = new Random();
double randomValueLat = 123.004722 + (145.816278 - 123.004722) * r.nextDouble();
double randomValueLon = 24.049806 + (45.5225 - 24.049806) * r.nextDouble();
listr[i] = String.valueOf(randomValueLat) + "," + String.valueOf(randomValueLon);
}
try {
json.put("type", "FeatureCollection");
JSONArray featureList = new JSONArray();
for (String obj : listr) {
JSONObject point = new JSONObject();
point.put("type", "Point");
JSONArray coord = new JSONArray("[" + obj + "]");
point.put("coordinates", coord);
JSONObject feature = new JSONObject();
feature.put("type", "Feature");
feature.put("properties", nullobj);
feature.put("geometry", point);
featureList.put(feature);
json.put("features", featureList);
}
} catch (JSONException e) {
e.printStackTrace();
}
tv.setText(json.toString());
}
}
で、こうなった。editTextに表示させてる。
そんで、いったんPCに送ってgeojson.ioで表示してみた。
富士山+東西南北端
100個
1000個
5000個
10000個もやってみたけど重すぎて途中でやめた。
参考
https://s.kitazaki.name/docs/geojson-spec-ja.html
https://ja.wikipedia.org/wiki/GeoJSON
https://ja.wikipedia.org/wiki/%E6%97%A5%E6%9C%AC%E3%81%AE%E7%AB%AF%E3%81%AE%E4%B8%80%E8%A6%A7
https://tools.m-bsys.com/development_tooles/json-beautifier.php




