@@ -0,0 +1,2937 @@
+package org.filteredpush.qc.georeference;%0A%0Aimport com.vividsolutions.jts.geom.Coordinate;%0Aimport com.vividsolutions.jts.geom.GeometryFactory;%0Aimport com.vividsolutions.jts.geom.MultiPolygon;%0Aimport com.vividsolutions.jts.geom.Point;%0Aimport org.filteredpush.qc.georeference.util.GEOUtil;%0Aimport org.geotools.data.FileDataStore;%0Aimport org.geotools.data.FileDataStoreFinder;%0Aimport org.geotools.data.simple.SimpleFeatureCollection;%0Aimport org.geotools.data.simple.SimpleFeatureIterator;%0Aimport org.geotools.data.simple.SimpleFeatureSource;%0Aimport org.geotools.filter.text.cql2.CQLException;%0Aimport org.geotools.filter.text.ecql.ECQL;%0Aimport org.geotools.geometry.jts.JTSFactoryFinder;%0Aimport org.opengis.feature.simple.SimpleFeature;%0Aimport org.opengis.filter.Filter;%0A%0Aimport java.io.IOException;%0Aimport java.net.URL;%0Aimport java.util.HashMap;%0Aimport java.util.Iterator;%0Aimport java.util.Map;%0A%0A/**%0A * Created by lowery on 6/12/17.%0A */%0Apublic class GEOUtilTester %7B%0A    private URL countryShapeFile = GEOUtil.class.getResource(%22/org.filteredpush.kuration.services/ne_10m_admin_0_countries.shp%22);%0A%0A    private final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(null);%0A    private Map%3CString, MultiPolygon%3E polys = new HashMap%3C%3E();%0A%0A    public GEOUtilTester() throws IOException %7B%0A        FileDataStore store = null;%0A        try %7B%0A            store = FileDataStoreFinder.getDataStore(countryShapeFile);%0A            SimpleFeatureSource featureSource = store.getFeatureSource();%0A%0A            SimpleFeatureIterator iter = featureSource.getFeatures().features();%0A%0A            while (iter.hasNext()) %7B%0A                SimpleFeature feature = iter.next();%0A                String name = (String) feature.getAttribute(%22NAME%22);%0A                MultiPolygon poly = (MultiPolygon) feature.getAttribute(%22the_geom%22);%0A%0A                polys.put(name, poly);%0A            %7D%0A        %7D catch (IOException e) %7B%0A            throw new RuntimeException(%22Error loading shapefile: %22 + countryShapeFile.getPath(), e);%0A        %7D finally %7B%0A            if (store!=null) %7B store.dispose(); %7D%0A        %7D%0A%0A    %7D%0A%0A    public boolean pointInCountry(String country, double latitude, double longitude) %7B%0A        MultiPolygon polygon = polys.get(country);%0A        return polygon.contains(geometryFactory.createPoint(new Coordinate(longitude, latitude)));%0A    %7D%0A%0A%0A    public static void main(String%5B%5D args) throws IOException %7B%0A%0A        GEOUtilTester tester = new GEOUtilTester();%0A%0A        // Barrow, Alaska%0A        double originalLng = -156.766389d;%0A        double originalLat = 71.295556d;%0A%0A        long startTime = System.currentTimeMillis();%0A%0A        //boolean result = GEOUtil.isPointInCountry(%22United States%22, originalLat, originalLng);%0A        boolean result = tester.pointInCountry(%22United States%22, originalLat, originalLng);%0A        %0A        System.out.println(%22result: %22 + result + %22, time: %22 + (System.currentTimeMillis() - startTime));%0A    %7D%0A%7D%0A

Test of using hashmap of country to polygon for geospatial queries