Package org.locationtech.geogig.geotools.cli.porcelain

Source Code of org.locationtech.geogig.geotools.cli.porcelain.AbstractGeoJsonCommand

/* Copyright (c) 2013-2014 Boundless and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/org/documents/edl-v10.html
*
* Contributors:
* Juan Marin (Boundless) - initial implementation
*/
package org.locationtech.geogig.geotools.cli.porcelain;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.geotools.data.DataStore;
import org.geotools.data.memory.MemoryDataStore;
import org.geotools.feature.FeatureCollection;
import org.geotools.geojson.feature.FeatureJSON;
import org.locationtech.geogig.cli.AbstractCommand;
import org.locationtech.geogig.cli.CLICommand;
import org.locationtech.geogig.cli.CommandFailedException;

public abstract class AbstractGeoJsonCommand extends AbstractCommand implements CLICommand {

    protected DataStore getDataStore(String geoJSON) throws FileNotFoundException, IOException {
        try {
            File geoJsonfile = new File(geoJSON);
            checkParameter(geoJsonfile.exists(), "File does not exist '%s'", geoJsonfile);
            InputStream in = new FileInputStream(geoJsonfile);
            FeatureJSON fjson = new FeatureJSON();
            @SuppressWarnings("rawtypes")
            FeatureCollection fc = fjson.readFeatureCollection(in);
            @SuppressWarnings("unchecked")
            DataStore dataStore = new MemoryDataStore(fc);
            return dataStore;
        } catch (IOException ioe) {
            throw new CommandFailedException("Error opening GeoJSON: " + ioe.getMessage(), ioe);
        }
    }

}
TOP

Related Classes of org.locationtech.geogig.geotools.cli.porcelain.AbstractGeoJsonCommand

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.