Android GIS Development Series--Introductory season (8) conversion of JSON to geometry

Source: Internet
Author: User

JSON data is common and useful in Android, and JSON data is also supported in ArcGIS, and JSON and geometry can be converted to the data we want.

One, geometry converted to JSON data

This implementation is very simple, for example, when we convert a point to JSON, we also use the powerful class Geometryengine.

Point point = new Point(113, 23);        String json = GeometryEngine.geometryToJson(SpatialReference.create(SpatialReference.WKID_WGS84), point); Log.w("TAG", "json===" + json);


The result of printing log is json==={"x":113.0,"y":23.0,"spatialReference":{"wkid":4326}} , is not very simple.

Second, JSON converted to geometry

We also use the Jsontogeometry method in the Geometryengine class, and we convert the above JSON back.

try {String jsonstr ="{\" x\ ": 113.0,\" y\ ": 23.0,\" spatialreference\ ": {\" wkid\ ": 4326}}"; Jsonfactory jsonfactory = new Jsonfactory (); Jsonparser Jsonparser = jsonfactory. Createjsonparser (JSONSTR); Mapgeometry mapgeometry = Geometryengine. Jsontogeometry (Jsonparser); Point mpoint = (point) mapgeometry. Getgeometry (); Log. I ("TAG", "mpoint---" +mpoint. GetX () +"= = =" +mpoint. GetY ())} catch (IOException e) {e. Printstacktrace ();}
The result of the code execution mPoint---113.0===23.0 . Note: Jsonfactory.createjsonparser This method can be brought into the parameters are also more, such as: File, OutputStream, byte array and so on, interested in small partners can study.





Android GIS Development Series-Introductory season (8) JSON-to-geometry conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.