google / ground-android

Ground mobile data collection app for Android
http://groundplatform.org
Apache License 2.0
245 stars 118 forks source link

[Code health] Harmonize geometry representation #929

Closed gino-m closed 2 years ago

gino-m commented 3 years ago

Shapes are represented in remote db in features as point (GeoPoint), geoJson (string) and geometry (map). There's also some confusion in the implementation about geometries vs LOIs. This design wasn't intentional and we can improve it.

Ideas:

scolsen commented 2 years ago

Am I right in thinking "Moving all to a map" means we'll unify them all under Geometry?

Point : Geometry
Polygon : Geometry
GeoJson : Geometry
gino-m commented 2 years ago

Am I right in thinking "Moving all to a map" means we'll unify them all under Geometry?

Point : Geometry
Polygon : Geometry
GeoJson : Geometry

Sorry, our messages crossed each other; I removed the bit about Map and tried to add some more clarity. PTAL!

scolsen commented 2 years ago

Instead of extending LocationOfInterest, have it contain an arbitrary Geometry

This is a definite yes.

Define generic geometry types independent of Ground model (perhaps import GeoTools?)

I think we should probably do this too, but I'm not sure if we should use GeoTools or not—I'd like to refactor LOIs first sticking with our own representation then figure it out from there.

gino-m commented 2 years ago

Define generic geometry types independent of Ground model (perhaps import GeoTools?)

I think we should probably do this too, but I'm not sure if we should use GeoTools or not—I'd like to refactor LOIs first sticking with our own representation then figure it out from there.

Good idea. Not sure either, but I see GeoTools has a permission license (LGPL), and includes [de]serialization of their model to/from GeoJSON.

scolsen commented 2 years ago

Yeah, I looked at it a bit more and it seems like its very robust. At the moment, I'm just trying to get gradle set up to try it out.

gino-m commented 2 years ago

We spoke. I'll summarize here:

@google/ground-maintainers FYI.

gino-m commented 2 years ago

@scolsen Before I forget - do you think we should support Polygon as well? The polygon drawing tool will only be capable of drawing a single polygon, but we could just represent that as a MultiPolygon with one element. Not sure what's better here. Any thoughts?

scolsen commented 2 years ago

@scolsen Before I forget - do you think we should support Polygon as well? The polygon drawing tool will only be capable of drawing a single polygon, but we could just represent that as a MultiPolygon with one element. Not sure what's better here. Any thoughts?

I think it comes down to whether or not we want to support re-editing. If we cast them to multipolygons users won't be able to modify the shape of the polygon or re-draw it after save—if we only use muiltipolygons, there's no way we'd be able to tell which one should be editable—that said, we could just generally let them edit any "shell" of a multipolygon (afaict, it's not possible to go from multipolgon -> List)

gino-m commented 2 years ago

Iiuc, MultiPolygons with only one Polygon are equivalent to a single Polygon. We could always check whether there's only one to allow editing.

gino-m commented 2 years ago

Hi @scolsen! What else is left? Are rendering, local persistence, and editing all moved over to the new model? If not maybe we should split this into separate issues to make them easier to assign?

JSunde commented 2 years ago

Oh I think there's more to this bug than I realized, I just saw the "TODO(#929)" and marked as fixed after my change, but I think there is still more to be done.

gino-m commented 2 years ago

There are three steps left, all assigned to @scolsen:

@scolsen @JSunde @shobhitagarwal1612 Would you be able to collaborate on these so feature work on the map can be unblocked?

JSunde commented 2 years ago

Yea I think that sounds good.

Right now the GoogleMapsFragment should be able to render Points, Polygons, and MultiPolygons. I think we still need to add support for:

Also I think we need to update the MapContainerViewModel and PolygonDrawingViewModel to create LOIs containing those geometries, instead of MapPins and MapPolygons.

One question, @gino-m do we currently have anything that we were previously rendering that is equivalent to the LinearRing and LinearString geometries?

gino-m commented 2 years ago

LinearRing is basically a polygon w/no holes. I don't think we need to render those. LinearString was rendered as part of the polygon drawing feature (for the an unfinished polygon being drawn)

scolsen commented 2 years ago

LinearRing is basically a polygon w/no holes. I don't think we need to render those. LinearString was rendered as part of the polygon drawing feature (for the an unfinished polygon being drawn)

ah, that's right, we called it PolyLine before i think

JSunde commented 2 years ago

I just merged the updates to the PolygonDrawingViewModel, #1279, to remove the MapPolygon and render a LineString for incomplete polygons and convert them to a LinearRing when they are completed.

I think that may have been the last of the rendering changes required.

Let me know if you think there is anything I missed! Otherwise I think we can probably close this issue.

scolsen commented 2 years ago

I think we can consider this one closed!

gino-m commented 2 years ago

Whoohoo! Great work!!!