Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeoJSONReader的read未对breakType进行区分,导致读取属性不全,而无法加载。 #45

Open
xcmonline opened this issue Jan 3, 2025 · 1 comment

Comments

@xcmonline
Copy link

`
public static VectorLayer read(FeatureCollection features) {
Shape shape = GeoJSONUtil.toShape(features.getFeature(0).getGeometry());
VectorLayer layer = new VectorLayer(shape.getShapeType());
String fieldName = "title";
layer.editAddField(fieldName, DataType.STRING);
LegendScheme ls = new LegendScheme(shape.getShapeType());
ls.setLegendType(LegendType.UNIQUE_VALUE);
ls.setFieldName(fieldName);

    for(int i = 0; i < features.getNumFeatures(); ++i) {
        Feature feature = features.getFeature(i);
        Map<String, Object> properties = feature.getProperties();
        String titleValue = (String)properties.get("title");
        PolygonBreak cb = new PolygonBreak();
        cb.setStartValue(titleValue);
        cb.setCaption(titleValue);

        **### //需要对 breakType区分,因为在 GeoJSONWriter 中的 write做了区别,导致一些类型的属性没有而产生异常**

        Color color = ColorUtil.parseToColor((String)properties.get("fill"));
        float alpha = Float.parseFloat(properties.get("fill-opacity").toString());
        color = ColorUtil.getColor(color, alpha);
        cb.setColor(color);
        color = ColorUtil.parseToColor((String)properties.get("stroke"));
        alpha = Float.parseFloat(properties.get("stroke-opacity").toString());
        color = ColorUtil.getColor(color, alpha);
        cb.setOutlineColor(color);
        float lineWidth = Float.parseFloat(properties.get("stroke-width").toString());
        cb.setOutlineSize(lineWidth);


        ls.addLegendBreak(cb);
        Geometry geometry = feature.getGeometry();
        if (geometry != null) {
            try {
                int idx = layer.getShapeNum();
                layer.editInsertShape(GeoJSONUtil.toShape(geometry), idx);
                layer.editCellValue(fieldName, idx, titleValue);
            } catch (Exception var15) {
                throw new RuntimeException(var15);
            }
        }
    }

    layer.setLegendScheme(ls);
    return layer;
}

`

@Yaqiang
Copy link
Contributor

Yaqiang commented Jan 4, 2025

GeoJSONReader is still in draft state and I will try to improve it. Also any code contribution is wellcome. It's appreciated if you could provide an example data file for testing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants