From: Amador A. C. <sph...@gm...> - 2010-04-29 14:15:46
|
I've the follow code, but I can't add multiple geometries because my SimpleFeatureType is "hard coded", how do I to load the type of feature dinamyc? package demo.geometry01; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.LinearRing; import com.vividsolutions.jts.geom.Polygon; import org.geotools.data.DataUtilities; import org.geotools.feature.FeatureCollection; import org.geotools.feature.FeatureCollections; import org.geotools.feature.simple.SimpleFeatureBuilder; import org.geotools.geometry.jts.JTSFactoryFinder; import org.geotools.map.DefaultMapContext; import org.geotools.map.MapContext; import org.geotools.swing.JMapFrame; import org.opengis.feature.simple.SimpleFeature; import org.opengis.feature.simple.SimpleFeatureType; public class SimpleGeometryLab { GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null); FeatureCollection col = FeatureCollections.newCollection(); SimpleFeatureBuilder sfb; FeatureCollection<SimpleFeatureType, SimpleFeature> miCol = FeatureCollections.newCollection(); MapContext map; JMapFrame frame; public static void main(String[] args) throws Exception { SimpleGeometryLab me = new SimpleGeometryLab(); } public SimpleGeometryLab() throws Exception { map = new DefaultMapContext(); frame = new JMapFrame(map); map.setTitle("Geometrias simples"); //Here my problem... ¬¬ SimpleFeatureType TYPE = DataUtilities.createType( "Location", "location:Point:srid=4326," + "name:String"); sfb = new SimpleFeatureBuilder(TYPE); sfb.add(crearPunto(10, 30)); sfb.add(crearLinea()); SimpleFeature feat = sfb.buildFeature(null); miCol.add(feat); map.addLayer(miCol, null); frame.setSize(800, 600); frame.setVisible(true); } private Geometry crearPunto(int x, int y) { Coordinate c = new Coordinate(x, y); return gf.createPoint(c); } //Not in use private Geometry crearLinea() { Coordinate[] c = new Coordinate[]{ new Coordinate(100, 112), new Coordinate(200, 100), new Coordinate(85, 46) }; return gf.createLineString(c); } //Not in use private Geometry createCircle(double x, double y, final double r) { final int l = 32; Coordinate coords[] = new Coordinate[l + 1]; for (int i = 0; i < l; i++) { double angle = ((double) i / (double) l) * Math.PI * 2.0; double dx = Math.cos(angle) * r; double dy = Math.sin(angle) * r; coords[i] = new Coordinate((double) x + dx, (double) y + dy); } coords[l] = coords[0]; LinearRing ring = gf.createLinearRing(coords); Polygon polygon = gf.createPolygon(ring, null); return polygon; } } -- TSU. Amador Cuenca |
From: Rob A. <rob...@gm...> - 2010-04-30 00:46:07
|
you need the application-schema support see http://docs.geoserver.org/2.0.0/user/data/app-schema/index.html Rob Atkinson On Fri, Apr 30, 2010 at 12:15 AM, Amador Antonio Cuenca <sph...@gm...> wrote: > I've the follow code, but I can't add multiple geometries because my > SimpleFeatureType is "hard coded", how do I to load the type of feature > dinamyc? > > package demo.geometry01; > > import com.vividsolutions.jts.geom.Coordinate; > import com.vividsolutions.jts.geom.Geometry; > import com.vividsolutions.jts.geom.GeometryFactory; > import com.vividsolutions.jts.geom.LinearRing; > import com.vividsolutions.jts.geom.Polygon; > import org.geotools.data.DataUtilities; > import org.geotools.feature.FeatureCollection; > import org.geotools.feature.FeatureCollections; > import org.geotools.feature.simple.SimpleFeatureBuilder; > > import org.geotools.geometry.jts.JTSFactoryFinder; > import org.geotools.map.DefaultMapContext; > import org.geotools.map.MapContext; > import org.geotools.swing.JMapFrame; > import org.opengis.feature.simple.SimpleFeature; > import org.opengis.feature.simple.SimpleFeatureType; > > public class SimpleGeometryLab { > > GeometryFactory gf = JTSFactoryFinder.getGeometryFactory(null); > FeatureCollection col = FeatureCollections.newCollection(); > SimpleFeatureBuilder sfb; > FeatureCollection<SimpleFeatureType, SimpleFeature> miCol = > FeatureCollections.newCollection(); > MapContext map; > JMapFrame frame; > > public static void main(String[] args) throws Exception { > SimpleGeometryLab me = new SimpleGeometryLab(); > } > > public SimpleGeometryLab() throws Exception { > map = new DefaultMapContext(); > frame = new JMapFrame(map); > map.setTitle("Geometrias simples"); > > //Here my problem... ¬¬ > SimpleFeatureType TYPE = DataUtilities.createType( > "Location", > "location:Point:srid=4326," > + "name:String"); > sfb = new SimpleFeatureBuilder(TYPE); > > sfb.add(crearPunto(10, 30)); > sfb.add(crearLinea()); > SimpleFeature feat = sfb.buildFeature(null); > miCol.add(feat); > > map.addLayer(miCol, null); > frame.setSize(800, 600); > frame.setVisible(true); > } > > private Geometry crearPunto(int x, int y) { > Coordinate c = new Coordinate(x, y); > return gf.createPoint(c); > } > > //Not in use > private Geometry crearLinea() { > Coordinate[] c = new Coordinate[]{ > new Coordinate(100, 112), > new Coordinate(200, 100), > new Coordinate(85, 46) > }; > return gf.createLineString(c); > } > > //Not in use > private Geometry createCircle(double x, double y, final double r) { > final int l = 32; > Coordinate coords[] = new Coordinate[l + 1]; > for (int i = 0; i < l; i++) { > double angle = ((double) i / (double) l) * Math.PI * 2.0; > double dx = Math.cos(angle) * r; > double dy = Math.sin(angle) * r; > coords[i] = new Coordinate((double) x + dx, (double) y + dy); > } > coords[l] = coords[0]; > > LinearRing ring = gf.createLinearRing(coords); > Polygon polygon = gf.createPolygon(ring, null); > > return polygon; > } > > } > > -- > TSU. Amador Cuenca > > ------------------------------------------------------------------------------ > > _______________________________________________ > Geotools-devel mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-devel > > |
From: Andrea A. <aa...@op...> - 2010-04-30 06:24:22
|
Rob Atkinson ha scritto: > you need the application-schema support > > see http://docs.geoserver.org/2.0.0/user/data/app-schema/index.html Or he can just add two separate geometry attributes and then specify the geometry to be used for rendering in the symbolizer "geometry" property. It depends on whether you know in advance you can have 2 geometry attributes (common case, actual geometry and label point). If the number of geometries is unknown and they are not semantically different then a n-valued attribute is the best fit, and that requires application-schema support Cheers Andrea -- Andrea Aime OpenGeo - http://opengeo.org Expert service straight from the developers. |