diff --git a/build.gradle b/build.gradle index 2025f48341..44b50df79e 100644 --- a/build.gradle +++ b/build.gradle @@ -43,9 +43,14 @@ allprojects { version scmVersion.version repositories { + maven { + url 'https://repo.osgeo.org/repository/release/' + } mavenCentral() } +} + tasks.withType(JavaCompile) { // All Java projects should target the same compatibility version. sourceCompatibility = JavaVersion.VERSION_11 @@ -76,7 +81,6 @@ allprojects { // Any project with a test should be added to test report aggregation in the root project. rootProject.dependencies.add('testReportAggregation', project) } -} subprojects { apply plugin: 'java' diff --git a/core/build.gradle b/core/build.gradle index cccd38adc9..5004be7d83 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -42,6 +42,11 @@ dependencies { implementation 'com.googlecode.libphonenumber:libphonenumber:8.12.13' implementation 'com.google.flogger:flogger:0.6' implementation 'io.github.classgraph:classgraph:4.8.146' + implementation 'org.geotools:gt-main:31.2' + implementation 'org.geotools:gt-shapefile:31.2' + implementation 'org.geotools:gt-geojson:31.2' + implementation 'org.geotools:gt-api:31.2' + implementation 'org.locationtech.jts:jts-core:1.19.0' testImplementation 'com.google.flogger:flogger-system-backend:0.6' testImplementation group: 'junit', name: 'junit', version: '4.13' testImplementation "com.google.truth:truth:1.0.1" diff --git a/core/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFeedLoader.java b/core/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFeedLoader.java index 1edb051184..c374deb3ee 100644 --- a/core/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFeedLoader.java +++ b/core/src/main/java/org/mobilitydata/gtfsvalidator/table/GtfsFeedLoader.java @@ -18,6 +18,9 @@ import com.google.common.collect.ImmutableList; import com.google.common.flogger.FluentLogger; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; @@ -30,6 +33,17 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; + +import org.geotools.api.data.DataStore; +import org.geotools.api.data.FileDataStore; +import org.geotools.api.data.FileDataStoreFinder; +import org.geotools.api.data.SimpleFeatureSource; +import org.geotools.feature.FeatureIterator; +import org.geotools.geojson.*; +import org.geotools.api.feature.simple.SimpleFeature; +import org.geotools.data.simple.SimpleFeatureCollection; +import org.geotools.data.simple.SimpleFeatureIterator; +import org.geotools.geojson.feature.FeatureJSON; import org.mobilitydata.gtfsvalidator.input.GtfsInput; import org.mobilitydata.gtfsvalidator.notice.NoticeContainer; import org.mobilitydata.gtfsvalidator.notice.RuntimeExceptionInLoaderError; @@ -55,6 +69,7 @@ public class GtfsFeedLoader { */ private final List> multiFileValidatorsWithParsingErrors = new ArrayList<>(); + private DataStore dataStore; public GtfsFeedLoader( ImmutableList>> tableDescriptorClasses) { @@ -102,7 +117,11 @@ public GtfsFeedContainer loadAndValidate( for (String filename : gtfsInput.getFilenames()) { GtfsTableDescriptor tableDescriptor = remainingDescriptors.remove(filename.toLowerCase()); if (tableDescriptor == null) { - noticeContainer.addValidationNotice(new UnknownFileNotice(filename)); + if (filename.equals("locations.geojson")) { + readGeoJsonFile(); + } else { + noticeContainer.addValidationNotice(new UnknownFileNotice(filename)); + } } else { loaderCallables.add( () -> { @@ -178,6 +197,71 @@ public GtfsFeedContainer loadAndValidate( } } + private void readGeoJsonFile() { + File file = new File("/Users/jingsi/Downloads/browncounty-mn-us--flex-v2/locations.geojson"); + + FeatureJSON fjson = new FeatureJSON(); + + // Read the GeoJSON file + try (FileReader reader = new FileReader(file)) { + SimpleFeatureCollection featureCollection = (SimpleFeatureCollection) fjson.readFeatureCollection(reader); + + // Iterate over the features and print them + try (FeatureIterator features = featureCollection.features()) { + while (features.hasNext()) { + SimpleFeature feature = features.next(); + System.out.println("Feature: "+feature); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + +// SimpleFeatureIterator iterator = null; +// try { +// FileDataStore dataStore = FileDataStoreFinder.getDataStore(geoJsonFile); +// +// +// Map map = new HashMap<>(); +// try { +// map.put("url", geoJsonFile.toURI().toURL()); +// System.out.println("url: " + map.get("url").toString()); +// } catch (MalformedURLException e) { +// throw new RuntimeException(e); +// } +// +// DataStore dataStore = null; +// FeatureIterator iterator = null; +// try { +// dataStore = DataStoreFinder.getDataStore(map); +// if (dataStore == null) { +// throw new IOException("Could not connect to data store"); +// } + +// String typeName = dataStore.getTypeNames()[0]; +// SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName); +// SimpleFeatureCollection collection = featureSource.getFeatures(); +// iterator = collection.features(); +// +// while (iterator.hasNext()) { +// SimpleFeature feature = iterator.next(); +// System.out.println("Feature ID: " + feature.getID()); +// System.out.println("Geometry: " + feature.getDefaultGeometry()); +// System.out.println("Properties: " + feature.getProperties()); +// } +// +// } catch (IOException e) { +// e.printStackTrace(); +// } finally { +// if (iterator != null) { +// iterator.close(); +// } +// if (dataStore != null) { +// dataStore.dispose(); +// } +// } + } + /** Adds a ThreadExecutionError to the notice container. */ private static void addThreadExecutionError( ExecutionException e, NoticeContainer noticeContainer) {