0

I have a citygml file with some buildings. And I am trying to extract the geometry of the polygon in that building using the citygml4j library. I have looked at the FeatureWalker class but I am unable to get the geometry of the polygon.

Can anyone let me know how this can be done?

    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);
2

you can collect all polygons of a city object by using a GMLWalker

GMLWalker gmlWalker= new GMLWalker() {
      public void visit(Polygon polygon) {

        if (polygon.isSetExterior()) {
            AbstractRing exteriorAbstractRing = polygon.getExterior().getRing();
            ...
        }
      }
    };

cityObject.accept(gmlWalker);

Have a look at the 3D City Database repo. The Importer/Exporter tool takes extensive use of citygml4j.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.