8a6c326c9c87d43a6c95014a4c62105feeb01631.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 com.xkcoding.http.util.StringUtil;
  6. import me.zhyd.oauth.log.Log;
  7. import org.springframework.stereotype.Component;
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. @Component
  11. public class geoinfo {
  12. public String geoinfo(String jd,String wd) {
  13. ArrayList<String> list=new ArrayList<>();
  14. JSONObject featureCollection = new JSONObject();
  15. String type = null;
  16. String substring;
  17. String r = null;
  18. //{"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]]}
  19. //{"crs":{"type":"name","properties":{"name":"EPSG:4490"}},"coordinates":"[[117.21470515847446,36.68296526003463], [117.21191109558109,36.68172842050911], [117.21173959267449,36.684959929690315]]","type":"LinString"}
  20. //{"type":"Point","crs":{"type":"name","properties":{"name":"EPSG:4490"}},"coordinates":[116.35487452721023,36.195113571900855]}
  21. try {
  22. JSONObject properties = new JSONObject();
  23. properties.put("name","EPSG:4490");
  24. JSONObject crs = new JSONObject();
  25. crs.put("type","name");
  26. crs.put("properties",properties);
  27. // {"crs":{"type":"name","properties":{"name":"EPSG:4490"}},"type":"LinString","coordinates":[[117.21470515847446,36.68296526003463],[117.21191109558109,36.68172842050911],[117.21173959267449,36.684959929690315]]}
  28. featureCollection.put("crs",crs);
  29. if(jd.contains(",")&&wd.contains(",")){
  30. String[] a=jd.split(",");
  31. String[] b=wd.split(",");
  32. for (int i = 0; i <a.length ; i++) {
  33. if(StringUtil.isNotEmpty(a[i]) &&StringUtil.isNotEmpty(b[i]) && a[i].contains("°") && b[i].contains("°")){
  34. a[i]=Dms2d.Dms2D(a[i]);
  35. b[i]=Dms2d.Dms2D(b[i]);
  36. }
  37. list.add("["+a[i]+","+b[i]+"]");
  38. }
  39. if(list.get(0).equals(list.get(list.size()-1))){
  40. type="Polygon";
  41. featureCollection.put("type", type);
  42. substring = featureCollection.toString().substring(0, featureCollection.toString().length() - 1);
  43. r=substring+","+"\""+"coordinates"+"\""+":"+"["+list.toString().replace(" ","")+"]"+"}";
  44. }else {
  45. type="LineString";
  46. featureCollection.put("type", type);
  47. substring = featureCollection.toString().substring(0, featureCollection.toString().length() - 1);
  48. r=substring+","+"\""+"coordinates"+"\""+":"+list.toString().replace(" ","")+"}";
  49. }
  50. }else{
  51. ArrayList<String> a=new ArrayList<>();
  52. if(StringUtil.isNotEmpty(jd) &&StringUtil.isNotEmpty(wd) && jd.contains("°") && wd.contains("°")){
  53. jd=Dms2d.Dms2D(jd);
  54. wd=Dms2d.Dms2D(wd);
  55. }
  56. a.add(jd);
  57. a.add(wd);
  58. type="Point";
  59. featureCollection.put("type", type);
  60. substring = featureCollection.toString().substring(0, featureCollection.toString().length() - 1);
  61. r=substring+","+"\""+"coordinates"+"\""+":"+a.toString().replace(" ","")+"}";
  62. }
  63. } catch (JSONException e) {
  64. Log.error("can't save json object: "+e.toString());
  65. }
  66. System.out.println(r);
  67. return r;
  68. }
  69. }