Select to view content in your preferred language

Modifying or pooling ArcGisPoint?

291
4
04-22-2025 06:02 AM
genarus
Emerging Contributor

Here I am again.

I want to move hundreds of objects on the global map using Web-Mercator positions. Apparently you have to use the ArcGisPoint API, but for some reason ArcGisPoint is a class & immutable. So if I want to move lots of objects every frame, I have to create lots of new instances of it. Which leads to an incredible amount of garbage and poor performance.

Hence my question, is there any way to reuse, modify or pool ArcGisPoint? I found another ArcGisPointBuilder, so you can at least modify a point. However, you still have to create a new class for each modification, so it is not more performant. So how would you handle this in scenarios where many objects have to move?

Could any official team member or dev please comment on this?

0 Kudos
4 Replies
AShahbaz
Esri Contributor

You might get some performance gain by using ArcGISMutablePointCollection, but you still wont be able to modify the individual points in the collection. I don't think you can avoid using ArcgisPoint or ArcGISLocationComponent unless you implement the conversion to the engine coordinates yourself (I assume you are using `GeographicToEngine` for the projection).

Since you are using a projected coordinate system, you might be able to keep track of the changes over time and apply the offset without reprojecting to engine coordinates. So in if an object is at (0,0,0) in web mercator at frame 0 and at (1,0,0) in the next frame, you could move the object by one meter toward east in the engine. But my guess is that the objects will start to drift from the actual location and you would have to do a projection every few frames.

Similarly, if the objects are moving in a somewhat predicable manner (e.g. airplanes), you could improve the performance by doing the conversion to engine coordinates less frequently (say once per second). For the frames in-between you would move the object by interpolating between the two calculated locations.   

0 Kudos
genarus
Emerging Contributor

Thank you very much for your feedback! I still have a few follow-up questions.

 

Firstly... why is ArcGisPoint an immutable class at all? And are you trying to change that? Or could you at least imagine to open some Utils so that they do not accept an ArcGisPoint but only raw coordinate parameters in general? E.g. for conversion? Especially for a map framework like ArcGis it would make sense to have an API to efficiently display and move many objects on the map, imagine traffic or simulations. With the current tools and forcing ArcGisPoint, this is simply not possible.

 

On the other hand, you talked about doing the GeopgrahicToEngine conversion yourself. What would that look like? Are there APIs from ArcGis without ArcGisPoint or could I “simply” write such a method myself (if so, how?)?

 

Then on the subject of Web-Mercator, maybe that will solve the problems. If I set the ArcGisMap so that its Origin is the Web-Mercator at position 0,0... then theoretically I could simply assign objects their Web-Mercator as a Unity-HP-Transform or? Then their HP-Transform = the Web-Mercator so they should appear in the right place on the map, right? So for my case I wouldn't need ArcGisPoints let alone ArcGisLocationComponent... would I? Or would I have to convert something again? I hope you understand ^^

0 Kudos
genarus
Emerging Contributor

And another question, there is the ArcGisPointBuilder class. Which supposedly can be used to change ArcGisPoints (according to the docs). This class has the method ClearGeometry, which supposedly deletes or replaces the point from the class. Couldn't this be used to change ArcGisPoints efficiently? Or would that also allocate a new one each time instead of changing it?

0 Kudos
AShahbaz
Esri Contributor



why is ArcGisPoint an immutable class at all? And are you trying to change that? Or could you at least imagine to open some Utils so that they do not accept an ArcGisPoint but only raw coordinate parameters in genera

Unfortunately that's a requirement from our backend that does the bulk of conversion. Even if we provide an api that takes individual coordinates, under the hood, we would have to create new points. I am not aware of any plans to change that at the moment.

Are there APIs from ArcGis without ArcGisPoint or could I “simply” write such a method myself (if so, how?)

I am not very familiar with this. My guess is it won't be very easy (especially because you are using a global world and web mercator positions). You probably need to get to Cartesian coordinates, transform those to the origin of Unity, possibly rebase with HP transform, and calculate the offsets to be applied the previous location at each frame. 

If I set the ArcGisMap so that its Origin is the Web-Mercator at position 0,0... then theoretically I could simply assign objects their Web-Mercator as a Unity-HP-Transform or? Then their HP-Transform = the Web-Mercator so they should appear in the right place on the map, right?

The changes in Mercator coordinates wont translate 1-to-1 to the same offsets in a global mode map. You need to take into account the spherical/ellipsoid shape of the earth.

And another question, there is the ArcGisPointBuilder class. Which supposedly can be used to change ArcGisPoints (according to the docs). This class has the method ClearGeometry, which supposedly deletes or replaces the point from the class. Couldn't this be used to change ArcGisPoints efficiently? Or would that also allocate a new one each time instead of changing it?

From what I see it doesn't allocates new memory for modifying, but I think you will need to eventually use `ToGeometry` to get to the point, which seems to create a new arcgis point. So I doubt that will help you.

 

Is your main concern with creating new points a memory limitation? Generally those should be garbage collected, or are you experiencing a memory leak over time? My suggestion would be to consider whether you need to convert the locations every frame. As I mentioned before, you might be able to limit the number of times you perform GeographicToEngine, and in the frames between a pair of calculations you could move the object smoothly from point A to B.  

0 Kudos