use of org.locationtech.geogig.osm.internal.MappingRule in project GeoGig by boundlessgeo.
the class WriteOSMMappingEntries method _call.
@Override
protected Void _call() {
Preconditions.checkNotNull(entry);
Preconditions.checkNotNull(mapping);
final File osmMapFolder = command(ResolveOSMMappingLogFolder.class).call();
for (MappingRule rule : mapping.getRules()) {
File file = new File(osmMapFolder, rule.getName());
try {
Files.write(entry.toString(), file, Charsets.UTF_8);
} catch (IOException e) {
throw Throwables.propagate(e);
}
}
File file = new File(osmMapFolder, entry.getPostMappingId().toString());
try {
Files.write(mapping.toString(), file, Charsets.UTF_8);
} catch (IOException e) {
throw Throwables.propagate(e);
}
return null;
}
use of org.locationtech.geogig.osm.internal.MappingRule in project GeoGig by boundlessgeo.
the class OSMExportPG method runInternal.
/**
* Executes the export command using the provided options.
*/
@Override
protected void runInternal(GeogigCLI cli) {
Preconditions.checkNotNull(mappingFile != null, "A data mapping file must be specified");
final Mapping mapping = Mapping.fromFile(mappingFile);
List<MappingRule> rules = mapping.getRules();
checkParameter(!rules.isEmpty(), "No rules are defined in the specified mapping");
for (final MappingRule rule : mapping.getRules()) {
Function<Feature, Optional<Feature>> function = new Function<Feature, Optional<Feature>>() {
@Override
@Nullable
public Optional<Feature> apply(@Nullable Feature feature) {
Optional<Feature> mapped = rule.apply(feature);
if (mapped.isPresent()) {
return Optional.of(mapped.get());
}
return Optional.absent();
}
};
SimpleFeatureType outputFeatureType = rule.getFeatureType();
String path = getOriginTreesFromOutputFeatureType(outputFeatureType);
DataStore dataStore = null;
try {
dataStore = getDataStore();
String tableName = outputFeatureType.getName().getLocalPart();
if (Arrays.asList(dataStore.getTypeNames()).contains(tableName)) {
if (!overwrite) {
throw new CommandFailedException("A table named '" + tableName + "'already exists. Use -o to overwrite");
}
} else {
try {
dataStore.createSchema(outputFeatureType);
} catch (IOException e) {
throw new CommandFailedException("Cannot create new table in database", e);
}
}
final SimpleFeatureSource featureSource = dataStore.getFeatureSource(tableName);
if (!(featureSource instanceof SimpleFeatureStore)) {
throw new CommandFailedException("Could not create feature store. Data source is read only.");
}
final SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
if (overwrite) {
featureStore.removeFeatures(Filter.INCLUDE);
}
ExportOp op = cli.getGeogig().command(ExportOp.class).setFeatureStore(featureStore).setPath(path).setFeatureTypeConversionFunction(function);
try {
op.setProgressListener(cli.getProgressListener()).call();
cli.getConsole().println("OSM data exported successfully to " + tableName);
} catch (IllegalArgumentException iae) {
throw new org.locationtech.geogig.cli.InvalidParameterException(iae.getMessage(), iae);
} catch (GeoToolsOpException e) {
throw new CommandFailedException("Could not export. Error:" + e.statusCode.name(), e);
}
} catch (IOException e) {
throw new IllegalStateException("Cannot connect to database: " + e.getMessage(), e);
} finally {
if (dataStore != null) {
dataStore.dispose();
}
}
}
}
use of org.locationtech.geogig.osm.internal.MappingRule in project GeoGig by boundlessgeo.
the class OSMExportSL method runInternal.
/**
* Executes the export command using the provided options.
*/
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
Preconditions.checkNotNull(mappingFile != null, "A data mapping file must be specified");
final Mapping mapping = Mapping.fromFile(mappingFile);
List<MappingRule> rules = mapping.getRules();
checkParameter(!rules.isEmpty(), "No rules are defined in the specified mapping");
for (MappingRule rule : rules) {
exportRule(rule, cli);
}
}
use of org.locationtech.geogig.osm.internal.MappingRule in project GeoGig by boundlessgeo.
the class OSMExportShp method runInternal.
/**
* Executes the export command using the provided options.
*/
@Override
protected void runInternal(GeogigCLI cli) throws IOException {
Preconditions.checkNotNull(mappingFile != null, "A data mapping file must be specified");
if (args == null || args.isEmpty() || args.size() != 1) {
printUsage(cli);
throw new CommandFailedException();
}
String shapefile = args.get(0);
final File file = new File(shapefile);
final Mapping mapping = Mapping.fromFile(mappingFile);
List<MappingRule> rules = mapping.getRules();
checkParameter(!rules.isEmpty(), "No rules are defined in the specified mapping");
for (MappingRule rule : rules) {
File targetFile = file;
if (rules.size() > 1) {
String name = getNameWithoutExtension(file.getName()) + "_" + rule.getName() + ".shp";
targetFile = new File(file.getParentFile(), name);
}
exportRule(rule, cli, targetFile);
}
}
Aggregations