I just want to know how to create an instance of a Multipoint from a PostGIS database.

I do the query, then get a ResultSet named area. The column with MultiPolygon attributes is named geom, so I do the following:

MultiPolygon m = (MultiPolygon)area.getObject("geom");

Forced cast doesn't work though!

有帮助吗?

解决方案

You shouldn't be referencing the ResultSet directly but should work through the datastore interface which takes care of the conversion for you. See the Query Tutorial for an example of searching a dataset and retrieving geometries.

You'll need something like:

 SimpleFeatureSource source = dataStore.getFeatureSource(typeName);

    FeatureType schema = source.getSchema();
    String name = schema.getGeometryDescriptor().getLocalName();

    Filter filter = CQL.toFilter(text.getText());

    Query query = new Query(typeName, filter, new String[] { name });

    SimpleFeatureCollection features = source.getFeatures(query);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top