2015-04-22 3 views
0

Les informations sur les bâtiments sont stockées dans le fichier citygml. J'essaie d'extraire la géométrie du polygone du bâtiment en utilisant la bibliothèque citygml4j. J'ai regardé la classe FeatureWalker, mais je suis incapable d'obtenir la géométrie du polygone.Extraction de la géométrie polygonale à partir des données citygml à l'aide de la bibliothèque citygml4j

Comment procéder? Voici mon code:

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: Si vous avez d'autres ressources/tutoriels sur la bibliothèque citygml4j, bien vouloir me faire savoir.

Merci,

Répondre

0

Vous pouvez rechercher les AbstractBoundarySurfaces directement, comme celui-ci:

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

Ensuite, vous pouvez traverser vers le bas l'arbre et rechercher les polygones.