سؤال

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