Java Code Examples for org.geotools.data.DataStore#getTypeNames()

The following examples show how to use org.geotools.data.DataStore#getTypeNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeoMesaGeoIndexer.java    From rya with Apache License 2.0 6 votes vote down vote up
private static SimpleFeatureType getStatementFeatureType(final DataStore dataStore) throws IOException, SchemaException {
    SimpleFeatureType featureType;

    final String[] datastoreFeatures = dataStore.getTypeNames();
    if (Arrays.asList(datastoreFeatures).contains(FEATURE_NAME)) {
        featureType = dataStore.getSchema(FEATURE_NAME);
    } else {
        final String featureSchema = SUBJECT_ATTRIBUTE + ":String," //
                + PREDICATE_ATTRIBUTE + ":String," //
                + OBJECT_ATTRIBUTE + ":String," //
                + CONTEXT_ATTRIBUTE + ":String," //
                + GEOMETRY_ATTRIBUTE + ":Geometry:srid=4326;geomesa.mixed.geometries='true'";
        featureType = SimpleFeatureTypes.createType(FEATURE_NAME, featureSchema);
        dataStore.createSchema(featureType);
    }
    return featureType;
}
 
Example 2
Source File: GeoWaveGeoIndexer.java    From rya with Apache License 2.0 6 votes vote down vote up
private static SimpleFeatureType getStatementFeatureType(final DataStore dataStore) throws IOException, SchemaException {
    SimpleFeatureType featureType;

    final String[] datastoreFeatures = dataStore.getTypeNames();
    if (Arrays.asList(datastoreFeatures).contains(FEATURE_NAME)) {
        featureType = dataStore.getSchema(FEATURE_NAME);
    } else {
        featureType = DataUtilities.createType(FEATURE_NAME,
            SUBJECT_ATTRIBUTE + ":String," +
            PREDICATE_ATTRIBUTE + ":String," +
            OBJECT_ATTRIBUTE + ":String," +
            CONTEXT_ATTRIBUTE + ":String," +
            GEOMETRY_ATTRIBUTE + ":Geometry:srid=4326," +
            GEO_ID_ATTRIBUTE + ":String");

        dataStore.createSchema(featureType);
    }
    return featureType;
}
 
Example 3
Source File: ElasticDataStoreIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testConstructionWithHostAndPortAndIndex() throws IOException {
    Map<String,Serializable> params = createConnectionParams();
    String host = ElasticDataStoreFactory.getValue(ElasticDataStoreFactory.HOSTNAME, params);
    Integer port = ElasticDataStoreFactory.getValue(ElasticDataStoreFactory.HOSTPORT, params);
    String indexName = ElasticDataStoreFactory.getValue(ElasticDataStoreFactory.INDEX_NAME, params);

    DataStore dataStore = new ElasticDataStore(host, port, indexName);
    String[] typeNames = dataStore.getTypeNames();
    assertTrue(typeNames.length > 0);
}
 
Example 4
Source File: FeatureFigureEditorApp.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
private static FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource(File file) throws IOException {
    Map<String, Object> map = new HashMap<String, Object>();
    map.put(ShapefileDataStoreFactory.URLP.key, file.toURI().toURL());
    map.put(ShapefileDataStoreFactory.CREATE_SPATIAL_INDEX.key, Boolean.TRUE);
    DataStore shapefileStore = DataStoreFinder.getDataStore(map);
    String typeName = shapefileStore.getTypeNames()[0]; // Shape files do only have one type name
    FeatureSource<SimpleFeatureType, SimpleFeature> featureSource;
    featureSource = shapefileStore.getFeatureSource(typeName);
    return featureSource;
}
 
Example 5
Source File: ElasticDataStoreIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetNamesByAlias() throws IOException {
    Map<String,Serializable> params = createConnectionParams();
    params.put(ElasticDataStoreFactory.INDEX_NAME.key, indexName + "_alias");

    ElasticDataStoreFactory factory = new ElasticDataStoreFactory();
    DataStore dataStore = factory.createDataStore(params);
    String[] typeNames = dataStore.getTypeNames();
    assertTrue(typeNames.length > 0);
}
 
Example 6
Source File: ElasticDataStoreIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testGetNames() throws IOException {
    Map<String,Serializable> params = createConnectionParams();

    ElasticDataStoreFactory factory = new ElasticDataStoreFactory();
    DataStore dataStore = factory.createDataStore(params);
    String[] typeNames = dataStore.getTypeNames();
    assertTrue(typeNames.length > 0);
}
 
Example 7
Source File: ElasticDataStoreIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testConstructionWithProxyClientAndIndex() throws IOException {
    Map<String,Serializable> params = createConnectionParams();
    String host = ElasticDataStoreFactory.getValue(ElasticDataStoreFactory.HOSTNAME, params);
    Integer port = ElasticDataStoreFactory.getValue(ElasticDataStoreFactory.HOSTPORT, params);
    String indexName = ElasticDataStoreFactory.getValue(ElasticDataStoreFactory.INDEX_NAME, params);

    HttpHost httpHost = new HttpHost(host, port, "http");
    RestClient client = RestClient.builder(httpHost).build();

    DataStore dataStore = new ElasticDataStore(client, client, indexName, false);
    String[] typeNames = dataStore.getTypeNames();
    assertTrue(typeNames.length > 0);
}
 
Example 8
Source File: ElasticDataStoreIT.java    From elasticgeo with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testConstructionWithClientAndIndex() throws IOException {
    Map<String,Serializable> params = createConnectionParams();
    String host = ElasticDataStoreFactory.getValue(ElasticDataStoreFactory.HOSTNAME, params);
    Integer port = ElasticDataStoreFactory.getValue(ElasticDataStoreFactory.HOSTPORT, params);
    String indexName = ElasticDataStoreFactory.getValue(ElasticDataStoreFactory.INDEX_NAME, params);

    HttpHost httpHost = new HttpHost(host, port, "http");
    RestClient client = RestClient.builder(httpHost).build();

    DataStore dataStore = new ElasticDataStore(client, indexName);
    String[] typeNames = dataStore.getTypeNames();
    assertTrue(typeNames.length > 0);
}
 
Example 9
Source File: DataSourceInfoTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/** Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getFeatures()}. */
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void testGetFeatures() {
    URL url =
            SLDEditorFile.class
                    .getClassLoader()
                    .getResource("point/sld/shp/sld_cookbook_point.shp");

    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);

        DataSourceInfo dsInfo = new DataSourceInfo();

        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();

        assertNull(dsInfo.getFeatures());
        dsInfo.setSchema(schema);

        assertNull(dsInfo.getFeatures());
        dsInfo.setDataStore(dataStore);

        assertTrue(dsInfo.getFeatures() != null);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
Example 10
Source File: DataSourceInfoTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getGeometryFieldName()}.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void testGetGeometryFieldName() {
    URL url =
            SLDEditorFile.class
                    .getClassLoader()
                    .getResource("point/sld/shp/sld_cookbook_point.shp");

    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);

        DataSourceInfo dsInfo = new DataSourceInfo();

        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();

        assertNull(dsInfo.getGeometryFieldName());
        dsInfo.setSchema(schema);

        assertEquals("the_geom", dsInfo.getGeometryFieldName());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
Example 11
Source File: DataSourceInfoTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.datasource.impl.DataSourceInfo#getPropertyDescriptorList()}.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void testGetPropertyDescriptorList() {
    URL url =
            SLDEditorFile.class
                    .getClassLoader()
                    .getResource("point/sld/shp/sld_cookbook_point.shp");

    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);

        DataSourceInfo dsInfo = new DataSourceInfo();

        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();

        assertNull(dsInfo.getPropertyDescriptorList());
        dsInfo.setSchema(schema);

        Collection<PropertyDescriptor> fieldList = dsInfo.getPropertyDescriptorList();

        assertTrue(fieldList.size() == 3);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
Example 12
Source File: DataSourceInfoTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getFeatureStore()}. Test
 * method for {@link
 * com.sldeditor.datasource.impl.DataSourceInfo#setSchema(org.opengis.feature.type.FeatureType)}.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void testGetFeatureStore() {
    URL url =
            SLDEditorFile.class
                    .getClassLoader()
                    .getResource("point/sld/shp/sld_cookbook_point.shp");

    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);

        DataSourceInfo dsInfo = new DataSourceInfo();

        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();
        dsInfo.setSchema(schema);

        assertNull(dsInfo.getFeatureStore());
        dsInfo.setDataStore(dataStore);

        FeatureStore<SimpleFeatureType, SimpleFeature> featureStore = dsInfo.getFeatureStore();

        assertTrue(featureStore != null);
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
Example 13
Source File: DataSourceInfoTest.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Test method for {@link com.sldeditor.datasource.impl.DataSourceInfo#getFeatureCollection()}.
 */
@SuppressWarnings({"unchecked", "rawtypes"})
@Test
public void testGetFeatureCollection() {
    URL url =
            SLDEditorFile.class
                    .getClassLoader()
                    .getResource("point/sld/shp/sld_cookbook_point.shp");

    Map map = new HashMap();
    map.put("url", url);
    DataStore dataStore;
    try {
        dataStore = DataStoreFinder.getDataStore(map);

        DataSourceInfo dsInfo = new DataSourceInfo();

        String typeName = dataStore.getTypeNames()[0];
        dsInfo.setTypeName(typeName);
        SimpleFeatureSource source = dataStore.getFeatureSource(typeName);
        SimpleFeatureType schema = source.getSchema();

        assertNull(dsInfo.getGeometryFieldName());
        dsInfo.setSchema(schema);

        assertEquals("the_geom", dsInfo.getGeometryFieldName());
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
 
Example 14
Source File: ShapeFileParserGDAL.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public List<TableDef> getTablesDefs() throws Exception {
	DataStore dataStore = null;
	List<ColumnDef> columns = null;
	TableDef onlytable = null;
	Set<Key> primkeys = new HashSet<Key>();
	List<TableDef> tables = new ArrayList<TableDef>();
	try {
		Map<String, URL> connect = new HashMap<String, URL>();
		connect.put("url", shapefile.toURI().toURL());
		dataStore = DataStoreFinder.getDataStore(connect);
		String[] typeNames = dataStore.getTypeNames();
		for (int i = 0; i < typeNames.length; ++i) {
			String typeName = typeNames[i];
			FeatureSource<?, ?> featureSource = dataStore.getFeatureSource(typeName);

			FeatureType ft = featureSource.getSchema();
			columns = new ArrayList<ColumnDef>();
			for (PropertyDescriptor property : ft.getDescriptors()) {

				Identifier identifier = Identifier.createDelimited(property.getName().getLocalPart());
				DataType datatype = TableDefUtils
						.TranslateDataTypeToSQLType((property.getType().getBinding().getName()));
				ColumnDef col = new ColumnDef(identifier, datatype, property.isNillable());
				columns.add(col);
			}
			// Identifier identifier = Identifier.createDelimited("gid");
			// ColumnDef col = new ColumnDef(identifier,
			// TranslateDataTypeToSQLType("Int"), false);
			// columns.add(col);
			// primkeys.add(Key.create(identifier));
			TableName tablename = TableName.create(null, null,
					Identifier.create(true, dataStore.getTypeNames()[0]));
			onlytable = new TableDef(tablename, columns, null, primkeys, new HashSet<ForeignKey>());
			tables.add(onlytable);
		}

	} catch (Throwable e) {
		throw new Exception(e.getMessage());
	} finally {
		dataStore.dispose();

	}
	return tables;

}
 
Example 15
Source File: ShapeFileParser.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public List<TableDef> getTablesDefs() throws Exception {
	DataStore dataStore = null;
	List<ColumnDef> columns = null;
	TableDef onlytable = null;
	Set<Key> primkeys = new HashSet<Key>();
	List<TableDef> tables = new ArrayList<TableDef>();
	try {
		Map<String, URL> connect = new HashMap<String, URL>();
		connect.put("url", shapefile.toURI().toURL());
		dataStore = DataStoreFinder.getDataStore(connect);
		String[] typeNames = dataStore.getTypeNames();
		for (int i = 0; i < typeNames.length; ++i) {
			String typeName = typeNames[i];
			FeatureSource<?, ?> featureSource = dataStore
					.getFeatureSource(typeName);

			FeatureType ft = featureSource.getSchema();
			columns = new ArrayList<ColumnDef>();
			for (PropertyDescriptor property : ft.getDescriptors()) {

				Identifier identifier = Identifier.createDelimited(property
						.getName().getLocalPart());
				DataType datatype = TableDefUtils.TranslateDataTypeToSQLType((property
						.getType().getBinding().getName()));
				ColumnDef col = new ColumnDef(identifier, datatype,
						property.isNillable());
				columns.add(col);
			}
			//Identifier identifier = Identifier.createDelimited("gid");
			//ColumnDef col = new ColumnDef(identifier, TranslateDataTypeToSQLType("Int"), false);
			//columns.add(col);
			//primkeys.add(Key.create(identifier));
			TableName tablename = TableName.create(null, null,
					Identifier.create(true, dataStore.getTypeNames()[0]));
			onlytable = new TableDef(tablename, columns, null, primkeys,
					new HashSet<ForeignKey>());
			tables.add(onlytable);
		}

	} catch (Throwable e) {
		throw new Exception(e.getMessage());
	} finally {
		dataStore.dispose();

	}
	return tables;

}
 
Example 16
Source File: ShapefileMappingGenerator.java    From GeoTriples with Apache License 2.0 4 votes vote down vote up
public void run() throws IOException {
	Map<String, URL> connect = new HashMap<String, URL>();
	connect.put("url", new File(pathToShapefile).toURI().toURL());
	DataStore dataStore = DataStoreFinder.getDataStore(connect);
	String[] typeNames = dataStore.getTypeNames();
	for (int i = 0; i < typeNames.length; ++i) {
		String typeName = typeNames[i];
		triplesMaps.put(typeName, "");
		triplesMaps.put(typeName, triplesMaps.get(typeName) + printTriplesMap(typeName));
		triplesMaps.put(typeName, triplesMaps.get(typeName) + printLogicalSource(typeName));
		triplesMaps.put(typeName, triplesMaps.get(typeName) + printSubjectMap(baseURI, typeName));
		FeatureSource<?, ?> featureSource = dataStore.getFeatureSource(typeName);

		FeatureType ft = featureSource.getSchema();
		String typeNameGeo = typeNames[i] + "_Geometry";
		for (PropertyDescriptor property : ft.getDescriptors()) {

			String identifier = property.getName().getLocalPart();
			if (identifier.equals("the_geom")) {
				continue;
			}
			String datatype = TranslateDataTypeToXSD((property.getType().getBinding().getName()));
			Query q = new Query();
			triplesMaps.put(typeName, triplesMaps.get(typeName)
					+ printPredicateObjectMap(identifier, identifier, datatype, typeName));

		}
		// triplesMaps.put(typeName,
		// triplesMaps.get(typeName) + printPredicateObjectMap(true,
		// "hasGeometry",
		// baseURI + (baseURI.endsWith("/") ? "" : "/") + typeNameGeo +
		// "/{GeoTriplesID}", null,
		// typeName, true));
		triplesMaps
				.put(typeName,
						triplesMaps.get(typeName) + printPredicateObjectMap(true, "hasGeometry",
								baseURI + (baseURI.endsWith("/") ? "" : "/") + typeName
										+ "/Geometry/{GeoTriplesID}",
								null, null, "ogc", null, typeName, true, false));
		triplesMaps.put(typeNameGeo, "");
		triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printTriplesMap(typeNameGeo));
		triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printLogicalSource(typeName));
		triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printSubjectMap(baseURI, typeName, null, true));
		triplesMaps.put(typeNameGeo, triplesMaps.get(typeNameGeo) + printGEOPredicateObjectMaps());
	}
	printmapping();
	printontology();
}
 
Example 17
Source File: OmsShapefileFeatureWriter.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
@Execute
public void writeFeatureCollection() throws IOException {
    if (!concatOr(!hasWritten, doReset)) {
        return;
    }

    pm.beginTask("Writing features to shapefile...", -1);

    if (!file.endsWith(".shp")) {
        file = file + ".shp";
    }
    if (geodata != null && geodata.size() != 0) {
        pType = geodata.getSchema();
    }
    File shapeFile = new File(file);
    FileDataStoreFactorySpi factory = FileDataStoreFinder.getDataStoreFactory("shp");

    Map<String, Serializable> map = new HashMap<>();
    map.put("url", shapeFile.toURI().toURL());
    String shpDoIndex = PreferencesHandler.getShpDoIndex();
    if (shpDoIndex != null) {
        map.put("create spatial index", new Boolean(shpDoIndex));
    }

    String shpCharset = PreferencesHandler.getShpCharset();
    if (shpCharset != null) {
        map.put("charset", shpCharset);
    }

    DataStore newDataStore = factory.createNewDataStore(map);
    newDataStore.createSchema(pType);

    Transaction transaction = new DefaultTransaction("create");
    String typeName = newDataStore.getTypeNames()[0];
    SimpleFeatureStore featureStore = (SimpleFeatureStore) newDataStore.getFeatureSource(typeName);

    featureStore.setTransaction(transaction);
    try {
        if (geodata == null) {
            featureStore.addFeatures(new DefaultFeatureCollection());
        } else {
            featureStore.addFeatures(geodata);
        }
        transaction.commit();
    } catch (Exception problem) {
        transaction.rollback();
        throw new IOException(problem.getLocalizedMessage());
    } finally {
        transaction.close();
        pm.done();
    }

    hasWritten = true;
}