/*
 * Copyright 2016 davidstrawn.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package strawn.evariant.rainsorter;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;
import java.io.IOException;
import java.util.List;
import org.geotools.feature.FeatureIterator;
import org.junit.Before;
import org.junit.Test;
import org.junit.Assert;
import org.opengis.feature.simple.SimpleFeature;
import strawn.evariant.rainsorter.data.msashapefile.MSAShapefileLoader;
import strawn.evariant.rainsorter.data.qclcdstations.QCWeatherStationLoader;
import strawn.evariant.rainsorter.data.qclcdstations.QCWeatherStationRecord;
import strawn.evariant.rainsorter.tools.GeometryTools;

/**
 *
 * @author davidstrawn
 * 
 * This class tests our shapefiles, and our station data.
 * Our shapefile has records that define the region covered by an MSA.
 * Using the latitude and longitude from our station data, we can see if a station is in a particular MSA
 */
public class StationAndShapefileIT {
    
    private static final double PORTLAND_LATITUDE = 45.551;
    private static final double PORTLAND_LONGITUDE = -122.409;
    private static final String PORTLAND_FIPS_CODE = "38900";
    
    private FeatureIterator<SimpleFeature> features;
    private List<QCWeatherStationRecord> stations;
    
    @Before
    public void setup() throws IOException {
        features = MSAShapefileLoader.loadFeatures();
        stations = QCWeatherStationLoader.loadRecordsFromDisk();
    }

    /**
     * The static variables are latitude and longitude of a station and portland
     * The test looks for a region that the coordinates are located in, 
     * and makes sure that its FIPS code is the same as that of Portland-Vancouver-Hillsboro, "38900"
     */
    @Test
    public void portlandIsInPortland() {
        while (features.hasNext()) {
            SimpleFeature feature = features.next();
            if(GeometryTools.isPointInRegion(PORTLAND_LONGITUDE, PORTLAND_LATITUDE, feature)) {
                Assert.assertEquals(PORTLAND_FIPS_CODE, feature.getProperty("CBSAFP").getValue().toString());
            }
        }
    }
    
    @Test
    public void allStationsBelongToOnlyOneRegion() {
        
    }
            
}

@@ -638,236 +638,50 @@
 ort 
-com.vividsolutions.jts.geom.Coordinate;%0Aimport com.vividsolutions.jts.geom.GeometryFactory;%0Aimport com.vividsolutions.jts.geom.Point;%0Aimport java.io.IOException;%0Aimport java.util.List;%0Aimport org.geotools.feature.FeatureIterator
+java.io.IOException;%0Aimport java.util.List
 ;%0Aim
@@ -1603,23 +1603,12 @@
 ate 
-FeatureIterator
+List
 %3CSim
@@ -2203,49 +2203,13 @@
     
-while (features.hasNext()) %7B%0A            
+for (
 Simp
@@ -2226,17 +2226,17 @@
 feature 
-=
+:
  feature
@@ -2240,16 +2240,11 @@
 ures
-.next();
+) %7B
 %0A   
@@ -2548,24 +2548,685 @@
 ) %7B%0A        
+for(QCWeatherStationRecord station : stations) %7B%0A            int featureMatchCount = 0;%0A            for (SimpleFeature feature : features) %7B%0A                if(GeometryTools.isPointInRegion(station.longitude, station.latitude, feature)) %7B%0A                    featureMatchCount++;%0A                    if(featureMatchCount %3E 1) %7B%0A                        System.out.println(%22Overmatch Station!:%22 + station.wban + %22, feature:%22 + feature.getAttribute(%22CBSAFP%22).toString());%0A                    %7D%0A                %7D%0A            %7D%0A            if(featureMatchCount == 0) %7B%0A                System.out.println(%22Unmatched Station!:%22 + station.wban);%0A            %7D%0A        %7D
 %0A    %7D%0A     

add second station test