Is there a way to do geometric operations (Union, substract, etc) on google_maps_flutter polygons?

837 views
Skip to first unread message

Surya Nigrat Datunsolang

unread,
Sep 6, 2019, 4:30:30 AM9/6/19
to Flutter Development (flutter-dev)
I am trying to build an app where the ability to do geometric operations on map polygons is very important.  what I am trying to achieve is as follows:
1. I have shapefiles created with ArcMap which I then converted to json files.
2. I wish to use the data from the json files (by parsing them) to create polygons on google map (using google_maps_flutter), the challenges and progress I have met and dealt with so far in this particular section is:
    a. the coordinate system in the json files is UTM, I have managed to create a function that can convert the UTM coordinates to Decimal Degrees and Degree Minute Second coordinate systems.
    b. I am not sure if polygon system in google_maps_flutter enables the creation of 'rings' (polygons with holes, like donuts... or rings). Since Many of the  Shapefile polygons are in this form, this ability will be pretty                important.
    
3. If I somehow overcome the challenges from point 2, I wish to use the polygons as some sort of area indicators which can be manipulated (substracted, joined together, etc). 
4. if point 3 is possible, I hope to utilize it for following scenarios:
   a. user gets notified when he/she enters a certain area indicated by the polygons (all I know from this is how to compare user current location with the map extents... I dont know how to utilize polygon as extents to compare user's locations with)
   b. user can plot an area (using gps tracking to form a polygon) which then can overlap the polygons from json files and know exactly which area his/her plotted polygon overlaps
   c. if b is possible, then user can use geometric operations to calculate the area size with which his or her plotted polygon overlapped.


For me this is a pretty big undertakings especially since I am just starting with flutter or app dev in general. But this project really gets me excited. I hope anyone can shed some lights on me.

my immediate need is an algorithm which can be used to detect user's presence in an area so I can use it like follows:
Latlang userLoc = getLocation();
Polygon somePolygon = createPolygon();
bool isInArea = areaChecker(userLoc, somePolygon);


Thank You!

Surya Nigrat Datunsolang

unread,
Sep 8, 2019, 2:32:45 AM9/8/19
to Flutter Development (flutter-dev)
I have come across an algorhitm that checks if a point is inside a polygon.. the idea is, if a line is drawn at any direction from the point and the number of times the line intersects edges of the polygon is odd it means the point is inside the polygon. On the other hand if it's even or zero, it means the point is outside of the polygon. the algorhitm is called Ray Casting. There is no dart code for it but I guess it is not too hard to infer it from C++ code I found. 

Surya Nigrat Datunsolang

unread,
Sep 17, 2019, 7:32:44 AM9/17/19
to Flutter Development (flutter-dev)
I hava made a considerable progress with this project. I have successfully created polygons on google maps from Json files thanks to some online services that creates class models from any json structure. I have also been able to achieve my goal to detect user position of being inside or outside of a polygon!
The last hurdle is how to do geometric operations with polygons. This turned out to be a big hurdle since it involves advanced math and I havent found any concrete source code which I can translate to dartlang. However I am very happy that my app is now functional!

What I did so far:

1. I created shapefiles in ArcMap and export them to json/geojson.
2. I used a web service to create model class in dartlang to be used to parse the json into
3. i used the latlong data from the object to create polygons on google map.
4. Using ray casting algo I am able to detect wether a point in map is inside or outside the polygon.

In the future I hope to be able to do geometric operations on these polygons.

I hope this can help anyone doing the same project in the future. I will keep updating this as I progress with the project

Reply all
Reply to author
Forward
0 new messages