0

I'm developíng an App in Android Studio using Kotlin with Minimun API of 21 -Lollipop- that works totally offline, and i need to test if a point (decimal degrees for lat and long) that the users write (Or that i get from GPS offline location) is inside certain polygon in a ShapeFile (Or any geo-file, it doesnt matter the type).

For example. The Shapefile has 2 polygons with name A and B. In the first page of the App the user have to select if they want to work with polygon A or B. After that the user has the option to write some decimal coordinates or to use the GPS of his phone to get a coordinate, and i have to test if those coordinates are inside the polygon that the users selected in the beginning (Polygon A). I'm working with WGS84.

Is there a package or something that are capable of doing that spatial intersection with the geofile and the point?

Example of polygons in Shapefile

1 Answer 1

0

Try android-maps-utils library PolyUtil.containsLocation(): https://github.com/googlemaps/android-maps-utils/blob/fc2b9643f8a8ea37433e77ca9857368e15d229d1/library/src/main/java/com/google/maps/android/PolyUtil.java#L91

3
  • Thanks!, i'm looking at the function and the polygon has a type List<LatLng>. Do you know how to extract from the shapefile (I can convert the file to any geo file if it's neccesary) the list of points? Dec 24, 2022 at 1:28
  • The same library also has utilities to read in GeoJSON and KML, so if you can convert to one of those formats it might help. Otherwise, if it's an ESRI shape file I believe ESRI has an SDK that could be used to extract the lat/lons for the points. Dec 24, 2022 at 2:18
  • 1
    Hey @sean-barbeau, i found a GeoJsonParser in the official google maps doc and after that i was able to use PolyUtil.containsLocation(). Thanks! Dec 27, 2022 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.