2015-04-22 64 views
0

我有建築物的信息存儲在citygml文件中。我正在嘗試使用citygml4j庫提取建築物的多邊形幾何體。我看了FeatureWalker類,但我無法獲取多邊形幾何。使用citygml4j庫從citygml數據中提取多邊形幾何體

我該如何去做這件事?這裏是我的代碼:

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庫的任何其他資源/教程,請讓我知道。

感謝,

回答

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

然後你就可以向下遍歷樹並查找多邊形。