Select to view content in your preferred language

Error saving with getGeometry().toJson()

164
5
Jump to solution
3 weeks ago
MaríaBencomo
Occasional Contributor

Hi!

I'm working on an app that display nautical charts; i'm using a polyline to represent a "route". This route can be save in the phone as json file. To do this, i use pathRoute.getGeometry().toJson().

As you can seee in the video, the route has 4 points, however, when i save the "route", it saves a lots of points in the json file. Why this's happening?

The nautical charts that i'm using is in 2 million scale. 

Thanks for your support.

Ma Eugenia

 

 

0 Kudos
1 Solution

Accepted Solutions
MaríaBencomo
Occasional Contributor

Hi Nicholas.

I just changed GeometryEngine.densifyGeodetic for GeometryEngine.densify, and for a 4 point route it save in the json file 7 point...

View solution in original post

0 Kudos
5 Replies
Nicholas-Furness
Esri Regular Contributor

I assume the route is being drawn using your own custom code and stored as a Graphic (the pathRoute above looks like a GeoElement of some sort - can you confirm if it's a Graphic or a Feature, though it shouldn't make a difference).

It looks like sometime between tapping the 4 points and writing it out to JSON, it is being densified somehow. Do you have any code that calls GeometryEngine.densify() or .densifyGeodetic()?

MaríaBencomo
Occasional Contributor

Hi Nicholas!

Yes, the route it's a graphic. I'm not using those method when i drawing the route; this how i do it.

Regards!

public Geometry drawRoute(ArrayList<Point> addPoint, int value) {
Geometry pathGeometry = GeometryEngine.densifyGeodetic(new Polyline(new PointCollection(addPoint, SpatialReferences.getWgs84())), 1.0d, this.mLinearUnit, GeodeticCurveType.GEODESIC);
pathRoute.setGeometry(pathGeometry);
return pathGeometry;
}

 

 

 

0 Kudos
MaríaBencomo
Occasional Contributor

Hi Nicholas.

I just changed GeometryEngine.densifyGeodetic for GeometryEngine.densify, and for a 4 point route it save in the json file 7 point...

0 Kudos
Nicholas-Furness
Esri Regular Contributor

Hi @MaríaBencomo 

Glad that improves things, but I'm curious why you're using densify at all. For straight-line segments you shouldn't need to. I could be missing a nuance of your use case though.

0 Kudos
MaríaBencomo
Occasional Contributor

Hi Nicholas.

Now everything works fine. I set 5.0d to maxSegmentLength and, now the amount of point in the json file is equal to the amount of point of the route. 

Geometry pathGeometry = GeometryEngine.densify(new Polyline(new PointCollection(addPoint)), 5.0d);

 

0 Kudos