417d1a77dae7c8f1f8ab658fe4de9e2e6754df27.svn-base 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package org.jeecg.modules.demo.untils;
  2. import com.alibaba.fastjson.JSONArray;
  3. import com.alibaba.fastjson.JSONException;
  4. import com.alibaba.fastjson.JSONObject;
  5. import me.zhyd.oauth.log.Log;
  6. import org.springframework.stereotype.Component;
  7. import java.util.ArrayList;
  8. import java.util.List;
  9. @Component
  10. public class geoinfo {
  11. public String geoinfo(String jd,String wd) {
  12. ArrayList<String> list=new ArrayList<>();
  13. JSONObject featureCollection = new JSONObject();
  14. String type = null;
  15. String substring;
  16. String r = null;
  17. //{"type":"LineString","crs":{"type":"name","properties":{"name":"EPSG:4490"}},"coordinates":[[117.02511407469186,36.58087944812466],[117.02303754894979,36.57606883015553],[117.02144554588087,36.587005199063775],[117.0279866019684,36.58648606762826],[117.02843651587918,36.579633532679416]]}
  18. //{"crs":{"type":"name","properties":{"name":"EPSG:4490"}},"coordinates":"[[117.21470515847446,36.68296526003463], [117.21191109558109,36.68172842050911], [117.21173959267449,36.684959929690315]]","type":"LinString"}
  19. //{"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4490"}},"coordinates":[116.35487452721023,36.195113571900855]}
  20. try {
  21. JSONObject properties = new JSONObject();
  22. properties.put("name","EPSG:4490");
  23. JSONObject crs = new JSONObject();
  24. crs.put("type","name");
  25. crs.put("properties",properties);
  26. // {"crs":{"type":"name","properties":{"name":"EPSG:4490"}},"type":"LinString","coordinates":[[117.21470515847446,36.68296526003463],[117.21191109558109,36.68172842050911],[117.21173959267449,36.684959929690315]]}
  27. featureCollection.put("crs",crs);
  28. if(jd.contains(",")&&wd.contains(",")){
  29. String[] a=jd.split(",");
  30. String[] b=wd.split(",");
  31. for (int i = 0; i <a.length ; i++) {
  32. list.add("["+a[i]+","+b[i]+"]");
  33. }
  34. if(list.get(0).equals(list.get(list.size()-1))){
  35. type="Polygon";
  36. featureCollection.put("type", type);
  37. substring = featureCollection.toString().substring(0, featureCollection.toString().length() - 1);
  38. r=substring+","+"\""+"coordinates"+"\""+":"+"["+list.toString().replace(" ","")+"]"+"}";
  39. }else {
  40. type="LineString";
  41. featureCollection.put("type", type);
  42. substring = featureCollection.toString().substring(0, featureCollection.toString().length() - 1);
  43. r=substring+","+"\""+"coordinates"+"\""+":"+list.toString().replace(" ","")+"}";
  44. }
  45. }else{
  46. ArrayList<String> a=new ArrayList<>();
  47. a.add(jd);
  48. a.add(wd);
  49. type="Point";
  50. featureCollection.put("type", type);
  51. substring = featureCollection.toString().substring(0, featureCollection.toString().length() - 1);
  52. r=substring+","+"\""+"coordinates"+"\""+":"+a.toString().replace(" ","")+"}";
  53. }
  54. } catch (JSONException e) {
  55. Log.error("can't save json object: "+e.toString());
  56. }
  57. System.out.println(featureCollection.toString());
  58. System.out.println(r);
  59. return r;
  60. }
  61. }