Map<String, Serializable> params = new HashMap<String, Serializable>();
params.put("url", outputShapefile.toURI().toURL());
params.put("create spatial index", Boolean.TRUE);
ShapefileDataStore dataStore = (ShapefileDataStore)dataStoreFactory.createNewDataStore(params);
dataStore.forceSchemaCRS(DefaultGeographicCRS.WGS84);
SimpleFeatureType STOP_TYPE = DataUtilities.createType(
"Stop",
"location:Point:srid=4326," +
"name:String," +
"code:String," +
"desc:String," +
"id:String," +
"agency:String"
);
SimpleFeatureType ROUTE_TYPE = DataUtilities.createType(
"Route", // <- the name for our feature type
"route:LineString:srid=4326," +
"patternName:String," +
"shortName:String," +
"longName:String," +
"desc:String," +
"type:String," +
"url:String," +
"routeColor:String," +
"routeTextColor:String," +
"agency:String"
);
SimpleFeatureCollection collection = FeatureCollections.newCollection();
SimpleFeatureBuilder featureBuilder = null;
if(gisExport.type.equals(GisUploadType.STOPS))
{
dataStore.createSchema(STOP_TYPE);
featureBuilder = new SimpleFeatureBuilder(STOP_TYPE);
List<Stop> stops = Stop.find("agency in (:ids)").bind("ids", gisExport.agencies).fetch();
for(Stop s : stops)
{
featureBuilder.add(s.locationPoint());
featureBuilder.add(s.stopName);
featureBuilder.add(s.stopCode);
featureBuilder.add(s.stopDesc);
featureBuilder.add(s.gtfsStopId);
featureBuilder.add(s.agency.name);
SimpleFeature feature = featureBuilder.buildFeature(null);
collection.add(feature);
}
}
else if(gisExport.type.equals(GisUploadType.ROUTES))
{
dataStore.createSchema(ROUTE_TYPE);
featureBuilder = new SimpleFeatureBuilder(ROUTE_TYPE);
List<Route> routes = Route.find("agency in (:ids)").bind("ids", gisExport.agencies).fetch();
// check for duplicates
// HashMap<String, Boolean> existingRoutes = new HashMap<String,Boolean>();
for(Route r : routes)
{
// String routeId = r.routeLongName + "_" + r.routeDesc + "_ " + r.phone.id;
//
// if(existingRoutes.containsKey(routeId))
// continue;
// else
// existingRoutes.put(routeId, true);
List<TripPattern> patterns = TripPattern.find("route = ?", r).fetch();
for(TripPattern tp : patterns)
{
if(tp.shape == null)
continue;
featureBuilder.add(tp.shape.shape);
featureBuilder.add(tp.name);
featureBuilder.add(r.routeShortName);
featureBuilder.add(r.routeLongName);
featureBuilder.add(r.routeDesc);
if(r.routeType != null)
featureBuilder.add(r.routeType.toString());
else
featureBuilder.add("");
featureBuilder.add(r.routeUrl);
featureBuilder.add(r.routeColor);
featureBuilder.add(r.routeTextColor);
featureBuilder.add(r.agency.name);
SimpleFeature feature = featureBuilder.buildFeature(null);
collection.add(feature);
}
}
}
else
throw new Exception("Unknown export type.");
Transaction transaction = new DefaultTransaction("create");
String typeName = dataStore.getTypeNames()[0];
SimpleFeatureSource featureSource = dataStore.getFeatureSource(typeName);
if (featureSource instanceof SimpleFeatureStore)
{
SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;