Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 1758 flex investigate integration of geojson files #1784

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
5 changes: 5 additions & 0 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -55,6 +69,7 @@ public class GtfsFeedLoader {
*/
private final List<Class<? extends FileValidator>> multiFileValidatorsWithParsingErrors =
new ArrayList<>();
private DataStore dataStore;

public GtfsFeedLoader(
ImmutableList<Class<? extends GtfsTableDescriptor<?>>> tableDescriptorClasses) {
Expand Down Expand Up @@ -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(
() -> {
Expand Down Expand Up @@ -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<SimpleFeature> 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<String, Object> 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<SimpleFeature> 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) {
Expand Down
Loading