使用citygml4j库

时间:2015-04-22 16:54:47

标签: java-api gml-geographic-markup-lan

我有建筑物'存储在citygml文件中的信息。我正在尝试使用citygml4j库提取建筑物的多边形几何体。我查看了FeatureWalker类,但我无法获得多边形几何。

我该怎么做呢?这是我的代码:

    CityGMLContext ctx = new CityGMLContext();
    CityGMLBuilder builder = ctx.createCityGMLBuilder();

    CityGMLInputFactory in = builder.createCityGMLInputFactory();
    CityGMLReader reader = in.createCityGMLReader(new File("/home/vishal/NWW/sampleData/LOD2_Building_v100.gml"));

    while(reader.hasNext())
    {
        CityGML citygml = reader.nextFeature();
        System.out.println("Found class:" + citygml.getCityGMLClass() + "\nVersion"+citygml.getCityGMLModule().getVersion());

        //Counting the no of buildings
        CityModel citymodel = new CityModel();
        if(citygml.getCityGMLClass() == CityGMLClass.CITY_MODEL)
        {
            citymodel = (CityModel)citygml;
            // Counting the no of buildings
            int count=0;
            for(CityObjectMember cityObjectMember : citymodel.getCityObjectMember())
            {
                AbstractCityObject cityobject = cityObjectMember.getCityObject();
                if(cityobject.getCityGMLClass() == CityGMLClass.BUILDING)
                {
                    ++count;
                }
            }
            System.out.println("Building count"+count);
        }

        FeatureWalker walker = new FeatureWalker(){
            public void visit(Building building){
                System.out.println(building.getId());
                //MultiSurface multisurface = boundrysurface.getLod2MultiSurface().getMultiSurface();
                //System.out.println(multisurface.getSurfaceMember().get(0));
                List<BoundarySurfaceProperty> list = building.getBoundedBySurface();
                System.out.println(list);
                System.out.println(list.get(0).getBoundarySurface());
                //HOW TO GET THE POLYGON AND ITS COORDINATES??
            }
        };
        citymodel.accept(walker);

PS:如果你有关于citygml4j库的任何其他资源/教程,请告诉我。

谢谢,

1 个答案:

答案 0 :(得分:0)

您可以直接搜索AbstractBoundarySurfaces,如下所示:

FeatureWalker walker = new FeatureWalker() {
        @Override
        public void visit(AbstractBoundarySurface boundarySurface) {
                MultiSurfaceProperty lod2MultiSurface = boundarySurface.getLod2MultiSurface();
                if (lod2MultiSurface != null) {
                        MultiSurface multiSurface = lod2MultiSurface.getMultiSurface();
                        if (multiSurface == null) {
                                // Do something!
                        }

                        List<SurfaceProperty> surfaceMember = multiSurface.getSurfaceMember();
                        for (SurfaceProperty surfaceProperty : surfaceMember) {
                                AbstractSurface abstractSurface = surfaceProperty.getObject();
                                if (abstractSurface instanceof Polygon) {
                                        Polygon polygon = (Polygon) abstractSurface;
                                        // Do something with polygon!
                                }
                                // Check for other subtypes of AbstractSurface
                        }
                }
                // Process LOD3 and LOD4
                super.visit(boundarySurface);
            }
};
building.accept(walker);

然后你可以遍历树并寻找多边形。