GeoUtils { public static boolean checkPointWithMultiPolygon( double longitude, double latitude, Geometry geometry ) { try { boolean contains = false; Point point = getGeoJsonPoint( longitude, latitude ); FeatureType featureType = FeatureType.getTypeFromName(geometry.getGeometryType()); if ( point != null && point.isValid() ) { if ( featureType == FeatureType.POLYGON ) { Polygon polygon = (Polygon) geometry; contains = polygon.contains( point ); } else if ( featureType == FeatureType.MULTI_POLYGON ) { MultiPolygon multiPolygon = (MultiPolygon) geometry; contains = multiPolygon.contains( point ); } } return contains; } catch ( Exception ex ) { return false; } }  static double[] getBoxShape( double longitude, double latitude, double distance ); static double getDistanceBetweenTwoPoints( Point2D from, Point2D to); static Point getGeoJsonPoint( double longitude, double latitude ); static boolean checkGeoJsonPointValid( double longitude, double latitude ); static boolean checkPointWithMultiPolygon( double longitude, double latitude,
        Geometry geometry ); static String replaceUnsafeSvgText(String svg ); static Geometry getGeometryFromCoordinatesAndType( FeatureType featureType, String coordinates ); static String getCoordinatesFromGeometry( Geometry geometry ); static final int SRID; }
@Test public void testVerifyPointIsWithinPolygon() throws IOException { String downtownOslo = TestResourceUtils.getFileContent( "gis/downtownOslo.json" ); Geometry g = new GeometryJSON().read( downtownOslo ); boolean result = GeoUtils.checkPointWithMultiPolygon( 10.746517181396484, 59.91080384720672, g ); assertTrue( result ); result = GeoUtils.checkPointWithMultiPolygon( 10.755915641784668, 59.9139664757207, g ); assertFalse( result ); }
@Test public void testVerifyPointIsWithinMultiPolygon() throws IOException { String downtownOslo = TestResourceUtils.getFileContent( "gis/brasilMultiPolygon.json" ); Geometry g = new GeometryJSON().read( downtownOslo ); boolean result = GeoUtils.checkPointWithMultiPolygon( -43.96728515625, -16.699340234594537, g ); assertTrue( result ); result = GeoUtils.checkPointWithMultiPolygon( -43.681640625, -18.698285474146807, g ); assertFalse( result ); }