Skip to main content
added 94 characters in body
Source Link
J.R
  • 17.4k
  • 2
  • 23
  • 55

you can use this code: SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("MyFeatureType"); builder.setCRS( DefaultGeographicCRS.WGS84 ); // set crs
builder.add("location", Point.class); // add geometry
com.vividsolutions.jts.geom.Coordinate coord = new com.vividsolutions.jts.geom.Coordinate( x,y ); com.vividsolutions.jts.geom.GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
com.vividsolutions.jts.geom.Point point = geometryFactory.createPoint( coord );

SimpleFeatureType pointtype = null; try { pointtype = DataUtilities.createType("POINT", "geom:Point,name:String"); } catch (SchemaException ex) { Logger.getLogger(SelectionLab.class.getName()).log(Level.SEVERE, null, ex); } SimpleFeatureBuilder featureBuilderPoints = new SimpleFeatureBuilder(pointtype); SimpleFeatureCollection collectionPoints = FeatureCollections.newCollection(); //PointString Point=builder.createPointString(Point); //LineString Point = builder.createLineString(Point); featureBuilderPoints.add(point); SimpleFeature featureLine = featureBuilderPoints.buildFeature(null); ((DefaultFeatureCollection)collectionPoints).add(featureLine);
Style PointStyle = SLD.createPointStyle("circle", Color.RED, Color.RED,(float) 0.5,(float) 5); map.addLayer(new FeatureLayer(collectionPoints, PointStyle));

SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.setName("MyFeatureType");
        builder.setCRS( DefaultGeographicCRS.WGS84 ); // set crs        
        builder.add("location", Point.class); // add geometry       
              com.vividsolutions.jts.geom.Coordinate coord = new com.vividsolutions.jts.geom.Coordinate( x,y );
    com.vividsolutions.jts.geom.GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();    
                 com.vividsolutions.jts.geom.Point point = geometryFactory.createPoint( coord );
                
 SimpleFeatureType pointtype = null;
       try {
           pointtype = DataUtilities.createType("POINT", "geom:Point,name:String");
       } catch (SchemaException ex) {
           Logger.getLogger(SelectionLab.class.getName()).log(Level.SEVERE, null, ex);
       }
SimpleFeatureBuilder featureBuilderPoints = new SimpleFeatureBuilder(pointtype);
SimpleFeatureCollection collectionPoints = FeatureCollections.newCollection();
//PointString Point=builder.createPointString(Point);
//LineString Point = builder.createLineString(Point);
featureBuilderPoints.add(point);
SimpleFeature featureLine = featureBuilderPoints.buildFeature(null);
((DefaultFeatureCollection)collectionPoints).add(featureLine);     
Style PointStyle = SLD.createPointStyle("circle", Color.RED, Color.RED,(float) 0.5,(float) 5);
map.addLayer(new FeatureLayer(collectionPoints, PointStyle));

you can use this code: SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("MyFeatureType"); builder.setCRS( DefaultGeographicCRS.WGS84 ); // set crs
builder.add("location", Point.class); // add geometry
com.vividsolutions.jts.geom.Coordinate coord = new com.vividsolutions.jts.geom.Coordinate( x,y ); com.vividsolutions.jts.geom.GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
com.vividsolutions.jts.geom.Point point = geometryFactory.createPoint( coord );

SimpleFeatureType pointtype = null; try { pointtype = DataUtilities.createType("POINT", "geom:Point,name:String"); } catch (SchemaException ex) { Logger.getLogger(SelectionLab.class.getName()).log(Level.SEVERE, null, ex); } SimpleFeatureBuilder featureBuilderPoints = new SimpleFeatureBuilder(pointtype); SimpleFeatureCollection collectionPoints = FeatureCollections.newCollection(); //PointString Point=builder.createPointString(Point); //LineString Point = builder.createLineString(Point); featureBuilderPoints.add(point); SimpleFeature featureLine = featureBuilderPoints.buildFeature(null); ((DefaultFeatureCollection)collectionPoints).add(featureLine);
Style PointStyle = SLD.createPointStyle("circle", Color.RED, Color.RED,(float) 0.5,(float) 5); map.addLayer(new FeatureLayer(collectionPoints, PointStyle));

you can use this code:

SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder();
        builder.setName("MyFeatureType");
        builder.setCRS( DefaultGeographicCRS.WGS84 ); // set crs        
        builder.add("location", Point.class); // add geometry       
              com.vividsolutions.jts.geom.Coordinate coord = new com.vividsolutions.jts.geom.Coordinate( x,y );
    com.vividsolutions.jts.geom.GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();    
                 com.vividsolutions.jts.geom.Point point = geometryFactory.createPoint( coord );
                
 SimpleFeatureType pointtype = null;
       try {
           pointtype = DataUtilities.createType("POINT", "geom:Point,name:String");
       } catch (SchemaException ex) {
           Logger.getLogger(SelectionLab.class.getName()).log(Level.SEVERE, null, ex);
       }
SimpleFeatureBuilder featureBuilderPoints = new SimpleFeatureBuilder(pointtype);
SimpleFeatureCollection collectionPoints = FeatureCollections.newCollection();
//PointString Point=builder.createPointString(Point);
//LineString Point = builder.createLineString(Point);
featureBuilderPoints.add(point);
SimpleFeature featureLine = featureBuilderPoints.buildFeature(null);
((DefaultFeatureCollection)collectionPoints).add(featureLine);     
Style PointStyle = SLD.createPointStyle("circle", Color.RED, Color.RED,(float) 0.5,(float) 5);
map.addLayer(new FeatureLayer(collectionPoints, PointStyle));
Source Link

you can use this code: SimpleFeatureTypeBuilder builder = new SimpleFeatureTypeBuilder(); builder.setName("MyFeatureType"); builder.setCRS( DefaultGeographicCRS.WGS84 ); // set crs
builder.add("location", Point.class); // add geometry
com.vividsolutions.jts.geom.Coordinate coord = new com.vividsolutions.jts.geom.Coordinate( x,y ); com.vividsolutions.jts.geom.GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
com.vividsolutions.jts.geom.Point point = geometryFactory.createPoint( coord );

SimpleFeatureType pointtype = null; try { pointtype = DataUtilities.createType("POINT", "geom:Point,name:String"); } catch (SchemaException ex) { Logger.getLogger(SelectionLab.class.getName()).log(Level.SEVERE, null, ex); } SimpleFeatureBuilder featureBuilderPoints = new SimpleFeatureBuilder(pointtype); SimpleFeatureCollection collectionPoints = FeatureCollections.newCollection(); //PointString Point=builder.createPointString(Point); //LineString Point = builder.createLineString(Point); featureBuilderPoints.add(point); SimpleFeature featureLine = featureBuilderPoints.buildFeature(null); ((DefaultFeatureCollection)collectionPoints).add(featureLine);
Style PointStyle = SLD.createPointStyle("circle", Color.RED, Color.RED,(float) 0.5,(float) 5); map.addLayer(new FeatureLayer(collectionPoints, PointStyle));