Conversion between ArcGIS runtime for iOS geometric objects and JSON

Source: Internet
Author: User

The geometric objects drawn by the client may need to be saved for later use in some application scenarios. You can consider converting the geometric objects to JSON and then retaining them in the sqllite database, when necessary, return the geometric object to the operator by parsing the JSON object. Note that in this example, while storing the geometric object, the type of the object is also stored, which lays the foundation for later JSON parsing. The core code is as follows:

The. h header file is defined as follows:

# Import <Foundation/Foundation. h>

# Import <ArcGIS/ArcGIS. h>

@ Interface convtergeometryjson:

-(Nsstring *) geometrytojson :( agsgeometry *) geometry;

-(Agsgeometry *) jsontogeometry :( nsstring *) JSON geometype :( nsstring *) type;

@ End

The. M file is implemented as follows:

# Import "convtergeometryjson. H"

@ Implementation convtergeometryjson

-(Nsstring *) geometrytojson :( agsgeometry *) geometry


If (geometry = nil ){

Return nil;




Nsdictionary * JSON = [Geometry

Nsstring * jsonstring = [JSON

Return jsonstring;



-(Agsgeometry *) jsontogeometry :( nsstring *) JSON geometype :( nsstring *) type {

Nsdictionary * jsondic = [JSON

Agsgeometry * GEO;

If ([type isequal: @ "point"]) {

GEO = [[agspoint alloc] initwithjson: jsondic];

} Else if ([Type
Isequal: @ "polyline"])


GEO = [[agspolympus line
Alloc] initwithjson: jsondic];




GEO = [[agspolympus Gon alloc]
Initwithjson: jsondic];


Nslog (@ "% @", jsondic );

Return GEO;


@ End

The above method completes the mutual conversion between the space geometric object and the JSON string. In addition, it should be noted that when sqllite is used to write the converted geometric object string to the corresponding field of the database, special character problems may occur, resulting in an unpredictable error in the SQL statement, you can solve the problem by using the following methods:

Sqlite3_bind_text (statement, 1, [name
Cstringusingencoding: 1],-1,
Sqlite_transient );

For more information, see sqllite.

Related Article

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: 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.