Почему этот код не может создать слой точек в GeoTools

Я тестирую добавление набора точек на карту с использованием API Geotools. Я следовал этому примеру, насколько мог Проблема с созданием точки и добавлением ее в FeatureCollection , так как код примера устарел, а такие вещи, как FeatureCollections, устарели. Вместо этого я попытался использовать экземпляр DefaultFeatureCollection, и я не уверен, правильно ли я его использую, и поэтому точки не отображаются на карте. Что я делаю не так? Вот часть моего кода:

private void plotMarkers() {
    final SimpleFeatureType TYPE = this.createFeatureType();
    final SimpleFeatureBuilder BLDR = new SimpleFeatureBuilder(TYPE);

    DefaultFeatureCollection features = new DefaultFeatureCollection();

    // arbitrary start position
    Coordinate pos = new Coordinate(0, 0);
    final double pointSpacing = 1.0;
    String title = "Test";
    features.add(creatureFeature(BLDR, pos, title));

    // display points on screen
    Style style = SLD.createPointStyle("circle", Color.RED, Color.RED, 1.0f, 5.0f);
    Layer layer = new FeatureLayer(features, style);

    this.getMapContent().addLayer(layer);
}

person cj5    schedule 10.04.2015    source источник
comment
вам нужно будет показать нам хотя бы метод createFeatures, прежде чем мы сможем помочь   -  person Ian Turton    schedule 12.04.2015
comment
Вы не можете перейти по ссылке, которую я дал? Это на том сайте. osgeo-org.1560.x6.nabble.com/   -  person cj5    schedule 13.04.2015
comment
нам также нужно посмотреть, как вы настроили карту - о, о может быть не на карте   -  person Ian Turton    schedule 13.04.2015
comment
this.setMapContent(new MapContent()); в конструкторе.   -  person cj5    schedule 13.04.2015


Ответы (1)


Может быть, это может помочь вам заставить его работать

private MapContent map;
private static Style pointStyle = SLD.createPointStyle("Circle", Color.RED, Color.RED, 0.5f, POINT_SIZE);
public static void CreatePoints(double X, double Y){
        createPointLayer();
        createFeatures(X,Y);
}
static void createFeatures(double X, double Y) {
    Point point = geometryFactory.createPoint(new Coordinate(X, Y));
    pointCollection.add(SimpleFeatureBuilder.build(pointType, new Object[]{point}, null));

    //create map layer event
    MapLayerEvent mple = new MapLayerEvent(pointLayer, MapLayerEvent.DATA_CHANGED);
    //create maplayer list event
    MapLayerListEvent mplle = new MapLayerListEvent(map, pointLayer, map.layers().indexOf(pointLayer), mple);

    okvir.mapPane.layerChanged(mplle);
    System.out.println(MessageFormat.format("Created Point: {0}", point));
}


private static void createPointLayer() {
    if (pointType == null) {
        pointFeatureTypeBuilder.setName("PointCreated");
        pointFeatureTypeBuilder.setCRS(map.getCoordinateReferenceSystem());
        pointFeatureTypeBuilder.add("the_geom", Point.class);
        pointType = pointFeatureTypeBuilder.buildFeatureType();
        pointCollection = new DefaultFeatureCollection(null, pointType);
    }
    pointLayer = new FeatureLayer(pointCollection, pointStyle);
    map.addLayer(pointLayer);
}
person Zoran Kokeza    schedule 24.06.2016