Java Code Examples for org.geotools.data.FeatureSource#getSchema()

The following examples show how to use org.geotools.data.FeatureSource#getSchema() . 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: RenderPanelImpl.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Render vector map.
 *
 * @param features the results
 * @param imageSize the image size
 * @param style the style
 * @param dpi the dpi
 */
private void renderVectorMap(
        FeatureSource<SimpleFeatureType, SimpleFeature> features,
        Rectangle imageSize,
        Style style,
        int dpi) {
    List<Layer> layerList = new ArrayList<>();
    if (style != null) {
        FeatureLayer featureLayer = new FeatureLayer(features, style);
        layerList.add(featureLayer);
    }

    boolean hasGeometry = false;
    ReferencedEnvelope bounds = null;

    if (features != null) {
        bounds = calculateBounds();

        wmsEnvVarValues.setMapBounds(bounds);

        EnvironmentVariableManager.getInstance().setWMSEnvVarValues(wmsEnvVarValues);

        if (features.getSchema() != null) {
            hasGeometry = (features.getSchema().getGeometryDescriptor() != null);
        }
    }

    internalRenderMap(layerList, bounds, imageSize, hasGeometry, dpi);
}
 
Example 2
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 3
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 4
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;

}